2025-01-24 16:21:00 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using AnimationFlowCore;
|
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// UI元素节点。
|
|
|
|
|
|
/// <remarks>通过mono序列化来绑定ui节点的元素换取查找与ui的稳定性。</remarks>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HideMonoScript]
|
2025-01-26 20:55:39 +08:00
|
|
|
|
[AddComponentMenu("UI绑定工具")]
|
2025-01-24 16:21:00 +08:00
|
|
|
|
public class UIBindComponent : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
public class UIBindData
|
|
|
|
|
|
{
|
|
|
|
|
|
public UIBindData()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public UIBindData(string name, Component bindCom, string splictN)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = name;
|
|
|
|
|
|
BindCom = bindCom;
|
|
|
|
|
|
SplitName = splictN;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TableColumnWidth(200, Resizable = false)]
|
|
|
|
|
|
public string Name;
|
|
|
|
|
|
|
|
|
|
|
|
public Component BindCom;
|
|
|
|
|
|
|
|
|
|
|
|
[HideInTables] public string SplitName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ButtonGroup("Edit")]
|
|
|
|
|
|
[Button("全部删除")]
|
|
|
|
|
|
void ClearBindComponents()
|
|
|
|
|
|
{
|
|
|
|
|
|
//ScriptGenerator.ClearBindComponets(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ButtonGroup("Edit")]
|
|
|
|
|
|
[Button("删除空引用")]
|
|
|
|
|
|
void ClearNullRefrence()
|
|
|
|
|
|
{
|
|
|
|
|
|
//ScriptGenerator.ClearNullRefrence(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ButtonGroup("Edit")]
|
|
|
|
|
|
[Button("自动绑定组件")]
|
|
|
|
|
|
void BindComponent()
|
|
|
|
|
|
{
|
|
|
|
|
|
//ScriptGenerator.BindComponent(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ButtonGroup("Edit")]
|
|
|
|
|
|
[Button("生成绑定代码")]
|
|
|
|
|
|
void GenerateUIPanelScript()
|
|
|
|
|
|
{
|
|
|
|
|
|
//ScriptGenerator.GenerateUIPanelScript(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ButtonGroup("Edit", 20)]
|
|
|
|
|
|
[Button("Apply预制体")]
|
|
|
|
|
|
void ApplyPrefab()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (UIType == UIType.Window)
|
|
|
|
|
|
{
|
|
|
|
|
|
// ScriptGenerator.CreateWndUIPrefab(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// ScriptGenerator.CreateWidgetUIPrefab(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("UI类型")] [BoxGroup("基础设置", true)] [EnumPaging] [SerializeField]
|
|
|
|
|
|
public UIType UIType = UIType.Window;
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("UI层级")] [BoxGroup("基础设置", true)] [EnumPaging] [ShowIf("IsWindow", animate: true)] [SerializeField]
|
|
|
|
|
|
public UILayer UILayer = UILayer.UI;
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("UI缓存类型")] [BoxGroup("基础设置", true)] [EnumPaging] [ShowIf("IsWindow", animate: true)] [SerializeField]
|
|
|
|
|
|
public EUICacheType UICacheType = EUICacheType.None;
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("资源加载类型")] [BoxGroup("基础设置", true)] [EnumPaging] [ShowIf("IsWindow", animate: true)] [SerializeField]
|
|
|
|
|
|
public EUIResLoadType ResLoadType = EUIResLoadType.AssetBundle;
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("全屏")] [BoxGroup("基础设置", true)] [ShowIf("IsWindow", animate: true)] [SerializeField]
|
|
|
|
|
|
public bool FullScreen;
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("缓存时间")] [BoxGroup("基础设置", true)] [ShowIf("IsCache", animate: true)] [MinValue(0, Expression = "缓存倒计时不能小于0!")] [SerializeField]
|
|
|
|
|
|
public int CacheDuration = 60;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsWindow => UIType == UIType.Window;
|
|
|
|
|
|
public bool IsCache => UICacheType == EUICacheType.CountDown && IsWindow;
|
|
|
|
|
|
|
|
|
|
|
|
[HideInInspector] public string Location;
|
|
|
|
|
|
|
|
|
|
|
|
[HideInInspector] public string ScriptName;
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("UI动画配置文件")] [BoxGroup("附加配置", true)] [ShowIf("IsWindow", animate: true)] [SerializeField] [InlineButton("CreateUIAnimation", "Create")]
|
|
|
|
|
|
private AnimationFlow uiAnimation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void CreateUIAnimation()
|
|
|
|
|
|
{
|
|
|
|
|
|
uiAnimation = gameObject.GetOrAddComponent<AnimationFlow>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
[TableList(ShowIndexLabels = true, DrawScrollView = true, MaxScrollViewHeight = 200, AlwaysExpanded = true)] [ReadOnly]
|
|
|
|
|
|
public List<UIBindData> Elements = new List<UIBindData>();
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
[HideInInspector] public List<Component> bindComponents = new List<Component>();
|
|
|
|
|
|
|
|
|
|
|
|
public T FindChild<T>(int index) where T : Component
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index >= bindComponents.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("索引无效");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
T bindCom = bindComponents[index] as T;
|
|
|
|
|
|
if (bindCom == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("类型无效");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return bindCom;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ShowUITween()
|
|
|
|
|
|
{
|
|
|
|
|
|
uiAnimation?.Play("Show");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CloseUITween()
|
|
|
|
|
|
{
|
|
|
|
|
|
uiAnimation?.Play("Close");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
bindComponents.Clear();
|
|
|
|
|
|
bindComponents = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|