CursorHolderBehaviour

 avatar
user_3183455
csharp
14 days ago
1.5 kB
1
Indexable
Never
using CuongMono.Item.Inventory;
using UnityEngine;
 
namespace CuongMono.Item
{
    public class CursorHolderBehaviour : MonoBehaviour
    {
        public bool IsPickedUp { get; set; }
        [SerializeField] private CursorInventoryItemSlotUI inventoryItemSlotUI;
        public CursorInventoryItemSlotUI InventoryItemSlotUI => inventoryItemSlotUI;
 
        //[SerializeField] private HotbarItemSlotUI hotbarItemSlotUI;
        //public HotbarItemSlotUI HotbarItemSlotUI => hotbarItemSlotUI;
        private void Update()
        {
            this.CheckItem();
            this.CursorBehaviour();
        }
        protected virtual void CursorBehaviour()
        {
            if (this.IsPickedUp) this.FollowCursor();
         
        }
        public virtual void UpdateUI()
        {
            this.InventoryItemSlotUI.UpdateUI();
            //this.HotbarItemSlotUI?.UpdateUI();
        }
        protected virtual void CheckItem()
        {
            if(this.InventoryItemSlotUI?.Item != null /*|| this.HotbarItemSlotUI?.Item != null*/) this.IsPickedUp = true;
            else this.IsPickedUp = false;
        }
        protected virtual void FollowCursor()
        {
            if (this.InventoryItemSlotUI == null /*|| this.HotbarItemSlotUI == null*/) return;
            this.InventoryItemSlotUI.transform.position = Input.mousePosition;
            //this.HotbarItemSlotUI.transform.position = Input.mousePosition;
        }
    }
}
Leave a Comment