Handle continuous interactions + Add Cleaning_workshop.prefab
This commit is contained in:
parent
6cce785d2c
commit
363845b456
11 changed files with 726 additions and 41 deletions
|
@ -21,13 +21,24 @@ public class Cleaning_workshop : Workshop
|
|||
if (mug!= null)
|
||||
{
|
||||
Debug.Log(userObject.name+ " stocked in "+gameObject.name);
|
||||
if (mug.content != null)//Empty mug
|
||||
if(mug.content != null)//Empty mug
|
||||
{
|
||||
mug.consume();
|
||||
prepTimer=0.0f;
|
||||
}
|
||||
else if(!mug.dirty)//Mug already clean
|
||||
prepTimer=prepTime;
|
||||
|
||||
stock.Add(userObject);
|
||||
|
||||
return true; //Object taken
|
||||
}
|
||||
}
|
||||
else if(userObject.tag=="Player" && currentMug!=null) //Give clean mug
|
||||
else if(userObject.tag=="Player" && prepTimer<prepTime && currentMug != null) //Prepare currentMug
|
||||
{
|
||||
continueUse(userObject);
|
||||
}
|
||||
else if(userObject.tag=="Player" && prepTimer>=prepTime) //Give tavernkeeper currentMug if cleaned
|
||||
{
|
||||
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
|
||||
Mug mug = currentMug.GetComponent<Mug>();
|
||||
|
@ -39,6 +50,8 @@ public class Cleaning_workshop : Workshop
|
|||
//Give mug
|
||||
player.grab(currentMug);
|
||||
currentMug=null;
|
||||
|
||||
UIPrepTimer.gameObject.SetActive(false); //Turn off UI prep timer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +66,13 @@ public class Cleaning_workshop : Workshop
|
|||
{
|
||||
currentMug=stock[0];
|
||||
stock.RemoveAt(0);
|
||||
|
||||
if(UIPrepTimer != null) //Display UI prep timer
|
||||
{
|
||||
UIPrepTimer.SetValue(prepTimer/prepTime);
|
||||
UIPrepTimer.DisplayIcon(false);
|
||||
UIPrepTimer.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,19 +15,12 @@ public class Production_workshop : Workshop
|
|||
//Handle objects interactions w/ 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);
|
||||
//TODO : Gérer Grabable qui ne sont pas des mugs ?
|
||||
if(userObject.tag=="Grabable" && currentMug is null)
|
||||
if(userObject.tag=="Grabable" && currentMug is null) //Try to stock Mug into workshop
|
||||
{
|
||||
Mug mug = userObject.GetComponent<Mug>();
|
||||
if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop
|
||||
|
@ -50,7 +43,11 @@ public class Production_workshop : Workshop
|
|||
Debug.Log(userObject.name+" cannot be filled with "+product_name+ " -stock:"+stock);
|
||||
}
|
||||
}
|
||||
else if(prepTimer>=prepTime && userObject.tag=="Player" && currentMug != null) //Give tavernkeeper currentMug if finished preparation
|
||||
else if(userObject.tag=="Player" && prepTimer<prepTime && currentMug != null) //Prepare currentMug
|
||||
{
|
||||
continueUse(userObject);
|
||||
}
|
||||
else if(userObject.tag=="Player" && prepTimer>=prepTime) //Give tavernkeeper currentMug if finished preparation
|
||||
{
|
||||
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
|
||||
Mug mug = currentMug.GetComponent<Mug>();
|
||||
|
|
|
@ -29,7 +29,7 @@ public class UITimer : MonoBehaviour
|
|||
//Value : [0,1]
|
||||
public void SetValue(float value)
|
||||
{
|
||||
if(value>1||value<0)
|
||||
if(value>1.01||value<-0.01) //Add a bit of flexibility so it only display real bad use
|
||||
Debug.LogWarning(gameObject.name+" - Timer value out of range [0,1]: "+value);
|
||||
//Change time color
|
||||
if(value>0.66)
|
||||
|
|
|
@ -12,12 +12,30 @@ public abstract class Workshop : MonoBehaviour, IUsable
|
|||
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
|
||||
protected float interactionCd = 0.0f; //Time to consider the interaction stopped
|
||||
public float interactionSmoothing = 0.0f; //% of action_cd added to the interaction CD for smooth continued interaction
|
||||
protected float cdTimer = 0.0f;
|
||||
|
||||
//Handle objects interactions w/ Workshop
|
||||
//Return wether the object is taken from tavernkeeper
|
||||
public abstract bool use(GameObject userObject);
|
||||
|
||||
//Handle continuous interaction w/ Workshop
|
||||
protected void continueUse(GameObject userObject)
|
||||
{
|
||||
Debug.Log(gameObject.name+" still used by "+userObject.name);
|
||||
if(interactionCd<0.01f) //No interaction CD => Try to set it up
|
||||
{
|
||||
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
|
||||
if(player != null)
|
||||
interactionCd=player.action_cd*(1.0f+interactionSmoothing); //=action_cd+ interactionSmoothing(%) action_cd (for smooth continued interaction)
|
||||
else
|
||||
Debug.LogWarning(userObject.name+" cannot have a continuous interaction on "+gameObject.name);
|
||||
}
|
||||
playerInteracting = true; //Set interaction indicator
|
||||
cdTimer = interactionCd; //Reset Interaction CD
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
@ -31,17 +49,23 @@ public abstract class Workshop : MonoBehaviour, IUsable
|
|||
UIPrepTimer.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
//LateUpdate is called after classic Updates
|
||||
void LateUpdate()
|
||||
{
|
||||
if(playerInteracting)
|
||||
{
|
||||
//Continue Preparation
|
||||
if(prepTimer<prepTime) //Update UI Prep timer
|
||||
{
|
||||
prepTimer+=Time.deltaTime;
|
||||
UIPrepTimer.SetValue(prepTimer/prepTime);
|
||||
if(UIPrepTimer != null)
|
||||
UIPrepTimer.SetValue(prepTimer/prepTime);
|
||||
}
|
||||
|
||||
playerInteracting=false; //Reset interaction indicator for next frame
|
||||
//Update interaction CD
|
||||
cdTimer-=Time.deltaTime;
|
||||
if (cdTimer<0)
|
||||
playerInteracting=false; //Reset interaction indicator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue