92 lines
2.4 KiB
C#
92 lines
2.4 KiB
C#
using UnityEngine;
|
|
|
|
public class uHonor : MonoBehaviour
|
|
{
|
|
public enum HonorPrefabType
|
|
{
|
|
Normal,
|
|
Bronze,
|
|
Silver,
|
|
Gold
|
|
}
|
|
|
|
[Header("Honor Prefabs")]
|
|
[SerializeField] private GameObject normalHonorPrefab;
|
|
[SerializeField] private GameObject bronzeHonorPrefab;
|
|
[SerializeField] private GameObject silverHonorPrefab;
|
|
[SerializeField] private GameObject goldHonorPrefab;
|
|
|
|
[Header("Honor Parent")]
|
|
[SerializeField] private Transform honorParent;
|
|
|
|
public Transform HonorParent => honorParent;
|
|
|
|
public void ClearHonors()
|
|
{
|
|
if (honorParent == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = honorParent.childCount - 1; i >= 0; i--)
|
|
{
|
|
Transform child = honorParent.GetChild(i);
|
|
if (child != null)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public GameObject SpawnHonor(HonorPrefabType prefabType)
|
|
{
|
|
if (honorParent == null)
|
|
{
|
|
Debug.LogWarning("[uHonor] honorParent is not assigned.");
|
|
return null;
|
|
}
|
|
|
|
GameObject prefab = GetHonorPrefab(prefabType);
|
|
if (prefab == null)
|
|
{
|
|
Debug.LogWarning($"[uHonor] Honor prefab for type {prefabType} is not assigned.");
|
|
return null;
|
|
}
|
|
|
|
return Instantiate(prefab, honorParent);
|
|
}
|
|
|
|
public GameObject SpawnHonor(GameObject prefab)
|
|
{
|
|
if (honorParent == null)
|
|
{
|
|
Debug.LogWarning("[uHonor] honorParent is not assigned.");
|
|
return null;
|
|
}
|
|
|
|
if (prefab == null)
|
|
{
|
|
Debug.LogWarning("[uHonor] Requested prefab is null.");
|
|
return null;
|
|
}
|
|
|
|
return Instantiate(prefab, honorParent);
|
|
}
|
|
|
|
public GameObject GetHonorPrefab(HonorPrefabType prefabType)
|
|
{
|
|
switch (prefabType)
|
|
{
|
|
case HonorPrefabType.Gold:
|
|
return goldHonorPrefab != null ? goldHonorPrefab : normalHonorPrefab;
|
|
case HonorPrefabType.Silver:
|
|
return silverHonorPrefab != null ? silverHonorPrefab : normalHonorPrefab;
|
|
case HonorPrefabType.Bronze:
|
|
return bronzeHonorPrefab != null ? bronzeHonorPrefab : normalHonorPrefab;
|
|
case HonorPrefabType.Normal:
|
|
default:
|
|
return normalHonorPrefab;
|
|
}
|
|
}
|
|
}
|