2022-10-19 13:51:46 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
|
namespace SimpleInventorySystem
|
2022-10-19 13:51:46 +00:00
|
|
|
|
{
|
2022-10-29 19:56:00 +00:00
|
|
|
|
public class AppendUI : MonoBehaviour
|
2022-10-19 13:51:46 +00:00
|
|
|
|
{
|
2022-10-29 19:56:00 +00:00
|
|
|
|
public Transform AttachToTransform;
|
2022-11-06 02:28:29 +00:00
|
|
|
|
public bool FindAttachToScriptInAttachToTransform;
|
|
|
|
|
private Transform targetParentTransform;
|
2022-10-29 19:56:00 +00:00
|
|
|
|
[Tooltip("Leave empty if a container exists in dropped target(s) ItemUI.")]
|
|
|
|
|
public GameObject PrefabUI;
|
|
|
|
|
private GameObject instantiatedUI;
|
2022-11-06 02:28:29 +00:00
|
|
|
|
public bool StackAppend = true;
|
|
|
|
|
|
|
|
|
|
private int inCount = 1;
|
2022-10-29 19:56:00 +00:00
|
|
|
|
|
|
|
|
|
public void AppendUIToTransform(ItemUI itemUI)
|
2022-10-19 13:51:46 +00:00
|
|
|
|
{
|
2022-11-06 02:28:29 +00:00
|
|
|
|
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)
|
2022-10-29 19:56:00 +00:00
|
|
|
|
{
|
|
|
|
|
if(itemUI.container != null)
|
|
|
|
|
{
|
2022-11-06 02:28:29 +00:00
|
|
|
|
Debug.Log("Append: " + targetParentTransform.name);
|
2022-10-29 19:56:00 +00:00
|
|
|
|
itemUI.container.SetActive(true);
|
2022-11-06 02:28:29 +00:00
|
|
|
|
itemUI.container.transform.SetParent(targetParentTransform, false);
|
|
|
|
|
Debug.Log("Append: " + "This should be working...");
|
2022-10-29 19:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
else if (itemUI.containerUIPrefab != null)
|
|
|
|
|
{
|
2022-11-06 02:28:29 +00:00
|
|
|
|
Debug.Log("Creating new");
|
|
|
|
|
itemUI.container = Instantiate(itemUI.containerUIPrefab, targetParentTransform, false);
|
|
|
|
|
itemUI.container.name = itemUI.container.name + " " + inCount;
|
|
|
|
|
inCount++;
|
2022-10-29 19:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
|
}
|
2022-10-29 19:56:00 +00:00
|
|
|
|
|
2022-11-06 02:28:29 +00:00
|
|
|
|
/*public void AppendUIToTransform()
|
2022-10-19 13:51:46 +00:00
|
|
|
|
{
|
2022-10-29 19:56:00 +00:00
|
|
|
|
if (PrefabUI != null && AttachToTransform != null)
|
|
|
|
|
{
|
|
|
|
|
instantiatedUI = Instantiate(PrefabUI, AttachToTransform);
|
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 19:56:00 +00:00
|
|
|
|
public void RemoveUIFromTransform()
|
|
|
|
|
{
|
|
|
|
|
if (instantiatedUI != null)
|
|
|
|
|
{
|
|
|
|
|
// TODO: May need to add more here
|
|
|
|
|
Destroy(instantiatedUI);
|
|
|
|
|
}
|
2022-11-06 02:28:29 +00:00
|
|
|
|
}*/
|
2022-10-29 19:56:00 +00:00
|
|
|
|
|
|
|
|
|
public void RemoveUIFromTransform(ItemUI itemUI)
|
|
|
|
|
{
|
2022-11-06 02:28:29 +00:00
|
|
|
|
if (itemUI != null)
|
2022-10-29 19:56:00 +00:00
|
|
|
|
{
|
|
|
|
|
if (itemUI.container != null)
|
|
|
|
|
{
|
2022-11-06 02:28:29 +00:00
|
|
|
|
Debug.Log("AppendUI:Remove:" + itemUI.gameObject.name + itemUI.container.name);
|
2022-10-29 19:56:00 +00:00
|
|
|
|
itemUI.container.transform.SetParent(itemUI.transform, false);
|
2022-11-06 02:28:29 +00:00
|
|
|
|
itemUI.container.SetActive(false);
|
2022-10-29 19:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GameObject InstantiatedUI()
|
|
|
|
|
{
|
|
|
|
|
return instantiatedUI;
|
|
|
|
|
}
|
2022-10-19 13:51:46 +00:00
|
|
|
|
}
|
2022-10-29 19:56:00 +00:00
|
|
|
|
}
|