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

64 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SimpleInventorySystem
{
public class AppendUI : MonoBehaviour
{
public Transform AttachToTransform;
[Tooltip("Leave empty if a container exists in dropped target(s) ItemUI.")]
public GameObject PrefabUI;
private GameObject instantiatedUI;
public void AppendUIToTransform(ItemUI itemUI)
{
if (itemUI != null && AttachToTransform != null)
{
if(itemUI.container != null)
{
itemUI.container.SetActive(true);
itemUI.container.transform.SetParent(AttachToTransform, false);
}
else if (itemUI.containerUIPrefab != null)
{
itemUI.container = Instantiate(itemUI.containerUIPrefab, AttachToTransform, false);
}
}
}
public void AppendUIToTransform()
{
if (PrefabUI != null && AttachToTransform != null)
{
instantiatedUI = Instantiate(PrefabUI, AttachToTransform);
}
}
public void RemoveUIFromTransform()
{
if (instantiatedUI != null)
{
// TODO: May need to add more here
Destroy(instantiatedUI);
}
}
public void RemoveUIFromTransform(ItemUI itemUI)
{
if (itemUI != null && AttachToTransform != null)
{
if (itemUI.container != null)
{
itemUI.container.SetActive(false);
itemUI.container.transform.SetParent(itemUI.transform, false);
}
}
}
public GameObject InstantiatedUI()
{
return instantiatedUI;
}
}
}