diff --git a/Assets/Scripts/IGrabable.cs b/Assets/Scripts/IGrabable.cs index 0f0c16d..5ff2cfb 100644 --- a/Assets/Scripts/IGrabable.cs +++ b/Assets/Scripts/IGrabable.cs @@ -8,5 +8,5 @@ public interface IGrabable // int size {get; set;} //Size (1 or 2 hands) of the object void use(); void take(); - void drop(Transform position); //Drop to position + void drop(Vector2 position); //Drop to position } diff --git a/Assets/Scripts/Mug.cs b/Assets/Scripts/Mug.cs index b857d08..2eea93c 100644 --- a/Assets/Scripts/Mug.cs +++ b/Assets/Scripts/Mug.cs @@ -12,11 +12,12 @@ public class Mug : MonoBehaviour, IGrabable } public void take() { - + gameObject.SetActive(false); } - public void drop(Transform position) //Drop to position + public void drop(Vector2 position) //Drop to position { - + gameObject.SetActive(true); + gameObject.transform.position = position; } // Start is called before the first frame update diff --git a/Assets/Scripts/Tavernkeeper_controller.cs b/Assets/Scripts/Tavernkeeper_controller.cs index efb8903..ae7d768 100644 --- a/Assets/Scripts/Tavernkeeper_controller.cs +++ b/Assets/Scripts/Tavernkeeper_controller.cs @@ -7,7 +7,7 @@ public class Tavernkeeper_controller : MonoBehaviour public float mvt_speed = 5.0f; //Movement speed public float action_dist = 1.5f; //Action distance - IDictionary hand_container; + IDictionary hand_container; //Objects in hand // Last user inputs float horizontal; @@ -96,8 +96,15 @@ public class Tavernkeeper_controller : MonoBehaviour { // hit_object.transform.SetParent(transform); // hit_object.transform.localPosition = new Vector2(-0.2f,0.2f); - hit_object.SetActive(false); - hand_container[hand]=hit_object; + + //Doit traiter différement chaque Grabable ... + Mug obj = hit_object.GetComponent(); + // if (obj.size==1 || (obj.size==2 && )); + if(obj!=null) + { + obj.take(); + hand_container[hand]=hit_object; + } } } //Full hand : try give to client @@ -113,9 +120,28 @@ public class Tavernkeeper_controller : MonoBehaviour { // Debug.Log("Hand full with "+ hand_container[hand]); // hand_container[hand].transform.SetParent(null); - hand_container[hand].SetActive(true); - hand_container[hand].transform.position = rigidbody2d.position; - hand_container[hand]=null; + + //Doit traiter différement chaque Grabable ... + Mug obj = hand_container[hand].GetComponent(); + if(obj !=null) + { + obj.drop(rigidbody2d.position); + hand_container[hand]=null; + } } } + + //Returns set of free hands (keys) + // ISet freeHands() + // { + // HashSet res = new HashSet(); + // foreach ( KeyValuePair kvp in hand_container) + // { + // if(kvp.Value is null) + // { + // res.Add(kvp.Key); + // } + // } + // return res; + // } }