137 lines
3.6 KiB
C#
137 lines
3.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace SimpleInventorySystem
|
|
{
|
|
public class GroupSlotUI : MonoBehaviour
|
|
{
|
|
public SlotUI slot;
|
|
public SlotUI[] slots;
|
|
public bool requireAllSlots;
|
|
public GameObject[] showGameObjects;
|
|
public SlotUI[] incompatibleSlots;
|
|
public GameObject[] hideGameObjects;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
if (slot != null)
|
|
{
|
|
slot.groupSlot = this;
|
|
}
|
|
if (slots != null)
|
|
{
|
|
foreach (SlotUI s in slots)
|
|
{
|
|
s.groupSlot = this;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ShowUIContainer()
|
|
{
|
|
foreach(GameObject uiContainerGameObject in showGameObjects)
|
|
{
|
|
uiContainerGameObject.SetActive(true);
|
|
}
|
|
foreach (GameObject uiContainerGameObject in hideGameObjects)
|
|
{
|
|
uiContainerGameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void HideUIContainer()
|
|
{
|
|
foreach (GameObject uiContainerGameObject in showGameObjects)
|
|
{
|
|
uiContainerGameObject.SetActive(false);
|
|
}
|
|
foreach (GameObject uiContainerGameObject in hideGameObjects)
|
|
{
|
|
uiContainerGameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
// TODO: Could use improvement
|
|
public bool HasSlotsOccupied()
|
|
{
|
|
if (slot != null && slot.GetItemUI() == null && (slots == null || slots.Length == 0))
|
|
{
|
|
Debug.Log("A");
|
|
return false;
|
|
}
|
|
else if(slots != null && slots.Length > 0)
|
|
{
|
|
bool atLesatOneSlot = false;
|
|
foreach(SlotUI s in slots)
|
|
{
|
|
if (s.GetItemUI() == null)
|
|
{
|
|
if (requireAllSlots)
|
|
{
|
|
Debug.Log("B");
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
atLesatOneSlot = true;
|
|
if (!requireAllSlots)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!atLesatOneSlot && !requireAllSlots)
|
|
{
|
|
Debug.Log("C");
|
|
return false;
|
|
}
|
|
}
|
|
Debug.Log("D");
|
|
return true;
|
|
}
|
|
|
|
public bool HasIncompatibleSlotsOccupied()
|
|
{
|
|
if(incompatibleSlots != null)
|
|
{
|
|
foreach(SlotUI s in incompatibleSlots)
|
|
{
|
|
if(s.GetItemUI() != null)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal void OnItemDropped()
|
|
{
|
|
if (HasSlotsOccupied() && !HasIncompatibleSlotsOccupied())
|
|
{
|
|
ShowUIContainer();
|
|
}
|
|
}
|
|
|
|
internal void OnItemRemoved()
|
|
{
|
|
Debug.Log("GroupSlotUI: Removed Item");
|
|
if (!HasSlotsOccupied())
|
|
{
|
|
HideUIContainer();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|