89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace SimpleInventorySystem
|
|
{
|
|
public class AppendUI : MonoBehaviour
|
|
{
|
|
public Transform AttachToTransform;
|
|
public bool FindAttachToScriptInAttachToTransform;
|
|
private Transform targetParentTransform;
|
|
[Tooltip("Leave empty if a container exists in dropped target(s) ItemUI.")]
|
|
//public GameObject PrefabUI;
|
|
private GameObject instantiatedUI;
|
|
public bool StackAppend = true;
|
|
|
|
private int inCount = 1;
|
|
|
|
public void AppendUIToTransform(ItemUI itemUI)
|
|
{
|
|
if(AttachToTransform != null)
|
|
{
|
|
if (AttachToTransform != null && FindAttachToScriptInAttachToTransform)
|
|
{
|
|
AttachTo attachTarget = AttachToTransform.GetComponentInChildren<AttachTo>();
|
|
if(attachTarget != null)
|
|
targetParentTransform = attachTarget.transform;
|
|
}
|
|
else
|
|
{
|
|
targetParentTransform = AttachToTransform;
|
|
}
|
|
}
|
|
|
|
if (itemUI != null && targetParentTransform != null)
|
|
{
|
|
if(itemUI.container != null)
|
|
{
|
|
Debug.Log("Append: " + targetParentTransform.name);
|
|
itemUI.container.SetActive(true);
|
|
itemUI.container.transform.SetParent(targetParentTransform, false);
|
|
Debug.Log("Append: " + "This should be working...");
|
|
}
|
|
else if (itemUI.containerUIPrefab != null)
|
|
{
|
|
Debug.Log("Creating new");
|
|
itemUI.container = Instantiate(itemUI.containerUIPrefab, targetParentTransform, false);
|
|
itemUI.container.name = itemUI.container.name + " " + inCount;
|
|
inCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*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)
|
|
{
|
|
if (itemUI.container != null)
|
|
{
|
|
Debug.Log("AppendUI:Remove:" + itemUI.gameObject.name + itemUI.container.name);
|
|
itemUI.container.transform.SetParent(itemUI.transform, false);
|
|
itemUI.container.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public GameObject InstantiatedUI()
|
|
{
|
|
return instantiatedUI;
|
|
}
|
|
}
|
|
} |