diff --git a/Assets/Prefabs/Characters/Tavernkeeper.prefab b/Assets/Prefabs/Characters/Tavernkeeper.prefab index b7077d3..0933405 100644 --- a/Assets/Prefabs/Characters/Tavernkeeper.prefab +++ b/Assets/Prefabs/Characters/Tavernkeeper.prefab @@ -32,7 +32,9 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -0.14237249, y: -0.5522889, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] + m_Children: + - {fileID: 7822737170605702480} + - {fileID: 8742837112030381377} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -185,3 +187,63 @@ NavMeshObstacle: m_CarveOnlyStationary: 1 m_Center: {x: 0, y: 0.2, z: 0} 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} diff --git a/Assets/Scenes/Tests/SampleScene.unity b/Assets/Scenes/Tests/SampleScene.unity index fc18c60..4a59bff 100644 --- a/Assets/Scenes/Tests/SampleScene.unity +++ b/Assets/Scenes/Tests/SampleScene.unity @@ -32571,7 +32571,17 @@ PrefabInstance: - target: {fileID: 2157073179154264261, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} 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} - target: {fileID: 2157073180203202244, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} @@ -32646,12 +32656,12 @@ PrefabInstance: - target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} propertyPath: nbMaxEvents - value: 1 + value: 20 objectReference: {fileID: 0} - target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} propertyPath: spawnChance - value: 100 + value: 30 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} diff --git a/Assets/Scripts/Cleaning_workshop.cs b/Assets/Scripts/Cleaning_workshop.cs index 5295a40..47eb281 100644 --- a/Assets/Scripts/Cleaning_workshop.cs +++ b/Assets/Scripts/Cleaning_workshop.cs @@ -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 diff --git a/Assets/Scripts/Client_controller.cs b/Assets/Scripts/Client_controller.cs index 132741c..2aaa860 100644 --- a/Assets/Scripts/Client_controller.cs +++ b/Assets/Scripts/Client_controller.cs @@ -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; } diff --git a/Assets/Scripts/IGrabable.cs b/Assets/Scripts/IGrabable.cs index 3bd512b..01fd6e0 100644 --- a/Assets/Scripts/IGrabable.cs +++ b/Assets/Scripts/IGrabable.cs @@ -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 } diff --git a/Assets/Scripts/Mug.cs b/Assets/Scripts/Mug.cs index 1435037..6599918 100644 --- a/Assets/Scripts/Mug.cs +++ b/Assets/Scripts/Mug.cs @@ -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(); + if(!triggerCollider.isTrigger) + Debug.LogWarning(gameObject.name+" collider found isn't a trigger"); } // Update is called once per frame diff --git a/Assets/Scripts/Production_workshop.cs b/Assets/Scripts/Production_workshop.cs index b9e968d..5bc8716 100644 --- a/Assets/Scripts/Production_workshop.cs +++ b/Assets/Scripts/Production_workshop.cs @@ -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 diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index 184d68e..492617b 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -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 hand_container; //Objects in hand + Dictionary 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(); - grabable_obj.drop(transform.position); + grabable_obj.drop(transform); } } hand_container["left"]=null;