diff --git a/Assets/Scenes/Tests/SampleScene.unity b/Assets/Scenes/Tests/SampleScene.unity index d4b8371..5013464 100644 --- a/Assets/Scenes/Tests/SampleScene.unity +++ b/Assets/Scenes/Tests/SampleScene.unity @@ -366,7 +366,7 @@ GameObject: - component: {fileID: 698542428} m_Layer: 8 m_Name: Chicken - m_TagString: Mug + m_TagString: Workshop m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -381,7 +381,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 1 + m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: -0.045565188, y: 0.14445162} @@ -472,10 +472,13 @@ MonoBehaviour: m_GameObject: {fileID: 698542424} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 06f2e18c7d91f7f4d99cd5e5c7d12b45, type: 3} + m_Script: {fileID: 11500000, guid: 5e4020837a3c5214f90b5688a1e4faa2, type: 3} m_Name: m_EditorClassIdentifier: - size: 2 + product_name: beer + product_value: 1 + product_sprite: {fileID: 21300000, guid: 17d59b2d4d882c04480a40119a442279, type: 3} + prepTime: 2 --- !u!1 &1163880821 GameObject: m_ObjectHideFlags: 0 @@ -490,7 +493,7 @@ GameObject: - component: {fileID: 1163880822} m_Layer: 8 m_Name: Mug - m_TagString: Untagged + m_TagString: Mug m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -611,6 +614,11 @@ PrefabInstance: propertyPath: m_Name value: Tavernkeeper objectReference: {fileID: 0} + - target: {fileID: 5841415790350674203, guid: dc287deb81f09d8419a5051e1d177e74, + type: 3} + propertyPath: m_TagString + value: Untagged + objectReference: {fileID: 0} - target: {fileID: 5841415790350674204, guid: dc287deb81f09d8419a5051e1d177e74, type: 3} propertyPath: m_Constraints @@ -671,5 +679,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 5841415790350674207, guid: dc287deb81f09d8419a5051e1d177e74, + type: 3} + propertyPath: action_dist + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: dc287deb81f09d8419a5051e1d177e74, type: 3} diff --git a/Assets/Scripts/Client_controller.cs b/Assets/Scripts/Client_controller.cs index 65abde7..18d05b2 100644 --- a/Assets/Scripts/Client_controller.cs +++ b/Assets/Scripts/Client_controller.cs @@ -7,18 +7,27 @@ public class Client_controller : MonoBehaviour { public float consumeTime = 3.0f; //Time to consume currentMug public float waitingTime = 10.0f; //Patience after ordering - GameObject currentMug; + GameObject currentMug = null; + //Return wether the object is taken from tavernkeeper public bool use(GameObject object_used) { - if(object_used != null && object_used.tag=="Mug") + if(currentMug is null) //No mug in hand { - Mug mug = object_used.GetComponent(); - if (mug.content != null) + if(object_used != null && object_used.tag=="Mug") { - Debug.Log(gameObject.name+" take "+object_used.name+ " of "+mug.content.Type); - currentMug = object_used; - return true; //Object taken from tavernkeeper + Mug mug = object_used.GetComponent(); + if (mug!= null && mug.content != null) + { + Debug.Log(gameObject.name+" take "+object_used.name+ " of "+mug.content.Type); + currentMug = object_used; + return true; + } + else + { + Debug.Log("Display order (or something else) of "+gameObject.name); + return false; + } } else { @@ -28,8 +37,8 @@ public class Client_controller : MonoBehaviour } else { - Debug.Log("Display order (or something else) of "+gameObject.name); - return false; //Object not taken from tavernkeeper + Debug.Log(gameObject.name+" already consumming "+currentMug.name); + return false; } } diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index 45c71ba..ac143b9 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -80,6 +80,7 @@ public class Tavernkeeper_controller : MonoBehaviour } //Handle action with hands + //TODO : Factoriser actions des IGrabable et actions des Clients/Workshop void handAction(string hand) { // Test collision of ray from tavernkeeper center (A verifier) at action_dist unit distance on Interactions layer @@ -119,6 +120,20 @@ public class Tavernkeeper_controller : MonoBehaviour } } } + else if(hit_object.tag == "Workshop") + { + // Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name); + Workshop workshop = hit_object.GetComponent(); + if(workshop!=null) + { + if(workshop.use(hand_container[hand])) //Interactions w/ object in hands + { + //Object taken by workshop + // Destroy(hand_container[hand]); + hand_container[hand]=null; + } + } + } } } //Full hand : drop diff --git a/Assets/Scripts/Workshop.cs b/Assets/Scripts/Workshop.cs new file mode 100644 index 0000000..c4f95dc --- /dev/null +++ b/Assets/Scripts/Workshop.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(Collider2D))] +public class Workshop : MonoBehaviour +{ + public string product_name; + public int product_value; + public Sprite product_sprite; + public float prepTime = 2.0f; + protected int _stock = 5; + + //Return wether the object is taken from tavernkeeper + public bool use(GameObject object_used) + { + if(object_used != null && object_used.tag=="Mug") + { + Mug mug = object_used.GetComponent(); + if (mug!= null && mug.content is null && _stock>0) + { + Debug.Log(gameObject.name+" fill "+object_used.name+ " with "+product_name); + mug.fill(new Consumable(product_name,product_value,product_sprite)); + _stock--; + return false; + } + else + { + Debug.Log(object_used.name+" cannot be filled with "+product_name+ " -stock:"+_stock); + return false; + } + } + else + { + Debug.Log("Display order (or something else) of "+gameObject.name); + return false; + } + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Workshop.cs.meta b/Assets/Scripts/Workshop.cs.meta new file mode 100644 index 0000000..3d8d853 --- /dev/null +++ b/Assets/Scripts/Workshop.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e4020837a3c5214f90b5688a1e4faa2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index ceff234..2b7b398 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -5,8 +5,8 @@ TagManager: serializedVersion: 2 tags: - Client - - Grabable - Mug + - Workshop layers: - Default - TransparentFX