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

62 lines
2.0 KiB
C#
Raw Normal View History

2025-02-20 01:30:24 +00:00
using System;
2025-02-25 00:53:33 +00:00
using System.Collections.Generic;
2025-02-20 01:30:24 +00:00
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>>();
2025-02-25 00:53:33 +00:00
2025-06-19 21:43:04 +00:00
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);
}
}
2025-02-20 01:30:24 +00:00
public void Make_Indicator(string indicatorName, Action<GameObject> action)
{
2025-02-25 00:53:33 +00:00
if (dic_indicator.ContainsKey(indicatorName))
{
for (int i = 0; i < dic_indicator[indicatorName].Count; i++)
{
if (!dic_indicator[indicatorName][i].activeInHierarchy)
{
2025-05-23 22:18:32 +00:00
action?.Invoke(dic_indicator[indicatorName][i]);
return;
}
}
}
2025-05-23 22:18:32 +00:00
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);
});
2025-02-20 01:30:24 +00:00
}
}