153 lines
3.1 KiB
C#
153 lines
3.1 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using Cysharp.Threading.Tasks;
|
|||
|
|
using PhxhSDK;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using Object = UnityEngine.Object;
|
|||
|
|
|
|||
|
|
public class UINode: MonoBehaviour
|
|||
|
|
{
|
|||
|
|
protected List<string> LoadedAssets = new List<string>();
|
|||
|
|
protected bool isAutoCraete = true;
|
|||
|
|
//private UINodeLogic _nodeLogic;
|
|||
|
|
public static UINode LoadNode()
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected void ClearBind(Button button)
|
|||
|
|
{
|
|||
|
|
if (button)
|
|||
|
|
{
|
|||
|
|
button.onClick.RemoveAllListeners();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected void BindButton(Button button, Action func)
|
|||
|
|
{
|
|||
|
|
if (!button)
|
|||
|
|
return;
|
|||
|
|
button.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
func?.Invoke();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected void BindButton<T>(Button button, Action<T> func, T param)
|
|||
|
|
{
|
|||
|
|
if (!button)
|
|||
|
|
return;
|
|||
|
|
button.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
func?.Invoke(param);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected void BindButton<T,TK>(Button button, Action<T,TK> func, T param1, TK param2)
|
|||
|
|
{
|
|||
|
|
if (!button)
|
|||
|
|
return;
|
|||
|
|
button.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
func?.Invoke(param1, param2);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected T _GetComponent<T>(string path) where T: Behaviour
|
|||
|
|
{
|
|||
|
|
if (!transform)
|
|||
|
|
return null;
|
|||
|
|
if (!transform.Find(path))
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
var compGo = transform.Find(path).gameObject;
|
|||
|
|
if (compGo)
|
|||
|
|
{
|
|||
|
|
return compGo.GetComponent<T>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DebugUtil.LogError($"{name}未找到组件{typeof(T).Name}: {path}");
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected GameObject _FindObj(string path)
|
|||
|
|
{
|
|||
|
|
if (!transform.Find(path))
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
var compGo = transform.Find(path).gameObject;
|
|||
|
|
if (compGo)
|
|||
|
|
{
|
|||
|
|
return compGo;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DebugUtil.LogError($"{name}未找到节点:{path}");
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Awake()
|
|||
|
|
{
|
|||
|
|
OnAwake();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public virtual void OnAwake()
|
|||
|
|
{
|
|||
|
|
if (isAutoCraete)
|
|||
|
|
{
|
|||
|
|
//_nodeLogic = UIManager.Instance.CreateNewNode(this);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public virtual void OnStart()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public virtual void OnUpdate()
|
|||
|
|
{
|
|||
|
|
//_nodeLogic.OnUpdate();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public virtual void SetData(object data)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public virtual void OnShow()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public virtual void OnHide()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public virtual void Destroy()
|
|||
|
|
{
|
|||
|
|
//UIManager.Instance.DestroyNode(_nodeLogic);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public virtual void OnRelease()
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < LoadedAssets.Count; i++)
|
|||
|
|
{
|
|||
|
|
AssetManager.Instance.Unload(LoadedAssets[i]);
|
|||
|
|
}
|
|||
|
|
LoadedAssets.Clear();
|
|||
|
|
}
|
|||
|
|
}
|