Display in hands Mug for Tavernkeeper

This commit is contained in:
Antoine H 2021-01-19 10:46:47 +01:00
parent aa850a7c0b
commit ca8790bb19
8 changed files with 109 additions and 16 deletions

View file

@ -32,7 +32,9 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.14237249, y: -0.5522889, z: 0} m_LocalPosition: {x: -0.14237249, y: -0.5522889, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children:
- {fileID: 7822737170605702480}
- {fileID: 8742837112030381377}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -185,3 +187,63 @@ NavMeshObstacle:
m_CarveOnlyStationary: 1 m_CarveOnlyStationary: 1
m_Center: {x: 0, y: 0.2, z: 0} m_Center: {x: 0, y: 0.2, z: 0}
m_TimeToStationary: 0.5 m_TimeToStationary: 0.5
--- !u!1 &6643709102800425710
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7822737170605702480}
m_Layer: 0
m_Name: leftMugSlot
m_TagString: Untagged
m_Icon: {fileID: 3443629218296621865, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7822737170605702480
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6643709102800425710}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.208, y: 0.542, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5841415790350674206}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &7698388720067243385
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8742837112030381377}
m_Layer: 0
m_Name: rightMugSlot
m_TagString: Untagged
m_Icon: {fileID: 3443629218296621865, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8742837112030381377
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7698388720067243385}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.18, y: 0.535, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5841415790350674206}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View file

@ -32571,7 +32571,17 @@ PrefabInstance:
- target: {fileID: 2157073179154264261, guid: dfb09d229e85c1446bee2e4f9357610e, - target: {fileID: 2157073179154264261, guid: dfb09d229e85c1446bee2e4f9357610e,
type: 3} type: 3}
propertyPath: nbMaxClients propertyPath: nbMaxClients
value: 3 value: 10
objectReference: {fileID: 0}
- target: {fileID: 2157073179154264261, guid: dfb09d229e85c1446bee2e4f9357610e,
type: 3}
propertyPath: clientFrequency
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2157073179154264261, guid: dfb09d229e85c1446bee2e4f9357610e,
type: 3}
propertyPath: clientSpawnChance
value: 50
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2157073180203202244, guid: dfb09d229e85c1446bee2e4f9357610e, - target: {fileID: 2157073180203202244, guid: dfb09d229e85c1446bee2e4f9357610e,
type: 3} type: 3}
@ -32646,12 +32656,12 @@ PrefabInstance:
- target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e, - target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e,
type: 3} type: 3}
propertyPath: nbMaxEvents propertyPath: nbMaxEvents
value: 1 value: 20
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e, - target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e,
type: 3} type: 3}
propertyPath: spawnChance propertyPath: spawnChance
value: 100 value: 30
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} m_SourcePrefab: {fileID: 100100000, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3}

View file

@ -21,6 +21,7 @@ public class Cleaning_workshop : Workshop
if (mug!= null) if (mug!= null)
{ {
Debug.Log(userObject.name+ " stocked in "+gameObject.name); Debug.Log(userObject.name+ " stocked in "+gameObject.name);
mug.take();
stock.Add(userObject); stock.Add(userObject);
return true; //Object taken return true; //Object taken

View file

@ -89,6 +89,7 @@ public class Client_controller : MonoBehaviour, IUsable
Debug.Log(gameObject.name+" "+status+" "+object_used.name+ " of "+mug.content.Type); Debug.Log(gameObject.name+" "+status+" "+object_used.name+ " of "+mug.content.Type);
currentMug = object_used; currentMug = object_used;
consumeTimer=consumeTime; consumeTimer=consumeTime;
mug.take();
return true; return true;
} }
else else
@ -181,7 +182,9 @@ public class Client_controller : MonoBehaviour, IUsable
ClientManager.Instance.clientReward(money); ClientManager.Instance.clientReward(money);
//Drop mug //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; currentMug=null;
} }

View file

@ -7,6 +7,6 @@ public interface IGrabable: IUsable
{ {
//Unity inspector doesn't handle well interface... //Unity inspector doesn't handle well interface...
int size {get; set;} //Size (1 or 2 hands) of the object int size {get; set;} //Size (1 or 2 hands) of the object
void take(); void take(Transform taker_tf=null);
void drop(Vector2 position); //Drop to position void drop(Transform tf); //Drop at transform position
} }

View file

@ -13,25 +13,37 @@ public class Mug : MonoBehaviour, IGrabable
public UITimer UIContent = null; public UITimer UIContent = null;
Collider2D triggerCollider;
//TODO: Gérer objets tavernier (drop) et autres //TODO: Gérer objets tavernier (drop) et autres
public bool use(GameObject userObject) public bool use(GameObject userObject)
{ {
if(userObject.tag=="Player") if(userObject.tag=="Player")
{ {
// Debug.Log(gameObject.name+" dropped by "+userObject.name); // Debug.Log(gameObject.name+" dropped by "+userObject.name);
drop(userObject.transform.position); drop(userObject.transform);
return true; //Object taken (on the floor) return true; //Object taken (on the floor)
} }
return false; //Return wether the object is taken from tavernkeeper 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.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 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"); Debug.LogWarning(gameObject.name+" doesn't have a UIContent set");
else else
UIContent.gameObject.SetActive(false); 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 // Update is called once per frame

View file

@ -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 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); Debug.Log(userObject.name+ " stocked in "+gameObject.name);
mug.take();
currentMug=userObject; currentMug=userObject;
if(UIPrepTimer != null) //Display UI prep timer if(UIPrepTimer != null) //Display UI prep timer

View file

@ -10,8 +10,7 @@ public class Tavernkeeper_controller : MonoBehaviour
public float action_dist = 1.5f; //Action distance public float action_dist = 1.5f; //Action distance
public float action_cd = 0.5f; //Action cooldown public float action_cd = 0.5f; //Action cooldown
//TODO : GameObject => IGrabable Dictionary<string, GameObject> hand_container; //Objects (IGrabable) in hand
Dictionary<string, GameObject> hand_container; //Objects in hand
float actionTimer; float actionTimer;
bool isInteracting; bool isInteracting;
@ -45,7 +44,8 @@ public class Tavernkeeper_controller : MonoBehaviour
// hit_object.transform.SetParent(transform); // hit_object.transform.SetParent(transform);
// hit_object.transform.localPosition = new Vector2(-0.2f,0.2f); // 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; hand_container[hand]=obj;
} }
else else
@ -63,7 +63,7 @@ public class Tavernkeeper_controller : MonoBehaviour
if(hand_container[hand]!=null) if(hand_container[hand]!=null)
{ {
IGrabable grabable_obj = hand_container[hand].GetComponent<IGrabable>(); IGrabable grabable_obj = hand_container[hand].GetComponent<IGrabable>();
grabable_obj.drop(transform.position); grabable_obj.drop(transform);
} }
} }
hand_container["left"]=null; hand_container["left"]=null;