Display in hands Mug for Tavernkeeper
This commit is contained in:
parent
aa850a7c0b
commit
ca8790bb19
8 changed files with 109 additions and 16 deletions
|
@ -21,6 +21,7 @@ public class Cleaning_workshop : Workshop
|
|||
if (mug!= null)
|
||||
{
|
||||
Debug.Log(userObject.name+ " stocked in "+gameObject.name);
|
||||
mug.take();
|
||||
stock.Add(userObject);
|
||||
|
||||
return true; //Object taken
|
||||
|
|
|
@ -89,6 +89,7 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
Debug.Log(gameObject.name+" "+status+" "+object_used.name+ " of "+mug.content.Type);
|
||||
currentMug = object_used;
|
||||
consumeTimer=consumeTime;
|
||||
mug.take();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -181,7 +182,9 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
ClientManager.Instance.clientReward(money);
|
||||
|
||||
//Drop mug
|
||||
obj.drop(gameObject.transform.position+ (Vector3)Vector2.down * 0.2f);
|
||||
Transform dropPos = gameObject.transform;
|
||||
dropPos.position += (Vector3)Vector2.down * 0.2f;
|
||||
obj.drop(dropPos);
|
||||
currentMug=null;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@ public interface IGrabable: IUsable
|
|||
{
|
||||
//Unity inspector doesn't handle well interface...
|
||||
int size {get; set;} //Size (1 or 2 hands) of the object
|
||||
void take();
|
||||
void drop(Vector2 position); //Drop to position
|
||||
void take(Transform taker_tf=null);
|
||||
void drop(Transform tf); //Drop at transform position
|
||||
}
|
||||
|
|
|
@ -13,25 +13,37 @@ public class Mug : MonoBehaviour, IGrabable
|
|||
|
||||
public UITimer UIContent = null;
|
||||
|
||||
Collider2D triggerCollider;
|
||||
|
||||
//TODO: Gérer objets tavernier (drop) et autres
|
||||
public bool use(GameObject userObject)
|
||||
{
|
||||
if(userObject.tag=="Player")
|
||||
{
|
||||
// Debug.Log(gameObject.name+" dropped by "+userObject.name);
|
||||
drop(userObject.transform.position);
|
||||
drop(userObject.transform);
|
||||
return true; //Object taken (on the floor)
|
||||
}
|
||||
return false; //Return wether the object is taken from tavernkeeper
|
||||
}
|
||||
public void take() //Object taken
|
||||
public void take(Transform taker_tf=null) //Object taken
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
if(taker_tf is null)
|
||||
gameObject.SetActive(false);
|
||||
else
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
gameObject.transform.SetParent(taker_tf);
|
||||
gameObject.transform.localPosition = new Vector2(0.0f,0.0f);
|
||||
triggerCollider.enabled=false;
|
||||
}
|
||||
}
|
||||
public void drop(Vector2 position) //Drop to position
|
||||
public void drop(Transform tf) //Drop to position
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
gameObject.transform.position = position;
|
||||
gameObject.transform.SetParent(tf.parent);
|
||||
gameObject.transform.position = tf.position;
|
||||
triggerCollider.enabled=true;
|
||||
}
|
||||
|
||||
public void fill(Consumable new_content) //Fill Mug w/ new Consumable
|
||||
|
@ -71,6 +83,10 @@ public class Mug : MonoBehaviour, IGrabable
|
|||
Debug.LogWarning(gameObject.name+" doesn't have a UIContent set");
|
||||
else
|
||||
UIContent.gameObject.SetActive(false);
|
||||
|
||||
triggerCollider = gameObject.GetComponent<Collider2D>();
|
||||
if(!triggerCollider.isTrigger)
|
||||
Debug.LogWarning(gameObject.name+" collider found isn't a trigger");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
|
@ -34,6 +34,7 @@ public class Production_workshop : Workshop
|
|||
if (mug!= null && mug.content is null && !mug.dirty && Stock>0) //Mug clean & empty + remaining stock in workshop
|
||||
{
|
||||
Debug.Log(userObject.name+ " stocked in "+gameObject.name);
|
||||
mug.take();
|
||||
currentMug=userObject;
|
||||
|
||||
if(UIPrepTimer != null) //Display UI prep timer
|
||||
|
|
|
@ -10,8 +10,7 @@ public class Tavernkeeper_controller : MonoBehaviour
|
|||
public float action_dist = 1.5f; //Action distance
|
||||
public float action_cd = 0.5f; //Action cooldown
|
||||
|
||||
//TODO : GameObject => IGrabable
|
||||
Dictionary<string, GameObject> hand_container; //Objects in hand
|
||||
Dictionary<string, GameObject> hand_container; //Objects (IGrabable) in hand
|
||||
|
||||
float actionTimer;
|
||||
bool isInteracting;
|
||||
|
@ -45,7 +44,8 @@ public class Tavernkeeper_controller : MonoBehaviour
|
|||
// hit_object.transform.SetParent(transform);
|
||||
// hit_object.transform.localPosition = new Vector2(-0.2f,0.2f);
|
||||
|
||||
grabable_obj.take();
|
||||
Transform mugSlot = gameObject.transform.Find(hand+"MugSlot");
|
||||
grabable_obj.take(mugSlot);
|
||||
hand_container[hand]=obj;
|
||||
}
|
||||
else
|
||||
|
@ -63,7 +63,7 @@ public class Tavernkeeper_controller : MonoBehaviour
|
|||
if(hand_container[hand]!=null)
|
||||
{
|
||||
IGrabable grabable_obj = hand_container[hand].GetComponent<IGrabable>();
|
||||
grabable_obj.drop(transform.position);
|
||||
grabable_obj.drop(transform);
|
||||
}
|
||||
}
|
||||
hand_container["left"]=null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue