Create Production_workshop.prefab + Start UI display for prep
This commit is contained in:
parent
998cc81e0a
commit
6cce785d2c
8 changed files with 530 additions and 144 deletions
|
@ -16,6 +16,13 @@ public class Production_workshop : Workshop
|
|||
//Return wether the object is taken from tavernkeeper
|
||||
public override bool use(GameObject userObject)
|
||||
{
|
||||
if(userObject.tag=="Player")
|
||||
{
|
||||
playerInteracting = true; //Set interaction indicator
|
||||
Debug.Log("Player interacting");
|
||||
}
|
||||
|
||||
|
||||
if(userObject != null)
|
||||
{
|
||||
// Debug.Log(userObject.tag);
|
||||
|
@ -27,6 +34,15 @@ public class Production_workshop : Workshop
|
|||
{
|
||||
Debug.Log(userObject.name+ " stocked in "+gameObject.name);
|
||||
currentMug=userObject;
|
||||
|
||||
if(UIPrepTimer != null) //Display UI prep timer
|
||||
{
|
||||
prepTimer=0.0f;
|
||||
UIPrepTimer.SetValue(prepTimer/prepTime);
|
||||
UIPrepTimer.DisplayIcon(product_sprite);
|
||||
UIPrepTimer.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
return true; //Object taken
|
||||
}
|
||||
else
|
||||
|
@ -34,7 +50,7 @@ public class Production_workshop : Workshop
|
|||
Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock);
|
||||
}
|
||||
}
|
||||
else if(userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug
|
||||
else if(prepTimer>=prepTime && userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug if finished preparation
|
||||
{
|
||||
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
|
||||
Mug mug = currentMug.GetComponent<Mug>();
|
||||
|
@ -44,6 +60,8 @@ public class Production_workshop : Workshop
|
|||
//Fill mug
|
||||
mug.fill(new Consumable(product_name,product_value,product_sprite));
|
||||
stock--;
|
||||
UIPrepTimer.gameObject.SetActive(false); //Turn off UI prep timer
|
||||
|
||||
//Give mug
|
||||
player.grab(currentMug);
|
||||
currentMug=null;
|
||||
|
@ -51,9 +69,8 @@ public class Production_workshop : Workshop
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log(gameObject.name+" doesn't handle : "+userObject);
|
||||
}
|
||||
Debug.LogWarning(gameObject.name+" doesn't handle : "+userObject);
|
||||
|
||||
return false; //Object not taken
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,15 @@ public class UITimer : MonoBehaviour
|
|||
time.color = Color.green;
|
||||
}
|
||||
|
||||
//TODO: Override DisplayIcon to set Icon
|
||||
public void DisplayIcon(bool value)
|
||||
{
|
||||
icon.gameObject.SetActive(value);
|
||||
}
|
||||
public void DisplayIcon(Sprite newIcon)
|
||||
{
|
||||
icon.sprite=newIcon;
|
||||
icon.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
//Value : [0,1]
|
||||
public void SetValue(float value)
|
||||
|
|
|
@ -6,12 +6,17 @@ using UnityEngine;
|
|||
[RequireComponent(typeof(Collider2D))]
|
||||
public abstract class Workshop : MonoBehaviour, IUsable
|
||||
{
|
||||
public float prepTime = 2.0f; //Time for preparation of product
|
||||
protected GameObject currentMug = null; //Mug currently stocked in workshop
|
||||
|
||||
public float prepTime = 2.0f; //Time for preparation of product
|
||||
protected float prepTimer= 0.0f;
|
||||
public UITimer UIPrepTimer = null; //Script of the UI display
|
||||
protected bool playerInteracting = false; //Wether the player is interacting w/ the workshop
|
||||
// bool playerInteractFrame = false; //Wether the player used the workshop in the current frame
|
||||
|
||||
//Handle objects interactions w/ Workshop
|
||||
//Return wether the object is taken from tavernkeeper
|
||||
public abstract bool use(GameObject userObject);
|
||||
public abstract bool use(GameObject userObject);
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
@ -20,5 +25,23 @@ public abstract class Workshop : MonoBehaviour, IUsable
|
|||
Debug.LogWarning(gameObject.name+" layer should be set to 'Interactions' to work properly");
|
||||
if(gameObject.tag != "Usable")
|
||||
Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly");
|
||||
if(UIPrepTimer is null)
|
||||
Debug.LogWarning(gameObject.name+" doesn't have a UIPrepTimer set");
|
||||
else
|
||||
UIPrepTimer.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if(playerInteracting)
|
||||
{
|
||||
if(prepTimer<prepTime) //Update UI Prep timer
|
||||
{
|
||||
prepTimer+=Time.deltaTime;
|
||||
UIPrepTimer.SetValue(prepTimer/prepTime);
|
||||
}
|
||||
|
||||
playerInteracting=false; //Reset interaction indicator for next frame
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue