2023-12-12 13:35:56 +08:00
|
|
|
|
using System;
|
2024-04-28 15:47:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using PhxhSDK;
|
2023-12-07 16:16:28 +08:00
|
|
|
|
using UnityEngine;
|
2023-12-12 13:35:56 +08:00
|
|
|
|
using UnityEngine.UI;
|
2024-04-28 15:47:12 +08:00
|
|
|
|
using Object = UnityEngine.Object;
|
2023-12-07 16:16:28 +08:00
|
|
|
|
|
|
|
|
|
|
public class UINode: MonoBehaviour
|
|
|
|
|
|
{
|
2024-04-28 15:47:12 +08:00
|
|
|
|
protected List<string> LoadedAssets = new List<string>();
|
2023-12-07 16:16:28 +08:00
|
|
|
|
public static UINode LoadNode()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-12 13:35:56 +08:00
|
|
|
|
protected void ClearBind(Button button)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.RemoveAllListeners();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void BindButton(Button button, Action func)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
func?.Invoke();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void BindButton<T>(Button button, Action<T> func, T param)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
func?.Invoke(param);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-01-08 16:44:05 +08:00
|
|
|
|
|
2024-10-08 11:01:38 +08:00
|
|
|
|
protected void BindButton<T,TK>(Button button, Action<T,TK> func, T param1, TK param2)
|
|
|
|
|
|
{
|
|
|
|
|
|
button.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
func?.Invoke(param1, param2);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-08 16:44:05 +08:00
|
|
|
|
protected T _GetComponent<T>(string path) where T: Behaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
var compGo = transform.Find(path).gameObject;
|
|
|
|
|
|
if (compGo)
|
|
|
|
|
|
{
|
|
|
|
|
|
return compGo.GetComponent<T>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DebugUtil.LogError($"{name}未找到组件{typeof(T).Name}: {path}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2023-12-12 13:35:56 +08:00
|
|
|
|
|
2024-08-08 12:19:32 +08:00
|
|
|
|
protected GameObject _FindObj(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
var compGo = transform.Find(path).gameObject;
|
|
|
|
|
|
if (compGo)
|
|
|
|
|
|
{
|
|
|
|
|
|
return compGo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DebugUtil.LogError($"{name}未找到节点:{path}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-28 15:47:12 +08:00
|
|
|
|
protected async UniTask<T> LoadAssetAsync<T>(string path) where T : Object
|
|
|
|
|
|
{
|
|
|
|
|
|
var asset = await AssetManager.Instance.LoadAssetAsync<T>(path);
|
|
|
|
|
|
if (!LoadedAssets.Contains(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadedAssets.Add(path);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return asset;
|
|
|
|
|
|
}
|
2024-11-04 18:11:51 +08:00
|
|
|
|
|
2024-04-28 15:47:12 +08:00
|
|
|
|
|
2023-12-07 19:31:28 +08:00
|
|
|
|
public virtual void OnAwake()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-07 16:16:28 +08:00
|
|
|
|
public virtual void OnStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void OnUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void SetData(object data)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-25 17:52:04 +08:00
|
|
|
|
|
|
|
|
|
|
public virtual void OnShow()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void OnHide()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-28 15:47:12 +08:00
|
|
|
|
|
|
|
|
|
|
public virtual void OnRelease()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < LoadedAssets.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
AssetManager.Instance.Unload(LoadedAssets[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
LoadedAssets.Clear();
|
|
|
|
|
|
}
|
2023-12-07 16:16:28 +08:00
|
|
|
|
}
|