Fix interactions IGrabable + Ajout interface IUsable

This commit is contained in:
Antoine H 2020-12-10 10:49:36 +01:00
parent eacf4f2711
commit 5b787c7da6
6 changed files with 33 additions and 6 deletions

View file

@ -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<Mug>();
if (mug!= null && mug.content != null)

View file

@ -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...

10
Assets/Scripts/IUsable.cs Normal file
View file

@ -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);
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5460fe38df63b9499279b797ec3497e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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<Workshop>();
IUsable workshop = hit_object.GetComponent<IUsable>();
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);
}
}
}

View file

@ -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<Mug>();
if (mug!= null && mug.content is null && !mug.dirty && stock>0) //Mug clean & empty + remaining stock in workshop