Project_WL/Assets/Script/Ingame/Obj/IndicatorInfo.cs

62 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
public class IndicatorInfo : MonoBehaviourSingletonTemplate<IndicatorInfo>
{
[RuntimeInitializeOnLoadMethod]
static void OnRuntimeMethodLoad()
{
var go = new GameObject("IndicatorInfo").AddComponent<IndicatorInfo>();
DontDestroyOnLoad(go.gameObject);
}
Dictionary<string, List<GameObject>> dic_indicator = new Dictionary<string, List<GameObject>>();
public void All_Off_Imm()
{
foreach (var pair in dic_indicator)
{
List<GameObject> objList = pair.Value;
for (int i = 0; i < objList.Count; i++)
objList[i].SetActive(false);
}
}
public void Make_Indicator(string indicatorName, Action<GameObject> action)
{
if (dic_indicator.ContainsKey(indicatorName))
{
for (int i = 0; i < dic_indicator[indicatorName].Count; i++)
{
if (!dic_indicator[indicatorName][i].activeInHierarchy)
{
action?.Invoke(dic_indicator[indicatorName][i]);
return;
}
}
}
AddrResourceMgr.Ins.LoadObject<GameObject>($"Assets/Res_Addr/Obj/{indicatorName}.prefab", handle =>
{
var go = DSUtil.Get_Clone(handle.Result);
go.transform.parent = transform;
AddrResourceMgr.Ins.Set_AddressableReleaseSelf(go);
go.SetActive(false);
action?.Invoke(go);
if (!dic_indicator.ContainsKey(indicatorName))
dic_indicator.Add(indicatorName, new List<GameObject>());
dic_indicator[indicatorName].Add(go);
});
}
public void Show_Indicator(string indicatorName, Vector3 pos, float showtime)
{
Make_Indicator(indicatorName, go =>
{
go.transform.position = pos;
go.SetActive(true);
CoroutineMgr.Ins.Set_Coroutine(() => { go.SetActive(false); }, showtime);
});
}
}