using UnityEngine; using System.Collections; using System; public enum ItemSocketType{ Default, Pocket, Hands } [Serializable] public class ItemDescription{ public bool IsEquippable; public string Name; public string Description; public string TypeName; public ItemSocketType TargetSocket; } public class PickableItem : MonoBehaviour { public ItemDescription description; public PlayerSensor sensor; private GameAction _action; public AudioClip pickupSound; public int uid; public bool equipped; public Sprite inventoryIcon; protected virtual void Start(){ if (sensor != null) { sensor.PlayerEnter += HandlePlayerEnter; sensor.PlayerExit += HandlePlayerExit; } else { Debug.Log("Player sensor is null"); } _action = new GameAction(gameObject, "pick " + description.Name); } void HandlePlayerEnter (PlayerSensor s, GameObject player) { ActionController.AddAction(_action); } void HandlePlayerExit (PlayerSensor s, GameObject player) { ActionController.RemoveAction(_action); } public virtual void OnPrepareUse() { } public virtual void OnBeginUse() { } public virtual void OnEndUse() { } public virtual void OnEquipped(){ } public virtual void OnUnequipped(){ } void OnAction(ActionArgs args){ if(args != null && args.Caller != null){ var inventory = args.Caller.GetComponent(); if(inventory != null){ Debug.Log("Inventory add item: " + name); inventory.AddItem(this); if(pickupSound != null){ AudioSource.PlayClipAtPoint(pickupSound, transform.position); } ActionController.RemoveAction(_action); sensor.enabled = false; sensor.sensorEnabled = false; gameObject.SetActive(false); //Destroy(gameObject); } }else{ Debug.LogWarning("PickableItem: unknown caller"); } /*var audio = Inventory.Audio; if(audio != null && pickupSound != null){ audio.PlayOneShot(pickupSound); }*/ } }