projectEli/Assets/SimpleInventorySystem/Scripts/UI/ContextMenuManagerUI.cs

106 lines
3.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace SimpleInventorySystem
{
public class ContextMenuManagerUI : MonoBehaviour
{
public static ContextMenuManagerUI instance;
public GameObject itemInspectMenu;
[HideInInspector] public ItemUI inspectItem;
public GameObject TacticalRigInspectionWindow;
private void Awake()
{
instance = this;
}
public bool IsInspectingItem()
{
return inspectItem != null;
}
public bool ItemInspectMenuHasFocus()
{
return InventorySystem.IsMouseOverUI(itemInspectMenu);
}
public void OpenContextMenu(ItemUI uiContext)
{
if(inspectItem != null)
{
CloseContextMenu();
}
//ContextMenuUI.transform.SetParent(uiContext, false);
itemInspectMenu.SetActive(true);
itemInspectMenu.transform.position = uiContext.transform.position;
inspectItem = uiContext;
//ContextMenuUI.transform.localScale = new Vector3(1, 1, 1);
Button inspectButton = itemInspectMenu.transform.Find("Inspect").GetComponent<Button>();
uiContext.SetInteractable(false);
Debug.Log("ContextMenuManager: " + inspectButton);
if (inspectButton != null)
{
inspectButton.onClick.AddListener(OpenInspectionWindow);
}
}
public void OpenInspectionWindow()
{
Debug.Log("Open");
if (inspectItem != null && inspectItem.ItemTag == ItemTags.TacticalRig && inspectItem.Equipped)
{
//
//(TacticalRigInspectionWindow, InventorySystem.instance.inventoryUI.transform);
inspectItem.ContextWindows.Add(TacticalRigInspectionWindow);
TacticalRigInspectionWindow.SetActive(true);
}
}
public void DropItem()
{
Debug.Log("Drop");
if (inspectItem != null)
{
inspectItem.DropItemOntoSlot();
CloseContextMenu();
}
}
public void CloseContextMenu()
{
if(inspectItem != null)
{
Button inspectButton = itemInspectMenu.transform.Find("Inspect").GetComponent<Button>();
if (inspectButton != null)
{
inspectButton.onClick.RemoveListener(OpenInspectionWindow);
}
inspectItem.SetInteractable(true);
}
inspectItem = null;
itemInspectMenu.SetActive(false);
}
// Start is called before the first frame update
void Start()
{
itemInspectMenu.SetActive(false);
TacticalRigInspectionWindow.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
//itemInspectMenu.SetActive(false);
}
}
}
}