From 5b787c7da6e7d8c5c14e6b866a5e9e553b0fa61c Mon Sep 17 00:00:00 2001 From: Antoine H Date: Thu, 10 Dec 2020 10:49:36 +0100 Subject: [PATCH] Fix interactions IGrabable + Ajout interface IUsable --- Assets/Scripts/Client_controller.cs | 5 +++-- Assets/Scripts/IGrabable.cs | 1 + Assets/Scripts/IUsable.cs | 10 ++++++++++ Assets/Scripts/IUsable.cs.meta | 11 +++++++++++ Assets/Scripts/Tavernkeeper_controller.cs | 6 ++++-- Assets/Scripts/Workshop.cs | 6 ++++-- 6 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 Assets/Scripts/IUsable.cs create mode 100644 Assets/Scripts/IUsable.cs.meta diff --git a/Assets/Scripts/Client_controller.cs b/Assets/Scripts/Client_controller.cs index ab1cce7..2cdd29d 100644 --- a/Assets/Scripts/Client_controller.cs +++ b/Assets/Scripts/Client_controller.cs @@ -4,7 +4,7 @@ using UnityEngine; //Define the behavior of a client [RequireComponent(typeof(Collider2D))] -public class Client_controller : MonoBehaviour +public class Client_controller : MonoBehaviour, IUsable { public float consumeTime = 3.0f; //Time to consume currentMug public float waitingTime = 10.0f; //Patience after ordering @@ -18,7 +18,8 @@ public class Client_controller : MonoBehaviour { if(currentMug is null) //No mug in hand { - if(object_used != null && object_used.tag=="Mug") + //TODO : Gérer Grabale qui ne sont pas des Mugs ? + if(object_used != null && object_used.tag=="Grabable") { Mug mug = object_used.GetComponent(); if (mug!= null && mug.content != null) diff --git a/Assets/Scripts/IGrabable.cs b/Assets/Scripts/IGrabable.cs index 7664c8d..0f0d768 100644 --- a/Assets/Scripts/IGrabable.cs +++ b/Assets/Scripts/IGrabable.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; +//Represent object that can be grabed. public interface IGrabable { //Unity inspector doesn't handle well interface... diff --git a/Assets/Scripts/IUsable.cs b/Assets/Scripts/IUsable.cs new file mode 100644 index 0000000..407f6e9 --- /dev/null +++ b/Assets/Scripts/IUsable.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +//Represent object that can be used by tavernkeeper +public interface IUsable +{ + //Return wether the object is taken from tavernkeeper + bool use(GameObject userObject); +} diff --git a/Assets/Scripts/IUsable.cs.meta b/Assets/Scripts/IUsable.cs.meta new file mode 100644 index 0000000..9aa2d03 --- /dev/null +++ b/Assets/Scripts/IUsable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5460fe38df63b9499279b797ec3497e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index 81f5ae2..89717cf 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -21,6 +21,7 @@ public class Tavernkeeper_controller : MonoBehaviour Rigidbody2D rigidbody2d; Animator animator; + //TODO: assigner automatiquement à une autre mains si pleine public void grab(GameObject obj, string hand) { //Test @@ -145,18 +146,19 @@ 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(); + IUsable workshop = hit_object.GetComponent(); if(workshop!=null) { if(hand_container[hand] is null) //No object in hands { workshop.use(gameObject); //Tavernkeeper interacting directly w/ workshop + Debug.Log(gameObject.name+" use "+hit_object.name); } else if(workshop.use(hand_container[hand])) //Interactions w/ object in hands { //Object taken by workshop hand_container[hand]=null; + Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name); } } } diff --git a/Assets/Scripts/Workshop.cs b/Assets/Scripts/Workshop.cs index 7e98202..905dca5 100644 --- a/Assets/Scripts/Workshop.cs +++ b/Assets/Scripts/Workshop.cs @@ -4,7 +4,7 @@ using UnityEngine; //Define the behavior of a workshop (producer of Consumable) [RequireComponent(typeof(Collider2D))] -public class Workshop : MonoBehaviour +public class Workshop : MonoBehaviour, IUsable { public string product_name; public int product_value; @@ -19,7 +19,9 @@ public class Workshop : MonoBehaviour { if(userObject != null) { - if(userObject.tag=="Mug") + // Debug.Log(userObject.tag); + //TODO : Gérer Grabable qui ne sont pas des mugs ? + if(userObject.tag=="Grabable") { Mug mug = userObject.GetComponent(); if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop