初始化

This commit is contained in:
come
2025-07-26 16:56:42 +08:00
parent 8291dbb91c
commit fa81439a8c
2574 changed files with 328492 additions and 2170 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 86a5ecb5e13f4487b1e55eb2558e6bff
timeCreated: 1679040266

View File

@@ -0,0 +1,42 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
//[DetailedInfoBox("UI 组件表 点击展开详细介绍", @"李胜扬")]
[LabelText("UI 组件表")]
[AddComponentMenu("YIUIBind/★★★UI Component Table 组件表★★★")]
public sealed partial class UIBindComponentTable:SerializedMonoBehaviour
{
[OdinSerialize]
[LabelText("所有绑定数据 最终数据")]
[ReadOnly]
[PropertyOrder(-9)]
private Dictionary<string,Component> m_AllBindDic = new Dictionary<string,Component>();
public IReadOnlyDictionary<string, Component> AllBindDic => m_AllBindDic;
private Component FindComponent(string comName)
{
m_AllBindDic.TryGetValue(comName, out var value);
if (value == null)
{
Logger.LogErrorContext(this,$" {name} 组件表中没有这个组件 {comName}");
}
return value;
}
public T FindComponent<T>(string comName) where T :Component
{
return (T)FindComponent(comName);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0af0d78ed910487782cd796592642ac5
timeCreated: 1679020044

View File

@@ -0,0 +1,203 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEditor;
using UnityEngine;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
//Editor
public sealed partial class UIBindComponentTable
{
[OdinSerialize]
[LabelText("所有绑定数据 编辑数据")]
[Searchable]
[HideReferenceObjectPicker]
[PropertyOrder(-10)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private List<UIBindPairData> m_AllBindPair = new List<UIBindPairData>();
[GUIColor(0, 1, 1)]
[LabelText("空名称自动设置")]
[SerializeField]
[HorizontalGroup("SetGroup")]
[PropertyOrder(-99)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private bool m_AutoSetNullName = true;
[GUIColor(0, 1, 1)]
[LabelText("空名称额外添加类型后缀")]
[SerializeField]
[ShowIf("m_AutoSetNullName")]
[HorizontalGroup("SetGroup")]
[PropertyOrder(-99)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private bool m_NullNameAddTypeName = true;
[GUIColor(1, 1, 0)]
[Button("自动检查", 30)]
[PropertyOrder(-100)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
public void AutoCheck()
{
if (!UIOperationHelper.CheckUIOperation(this)) return;
CheckAllBindName();
}
public void EditorAddComponent(Component component, string setName = "")
{
if (!UIOperationHelper.CheckUIOperation(this)) return;
AutoCheck();
setName = GetAutoGenName(component, setName);
if (m_AllBindDic.ContainsValue(component))
{
UnityTipsHelper.CallBackOk(
$" {name} 对象上的 {component.GetType()} 这个组件已经存在了 重复对象 {component.name} 相同组件只能有一个",
() => { Selection.activeGameObject = this.gameObject; });
return;
}
if (m_AllBindDic.ContainsKey(setName))
{
UnityTipsHelper.CallBackOk(
$"{setName} 这个命名已经存在了 重复添加 必须命名唯一的名称",
() => { Selection.activeGameObject = this.gameObject; });
return;
}
m_AllBindPair.Add(
new UIBindPairData
{
Name = setName,
Component = component
});
AutoCheck();
}
public string GetAutoGenName(Component component, string name)
{
if (component == null)
{
Logger.LogErrorContext(this, $"{name} 空对象 所以 {name} 已忽略");
return "";
}
if (!name.CheckFirstName(NameUtility.ComponentName))
{
if (string.IsNullOrEmpty(name))
{
if (!m_AutoSetNullName)
{
return "";
}
if (m_NullNameAddTypeName)
{
name = $"{NameUtility.FirstName}{NameUtility.ComponentName}{component.name}{component.GetType().Name}";
}
else
{
name = $"{NameUtility.FirstName}{NameUtility.ComponentName}{component.name}";
}
}
else
{
name = $"{NameUtility.FirstName}{NameUtility.ComponentName}{name}";
}
}
name = name.ChangeToBigName(NameUtility.ComponentName);
return name;
}
/// <summary>
/// 检查所有绑定命名
/// 必须m_ 开头
/// 如果没用命名则使用对象的名字拼接
/// 会尝试强制修改
/// 如果还有同名则报错
/// </summary>
private void CheckAllBindName()
{
m_AllBindDic.Clear();
if (m_AllBindPair == null || m_AllBindPair.Count < 1) return;
for (var i = 0; i < m_AllBindPair.Count; i++)
{
var bindPair = m_AllBindPair[i];
var oldName = bindPair.Name;
var component = bindPair.Component;
if (component == null)
{
Logger.LogErrorContext(this, $"{name} 空对象 所以 {oldName} 已忽略");
continue;
}
var newName = GetAutoGenName(component, oldName);
if (string.IsNullOrEmpty(newName))
{
Logger.LogErrorContext(this, $"{name} 空名称 所以已忽略");
continue;
}
if (oldName != newName)
{
bindPair.Name = newName;
}
if (string.IsNullOrEmpty(bindPair.Name))
{
Logger.LogErrorContext(this, $"{name} 存在空名称 {bindPair.Component?.name} 已忽略");
continue;
}
if (bindPair.Component == null)
{
Logger.LogErrorContext(this, $"{name} 空对象 所以 {bindPair.Name} 已忽略");
continue;
}
if (m_AllBindDic.ContainsValue(bindPair.Component))
{
Logger.LogErrorContext(bindPair.Component, $"{name} 这个组件已经存在了 重复对象 {bindPair.Component.name} 已忽略");
continue;
}
if (m_AllBindDic.ContainsKey(bindPair.Name))
{
Logger.LogErrorContext(bindPair.Component, $"{name} 这个命名已经存在了 重复添加 {bindPair.Name} 已忽略");
continue;
}
m_AllBindDic.Add(bindPair.Name, bindPair.Component);
}
}
}
/// <summary>
/// 绑定数据对应关系
/// </summary>
[Serializable]
[HideLabel]
[HideReferenceObjectPicker]
internal class UIBindPairData
{
[LabelText("名称")]
public string Name ;
[LabelText("对象")]
public Component Component;
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fa456a6e75ac4edd9f18ba263f371296
timeCreated: 1685500528

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b917edcc4aa449bcad51b9656bed0dec
timeCreated: 1679040282

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 01b6836f777e40e99a02a89af7384a92
timeCreated: 1679126218

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2f2e524770804e8e8ae125b829d6883b
timeCreated: 1685518355

View File

@@ -0,0 +1,217 @@
using System;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
[Serializable]
[HideReferenceObjectPicker]
internal class UIDataBoolRef
{
//当前的变量
[OdinSerialize]
[HideInInspector]
private UIData m_Data;
public UIData Data => m_Data;
[ShowInInspector]
[LabelText("名称")]
[ReadOnly]
private string m_DataName;
#if UNITY_EDITOR
[ShowInInspector]
[LabelText("值")]
[ReadOnly]
private string m_DataValue;
#endif
[SerializeField]
#if UNITY_EDITOR
[OnValueChanged("OnValueChangedCompareMode")]
#endif
[ShowIf("ShowCompareMode")]
private UICompareModeEnum m_CompareMode = UICompareModeEnum.Equal;
private bool ShowCompareMode()
{
if (m_Data.DataValue.UIBindDataType == EUIBindDataType.Int ||
m_Data.DataValue.UIBindDataType == EUIBindDataType.Float)
{
return true;
}
return false;
}
[OdinSerialize]
[HideLabel]
[ShowInInspector]
public UIDataValue m_ReferenceData;
public UIDataValue ReferenceData => m_ReferenceData;
[SerializeField]
[LabelText("取反")]
[ShowInInspector]
private bool m_Reverse;
private UIDataBoolRef()
{
}
public UIDataBoolRef(UIData data)
{
Refresh(data);
}
//刷新数据
public void Refresh(UIData data)
{
m_Data = data;
m_DataName = m_Data.Name;
#if UNITY_EDITOR
m_DataValue = m_Data.GetValueToString();
#endif
if (m_Data.DataValue.UIBindDataType == EUIBindDataType.Bool ||
m_Data.DataValue.UIBindDataType == EUIBindDataType.String)
{
m_CompareMode = UICompareModeEnum.Equal;
}
if (m_ReferenceData == null || (m_ReferenceData.UIBindDataType != m_Data.DataValue.UIBindDataType))
{
m_ReferenceData = UIDataHelper.GetNewDataValue(m_Data.DataValue.UIBindDataType);
}
}
#if UNITY_EDITOR
//比较运算的修改
private void OnValueChangedCompareMode()
{
if (m_Data.DataValue.UIBindDataType == EUIBindDataType.String && m_CompareMode != UICompareModeEnum.Equal)
{
m_CompareMode = UICompareModeEnum.Equal;
UnityTipsHelper.ShowError($"字符串类型 只允许使用 == 运算判断 != 使用取反");
}
if (m_Data.DataValue.UIBindDataType == EUIBindDataType.Bool && m_CompareMode != UICompareModeEnum.Equal)
{
m_CompareMode = UICompareModeEnum.Equal;
UnityTipsHelper.ShowError($"布尔类型 只允许使用 == 运算判断 != 使用取反");
}
}
#endif
/// <summary>
/// 获取最终比较结果
/// </summary>
/// <returns></returns>
public bool GetResult()
{
if (m_Data?.DataValue == null)
{
return false;
}
var result = false;
switch (m_Data.DataValue.UIBindDataType)
{
case EUIBindDataType.Bool:
var valueBool = m_Data.GetValue<bool>();
var referenceBool = m_ReferenceData.GetValue<bool>();
result = valueBool == referenceBool;
break;
case EUIBindDataType.Int:
var valueInteger = m_Data.GetValue<int>();
var referenceInteger = m_ReferenceData.GetValue<int>();
switch (m_CompareMode)
{
case UICompareModeEnum.Less:
result = valueInteger < referenceInteger;
break;
case UICompareModeEnum.LessEqual:
result = valueInteger <= referenceInteger;
break;
case UICompareModeEnum.Equal:
result = valueInteger == referenceInteger;
break;
case UICompareModeEnum.Great:
result = valueInteger > referenceInteger;
break;
case UICompareModeEnum.GreatEqual:
result = valueInteger >= referenceInteger;
break;
default:
Logger.LogError($"不可能有其他类型 不允许扩展 {m_CompareMode}");
break;
}
break;
case EUIBindDataType.Float:
var valueFloat = m_Data.GetValue<float>();
var referenceFloat = m_ReferenceData.GetValue<float>();
switch (m_CompareMode)
{
case UICompareModeEnum.Less:
result = valueFloat < referenceFloat;
break;
case UICompareModeEnum.LessEqual:
result = valueFloat <= referenceFloat;
break;
case UICompareModeEnum.Equal:
result = Mathf.Approximately(
valueFloat, referenceFloat);
break;
case UICompareModeEnum.Great:
result = valueFloat > referenceFloat;
break;
case UICompareModeEnum.GreatEqual:
result = valueFloat >= referenceFloat;
break;
default:
Logger.LogError($"不可能有其他类型 不允许扩展 {m_CompareMode}");
break;
}
break;
case EUIBindDataType.String:
var valueString = m_Data.GetValue<string>();
var referenceString = m_ReferenceData.GetValue<string>();
switch (m_CompareMode)
{
case UICompareModeEnum.Equal:
result = valueString == referenceString;
break;
case UICompareModeEnum.Less:
case UICompareModeEnum.LessEqual:
case UICompareModeEnum.Great:
case UICompareModeEnum.GreatEqual:
default:
Logger.LogError($"String 的 bool 比较只支持 == 取反就是 != 不支持其他");
break;
}
break;
//case UIDataType.Asset:
//case UIDataType.Color:
default:
Logger.LogError($"类型比较 不支持这个类型 {m_Data.DataValue.UIBindDataType}");
return false;
}
if (m_Reverse)
{
result = !result;
}
return result;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77fd80a29f7745439791b946633e6870
timeCreated: 1685518281

View File

@@ -0,0 +1,61 @@
using System;
using Sirenix.OdinInspector;
using UnityEngine;
namespace YIUIBind
{
/// <summary>
/// 数据选择数据展示
/// </summary>
[Serializable]
[HideLabel]
[HideReferenceObjectPicker]
public class UIDataSelect
{
[LabelText("名称")]
[ReadOnly]
private string m_DataName;
[ShowInInspector]
[LabelText("类型")]
[ReadOnly]
private EUIBindDataType m_DataType;
#if UNITY_EDITOR
[ShowInInspector]
[LabelText("值")]
[ReadOnly]
private string m_DataValue;
#endif
[SerializeField]
[HideInInspector]
private UIData m_Data;
public UIData Data => m_Data;
private UIDataSelect()
{
}
public UIDataSelect(UIData uiData)
{
RefreshData(uiData);
}
public void RefreshData(UIData uiData)
{
m_Data = uiData;
m_DataName = m_Data.Name;
m_DataType = m_Data.DataValue.UIBindDataType;
#if UNITY_EDITOR
m_DataValue = m_Data.GetValueToString();
#endif
}
public void ChangeName(string name)
{
m_DataName = name;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0ce57754af924379806252539d438129
timeCreated: 1685518418

View File

@@ -0,0 +1,126 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using Sirenix.OdinInspector;
using UnityEngine;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
/// <summary>
/// 所有绑定数据基类
/// </summary>
[ExecuteInEditMode]
[HideLabel]
[HideReferenceObjectPicker]
public abstract class UIDataBind : SerializedMonoBehaviour
{
[Required("必须选择")]
[SerializeField]
[HideLabel]
[HideReferenceObjectPicker]
[ReadOnly]
[PropertyOrder(-999)]
private UIBindDataTable m_DataTable;
public UIBindDataTable DataTable => m_DataTable;
private bool m_Binded;
internal UIData FindData(string dataName)
{
if (string.IsNullOrEmpty(dataName))
{
Logger.LogWarning($"{name} 不能找一个空变量 请检查配置");
return null;
}
var data = m_DataTable?.FindData(dataName);
if (data == null)
{
if (m_DataTable == null)
{
Logger.LogErrorContext(this, $"{name} 未设置变量表 所以无法找到变量 {dataName} 请检查配置");
return null;
}
Logger.LogErrorContext(this, $"{name} 没有找到这个变量 {dataName} 请检查配置");
return null;
}
return data;
}
//会被上一级的UIDataTable初始化
//也可以被自己初始化 根据顺序
internal void Initialize(bool refresh = false)
{
if (!refresh && m_Binded) return;
m_Binded = true;
RefreshDataTable();
UnBindData();
BindData();
OnRefreshData();
}
protected void OnDestroy()
{
UnBindData();
m_Binded = false;
}
/// <summary>
/// 绑定
/// </summary>
protected abstract void BindData();
/// <summary>
/// 解绑
/// </summary>
protected abstract void UnBindData();
/// <summary>
/// 刷新
/// 所有绑定 解绑过后刷新
/// 相当于初始化 所以之类非必要不要自己写Awake Start之类的
/// 记得一定要调用base.OnRefreshData(); 以免多重基础后的错误问题
/// </summary>
protected abstract void OnRefreshData();
private void RefreshDataTable()
{
if (m_DataTable == null)
{
m_DataTable = this.GetComponentInParentHard<UIBindDataTable>();
}
}
#if UNITY_EDITOR
/// <summary>
/// 因为UIData被删除了
/// 所以对应的需要处理相关关联绑定
/// </summary>
public abstract void RemoveBindData(UIData data);
protected void OnValidate()
{
if (UIOperationHelper.IsPlaying() && m_Binded)
{
return;
}
m_Binded = true;
RefreshDataTable();
UnBindData();
BindData();
OnRefreshData();
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 11085cd88f3a473d99a8e40a714d991f
timeCreated: 1679040750

View File

@@ -0,0 +1,134 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
/// <summary>
/// bool类型基类
/// </summary>
public abstract class UIDataBindBool : UIDataBindSelectBase
{
[SerializeField]
[LabelText("所有结果逻辑")]
#if UNITY_EDITOR
[EnableIf("@UIOperationHelper.CommonShowIf()")]
#endif
private UIBooleanLogic m_BooleanLogic = UIBooleanLogic.And;
[OdinSerialize]
[LabelText("所有计算结果的变量")]
[ListDrawerSettings(IsReadOnly = true)]
#if UNITY_EDITOR
[EnableIf("@UIOperationHelper.CommonShowIf()")]
#endif
private List<UIDataBoolRef> m_Datas = new List<UIDataBoolRef>();
protected override int Mask()
{
return 1 << (int)EUIBindDataType.Bool |
1 << (int)EUIBindDataType.Int |
1 << (int)EUIBindDataType.Float |
1 << (int)EUIBindDataType.String;
}
/// <summary>
/// 结果
/// </summary>
protected bool GetResult()
{
if (m_Datas == null || m_Datas.Count <= 0)
{
return false;
}
switch (m_BooleanLogic)
{
case UIBooleanLogic.And:
var resultAnd = true;
foreach (var v in m_Datas)
{
if (v != null)
{
resultAnd = resultAnd && v.GetResult();
}
}
return resultAnd;
case UIBooleanLogic.Or:
var resultOr = false;
foreach (var v in m_Datas)
{
if (v != null)
{
resultOr = resultOr || v.GetResult();
}
}
return resultOr;
default:
Logger.LogError($"没有其他逻辑 也不允许有其他逻辑 {m_BooleanLogic}");
return false;
}
}
//刷新后 绑定后的事件
protected override void OnRefreshData()
{
//循环比较
//没有的就删除
//缺少的就添加
//且同步修改后的名字
foreach (var target in DataSelectDic.Values)
{
var exist = false;
//我的
foreach (var self in m_Datas)
{
if (target.Data.DataGuid == self.Data.DataGuid)
{
//存在则刷新
self.Refresh(target.Data);
exist = true;
break;
}
}
if (exist) continue;
//说明不存在
m_Datas.Add(new UIDataBoolRef(target.Data));
}
//需要移除 所以从后往前
for (var i = m_Datas.Count - 1; i >= 0; i--)
{
var self = m_Datas[i];
var exist = false;
foreach (var target in DataSelectDic.Values)
{
if (target.Data.DataGuid == self.Data.DataGuid)
{
exist = true;
break;
}
}
if (exist) continue;
//说明不一样
m_Datas.RemoveAt(i);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7898c46a6c7474b9a7bf2d479c2a337
timeCreated: 1679149445

View File

@@ -0,0 +1,145 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
/// <summary>
/// 基类 都需要选择绑定数据时
/// </summary>
[Serializable]
public abstract partial class UIDataBindSelectBase : UIDataBind
{
[OdinSerialize]
[LabelText("所有已绑定数据")]
[ShowInInspector]
[DictionaryDrawerSettings(KeyLabel = "数据名称", ValueLabel = "数据内容", IsReadOnly = true,
DisplayMode = DictionaryDisplayOptions.ExpandedFoldout)]
[ReadOnly]
#if UNITY_EDITOR
[EnableIf("@UIOperationHelper.CommonShowIf()")]
#endif
private Dictionary<string, UIDataSelect> m_DataSelectDic = new Dictionary<string, UIDataSelect>();
public IReadOnlyDictionary<string, UIDataSelect> DataSelectDic => m_DataSelectDic;
#region 便
protected T GetFirstValue<T>(T defaultValue = default)
{
if (DataSelectDic.Count <= 0) return default;
var data = DataSelectDic?.First().Value?.Data;
return data == null ? default : data.GetValue<T>(defaultValue);
}
protected void SetFirstValue<T>(T value, bool force = false)
{
if (DataSelectDic.Count <= 0) return;
DataSelectDic?.First().Value?.Data?.Set<T>(value, force);
}
#endregion
#region
protected override void BindData()
{
foreach (var dataSelect in m_DataSelectDic)
{
var dataName = dataSelect.Key;
if (string.IsNullOrEmpty(dataName))
{
continue;
}
var data = FindData(dataName);
if (data == null)
{
continue;
}
data.AddValueChangeAction(OnValueChanged);
#if UNITY_EDITOR
data.OnDataChangAction += OnNameChanged;
data.AddBind(this);
#endif
dataSelect.Value.RefreshData(data);
}
OnValueChanged();
}
private void UnbindData(string dataName)
{
if (m_DataSelectDic.TryGetValue(dataName, out var value))
{
UnbindData(value);
}
}
private void UnbindData(UIDataSelect value)
{
var data = value?.Data;
if (data == null)
{
Logger.LogErrorContext(this, $"{name}空数据 请检查为什么 当前是否不在预制件编辑器中使用了");
return;
}
data.RemoveValueChangeAction(OnValueChanged);
#if UNITY_EDITOR
data.OnDataChangAction -= OnNameChanged;
data.RemoveBind(this);
#endif
}
//解除所有绑定
protected override void UnBindData()
{
foreach (var dic in m_DataSelectDic)
{
UnbindData(dic.Value);
}
}
#endregion
/// <summary>
/// 数据改变时
/// </summary>
protected abstract void OnValueChanged();
//没有特别需要处理的 但是为了结构一致 所以继承的都要调用
//要调用base.OnRefreshData(); 以免多重基础后的错误问题
protected override void OnRefreshData()
{
}
/// <summary>
/// 可选择类型 用掩码
/// </summary>
/// <returns></returns>
protected abstract int Mask();
/// <summary>
/// 可选择最大数量 默认最大
/// </summary>
/// <returns></returns>
protected virtual int SelectMax()
{
return int.MaxValue;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8cc98c3d03944ed6ab94be9a7524b41d
timeCreated: 1679066804

View File

@@ -0,0 +1,196 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public abstract partial class UIDataBindSelectBase
{
[ValueDropdown("GetBindKeys")]
[OnValueChanged("OnBindKeySelected")]
[ShowInInspector]
[PropertyOrder(-10)]
[LabelText("选择绑定数据")]
[NonSerialized]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private string m_SelectBindKey;
[GUIColor(0, 1, 0)]
[ButtonGroup("Select")]
[Button("添加")]
[PropertyOrder(-9)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private void AddSelect()
{
if (string.IsNullOrEmpty(m_SelectBindKey))
{
var tips = $"请选择";
UnityTipsHelper.Show(tips);
Logger.LogError(tips);
return;
}
if (m_DataSelectDic.Count >= SelectMax())
{
//不要问为什么不直接替换..
UnityTipsHelper.ShowErrorContext(this, $"当前数据只允许最多选择 {SelectMax()} 个 已超过可选择上限 请先移除其他");
m_SelectBindKey = "";
return;
}
if (m_DataSelectDic.ContainsKey(m_SelectBindKey))
{
var tips = $"已存在 {m_SelectBindKey}";
UnityTipsHelper.ShowError(tips);
m_SelectBindKey = "";
return;
}
var uiData = FindData(m_SelectBindKey);
if (uiData == null)
{
var tips = $"没找到这个数据 {m_SelectBindKey}";
UnityTipsHelper.ShowError(tips);
m_SelectBindKey = "";
return;
}
var data = new UIDataSelect(uiData);
m_DataSelectDic.Add(m_SelectBindKey, data);
m_SelectBindKey = "";
base.OnValidate();
}
[GUIColor(1, 1, 0)]
[ButtonGroup("Select")]
[Button("移除")]
[PropertyOrder(-8)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private void RemoveSelect()
{
if (string.IsNullOrEmpty(m_SelectBindKey))
{
var tips1 = $"请选择";
UnityTipsHelper.Show(tips1);
Logger.LogError(tips1);
return;
}
RemoveSelect(m_SelectBindKey);
m_SelectBindKey = "";
}
private void RemoveSelect(string name)
{
if (!m_DataSelectDic.ContainsKey(name))
{
var tips = $"{name} 不存在无法移除";
UnityTipsHelper.ShowError(tips);
return;
}
UnbindData(name);
m_DataSelectDic.Remove(name);
OnValidate();
}
private bool IsValid(EUIBindDataType type)
{
return (1 << (int)type & Mask()) != 0;
}
//找到黑板字典里的所有数据
private IEnumerable<string> GetBindKeys()
{
var allKey = new List<string>();
if (DataTable == null)
{
Logger.LogError($"请检查未设置 数据表");
return allKey;
}
//我现在有的 可能是错误的需要移除的
foreach (var key in m_DataSelectDic.Keys)
{
if (DataTable.FindData(key) == null)
{
allKey.Add($"[X]{key}");
}
}
//表中可用的
foreach (var data in DataTable.DataDic.Values)
{
if (IsValid(data.DataValue.UIBindDataType))
{
if (string.IsNullOrEmpty(data.Name))
{
Logger.LogErrorContext(this, $"{name} 这个表中有null名称 请检查");
continue;
}
var ex = " ";
foreach (var key in m_DataSelectDic.Keys)
{
if (key == data.Name)
{
ex = "[√]";
break;
}
}
ex = $"{ex}[{data.DataValue.UIBindDataType}] ";
allKey.Add($"{ex}{data.Name}");
}
}
return allKey;
}
const string m_Pattern = @"\[[^\]]*\]|\s";
//选择这个数据然后刷新
private void OnBindKeySelected()
{
if (string.IsNullOrEmpty(m_SelectBindKey))
{
return;
}
m_SelectBindKey = System.Text.RegularExpressions.Regex.Replace(m_SelectBindKey, m_Pattern, "");
}
public override void RemoveBindData(UIData data)
{
RemoveSelect(data.Name);
}
/// <summary>
/// 数据的名称的改变
/// </summary>
private void OnNameChanged(UIData change)
{
var keys = m_DataSelectDic.Keys.ToArray();
foreach (var key in keys)
{
var data = m_DataSelectDic[key];
if (change == data.Data) //换key
{
m_DataSelectDic.Remove(key); //移除老的
m_DataSelectDic.Add(change.Name, data); //添加新的
}
}
OnValidate();
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 52d975ffeaa4482ab7250013e07eb025
timeCreated: 1685518499

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 432e6cb4148a4efca2e5de7c4d328716
timeCreated: 1679126201

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 94949b2286ca4b8cb8edcb61e8128995
timeCreated: 1679583315

View File

@@ -0,0 +1,54 @@
using Sirenix.OdinInspector;
namespace YIUIBind
{
[LabelText("类型")]
//禁止修改ID
//因为涉及到Mask 所以最高只有32个 请注意
//@lsy
public enum EUIBindDataType
{
[LabelText("Bool")]
Bool = 0,
[LabelText("String")]
String = 1,
[LabelText("Int")]
Int = 2,
[LabelText("Float")]
Float = 3,
[LabelText("Vector3")]
Vector3 = 4,
[LabelText("List_Int")]
List_Int = 5,
[LabelText("List_Long")]
List_Long = 6,
[LabelText("List_String")]
List_String = 7,
[LabelText("Long")]
Long = 8,
[LabelText("Uint")]
Uint = 9,
[LabelText("Ulong")]
Ulong = 10,
[LabelText("Double")]
Double = 11,
[LabelText("Vector2")]
Vector2 = 12,
[LabelText("Color")]
Color = 13,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b87d4d0fdd6a484ebb6151221dbc5af3
timeCreated: 1679583315

View File

@@ -0,0 +1,7 @@
namespace YIUIBind
{
public interface IUIDataValue<T>
{
T GetValue();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1d6ceca2b6c5420188371f6aef28e26d
timeCreated: 1679583315

View File

@@ -0,0 +1,49 @@
using System;
using Sirenix.OdinInspector;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
[Serializable]
[HideLabel]
public abstract class UIDataValue
{
[ShowInInspector]
[PropertyOrder(-99)]
public abstract EUIBindDataType UIBindDataType { get; }
public abstract Type UIDataValueType { get; }
/// <summary>
/// 从另一个Value设置数据
/// </summary>
internal abstract bool SetValueFrom(UIDataValue dataValue);
//值改变消息 无参
private Action m_OnValueChangAction;
internal void AddValueChangeAction(Action action)
{
m_OnValueChangAction -= action;
m_OnValueChangAction += action;
}
internal void RemoveValueChangeAction(Action action)
{
m_OnValueChangAction -= action;
}
internal void InvokeValueChangAction()
{
try
{
m_OnValueChangAction?.Invoke();
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5f110bc67c1b4c9386acdea4c7858873
timeCreated: 1679583315

View File

@@ -0,0 +1,107 @@
using System;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
/// <summary>
/// 数据基类
/// 泛型 扩展请参考其他数据 注意满足需求
/// 具体请查看文档
/// @李胜扬
/// </summary>
[Serializable]
public abstract class UIDataValueBase<T> : UIDataValue, IUIDataValue<T>
{
[OdinSerialize]
[LabelText("值")]
[HideReferenceObjectPicker]
[Delayed]
#if UNITY_EDITOR
[OnValueChanged("OnValueChanged")]
#endif
private T m_Value;
#if UNITY_EDITOR
private void OnValueChanged()
{
InvokeValueChangAction();
}
#endif
//基类中的事件 双参数 1 新值 2 老值
private Action<T, T> m_OnValueChangeAction;
public void AddValueChangeAction(Action<T, T> action)
{
m_OnValueChangeAction -= action;
m_OnValueChangeAction += action;
}
public void RemoveValueChangeAction(Action<T, T> action)
{
m_OnValueChangeAction -= action;
}
public void InvokeValueChangAction(T newValue, T oldValue)
{
try
{
m_OnValueChangeAction?.Invoke(newValue, oldValue);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
public T GetValue()
{
return m_Value;
}
internal sealed override bool SetValueFrom(UIDataValue dataValue)
{
return SetValueFrom(dataValue, true); //必须使用强制刷新
}
public bool SetValueFrom(UIDataValue dataValue, bool force, bool notify = true)
{
if (dataValue == null)
{
Logger.LogError($"{typeof(T)} 失败Value为空");
return false;
}
if (!(dataValue is UIDataValueBase<T>))
{
Logger.LogError($"失败,类型不一致 当前类型 {typeof(T)} 传入类型 {dataValue.UIDataValueType}");
return false;
}
return SetValue(dataValue.GetValue<T>(), force, notify);
}
public bool SetValue(T value, bool force = false, bool notify = true)
{
if (!force && EqualsValue(value)) return false;
var oldValue = m_Value;
SetValueFrom(value);
InvokeValueChangAction();
if (notify)
InvokeValueChangAction(value, oldValue);
return true;
}
protected virtual void SetValueFrom(T value)
{
m_Value = value;
}
protected abstract bool EqualsValue(T value);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e4e9883c72ee421c9c08e6981187f31b
timeCreated: 1679583315

View File

@@ -0,0 +1,122 @@
using System;
using Sirenix.OdinInspector;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueBool : UIDataValueBase<bool>, IEquatable<UIDataValueBool>
{
public override string ToString()
{
return GetValue() ? "True" : "False";
}
public override Type UIDataValueType => typeof(bool);
public override EUIBindDataType UIBindDataType => EUIBindDataType.Bool;
#region
//类对比
public bool Equals(UIDataValueBool other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
//值对比
protected override bool EqualsValue(bool value)
{
return GetValue() == value;
}
//值对比 少用 这个有装箱拆箱的性能开销
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (bool)obj;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueBool lhs, UIDataValueBool rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueBool lhs, UIDataValueBool rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueBool lhs, UIDataValueBool rhs)
{
Logger.LogError($"注意你正在对比2个bool的 大小 >");
return false;
}
public static bool operator <(UIDataValueBool lhs, UIDataValueBool rhs)
{
Logger.LogError($"注意你正在对比2个bool的 大小 <");
return false;
}
public static bool operator >=(UIDataValueBool lhs, UIDataValueBool rhs)
{
Logger.LogError($"注意你正在对比2个bool的 大小 >=");
return false;
}
public static bool operator <=(UIDataValueBool lhs, UIDataValueBool rhs)
{
Logger.LogError($"注意你正在对比2个bool的 大小 <=");
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 06279e9b141647768848575895fca908
timeCreated: 1679583315

View File

@@ -0,0 +1,125 @@
using System;
using Sirenix.OdinInspector;
using UnityEngine;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueColor : UIDataValueBase<Color>, IEquatable<UIDataValueColor>
{
public override string ToString()
{
return GetValue().ToString();
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.Color;
public UIDataValueColor()
{
SetValue(Color.white);
}
public override Type UIDataValueType => typeof(Color);
#region
public bool Equals(UIDataValueColor other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
protected override bool EqualsValue(Color value)
{
return GetValue() == value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (Color)obj;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueColor lhs, UIDataValueColor rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueColor lhs, UIDataValueColor rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueColor lhs, UIDataValueColor rhs)
{
Logger.LogError($"请不要比较这个类型 {EUIBindDataType.Color}");
return false;
}
public static bool operator <(UIDataValueColor lhs, UIDataValueColor rhs)
{
Logger.LogError($"请不要比较这个类型 {EUIBindDataType.Color}");
return false;
}
public static bool operator >=(UIDataValueColor lhs, UIDataValueColor rhs)
{
Logger.LogError($"请不要比较这个类型 {EUIBindDataType.Color}");
return false;
}
public static bool operator <=(UIDataValueColor lhs, UIDataValueColor rhs)
{
Logger.LogError($"请不要比较这个类型 {EUIBindDataType.Color}");
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e16a881d29b647e1a57cf3b228d26c9c
timeCreated: 1681373403

View File

@@ -0,0 +1,114 @@
using System;
using Sirenix.OdinInspector;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueFloat : UIDataValueBase<float>, IEquatable<UIDataValueFloat>
{
public override string ToString()
{
return GetValue().ToString();
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.Float;
public override Type UIDataValueType => typeof(float);
#region
public bool Equals(UIDataValueFloat other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return Math.Abs(GetValue() - other.GetValue()) < 0.0001f;
}
protected override bool EqualsValue(float value)
{
return Math.Abs(GetValue() - value) < 0.0001f;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return Math.Abs(GetValue() - (float)obj) < 0.0001f;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueFloat lhs, UIDataValueFloat rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueFloat lhs, UIDataValueFloat rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueFloat lhs, UIDataValueFloat rhs)
{
return lhs.GetValue() > rhs.GetValue();
}
public static bool operator <(UIDataValueFloat lhs, UIDataValueFloat rhs)
{
return lhs.GetValue() < rhs.GetValue();
}
public static bool operator >=(UIDataValueFloat lhs, UIDataValueFloat rhs)
{
return lhs.GetValue() >= rhs.GetValue();
}
public static bool operator <=(UIDataValueFloat lhs, UIDataValueFloat rhs)
{
return lhs.GetValue() <= rhs.GetValue();
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fac919685af3499797a9f776fed8a74d
timeCreated: 1679583315

View File

@@ -0,0 +1,114 @@
using System;
using Sirenix.OdinInspector;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueInt : UIDataValueBase<int>, IEquatable<UIDataValueInt>
{
public override string ToString()
{
return GetValue().ToString();
}
public override Type UIDataValueType => typeof(int);
public override EUIBindDataType UIBindDataType => EUIBindDataType.Int;
#region
public bool Equals(UIDataValueInt other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
protected override bool EqualsValue(int value)
{
return GetValue() == value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (int)obj;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueInt lhs, UIDataValueInt rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueInt lhs, UIDataValueInt rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueInt lhs, UIDataValueInt rhs)
{
return lhs.GetValue() > rhs.GetValue();
}
public static bool operator <(UIDataValueInt lhs, UIDataValueInt rhs)
{
return lhs.GetValue() < rhs.GetValue();
}
public static bool operator >=(UIDataValueInt lhs, UIDataValueInt rhs)
{
return lhs.GetValue() >= rhs.GetValue();
}
public static bool operator <=(UIDataValueInt lhs, UIDataValueInt rhs)
{
return lhs.GetValue() <= rhs.GetValue();
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 00f47d821b13491a8e570c9cba7e73dc
timeCreated: 1679583315

View File

@@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueListInt : UIDataValueBase<List<int>>, IEquatable<UIDataValueListInt>
{
public override string ToString()
{
return GetValue().ToString();
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.List_Int;
public UIDataValueListInt()
{
if (GetValue() == null)
{
SetValue(new List<int>());
}
}
public override Type UIDataValueType => typeof(List<int>);
protected override void SetValueFrom(List<int> value)
{
//因为List是引用类型所以这里要做一下特殊处理如果要设置的值为0元素的List
//否则就拷贝全部元素
if (GetValue() == null)
{
base.SetValueFrom(value);
return;
}
GetValue().Clear();
GetValue().AddRange(value);
}
#region
private bool EqualsList(List<int> value)
{
if (GetValue()?.Count != value.Count)
{
return false;
}
return !GetValue().Where((t, i) => t != value[i]).Any();
}
public bool Equals(UIDataValueListInt other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return EqualsList(other.GetValue());
}
protected override bool EqualsValue(List<int> value)
{
return EqualsList(value);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
var value = (List<int>)obj;
return EqualsList(value);
}
public override int GetHashCode()
{
return GetValue()?.GetHashCode() ?? 0;
}
public static bool operator ==(UIDataValueListInt lhs, UIDataValueListInt rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueListInt lhs, UIDataValueListInt rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueListInt lhs, UIDataValueListInt rhs)
{
return lhs.GetValue().Count > rhs.GetValue().Count;
}
public static bool operator <(UIDataValueListInt lhs, UIDataValueListInt rhs)
{
return lhs.GetValue().Count < rhs.GetValue().Count;
}
public static bool operator >=(UIDataValueListInt lhs, UIDataValueListInt rhs)
{
return lhs.GetValue().Count >= rhs.GetValue().Count;
}
public static bool operator <=(UIDataValueListInt lhs, UIDataValueListInt rhs)
{
return lhs.GetValue().Count <= rhs.GetValue().Count;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9004234c76fd4196bad80be78a97b82a
timeCreated: 1679583315

View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueListLong : UIDataValueBase<List<long>>, IEquatable<UIDataValueListLong>
{
public override string ToString()
{
return GetValue().ToString();
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.List_Long;
public UIDataValueListLong()
{
if (GetValue() == null)
{
SetValue(new List<long>());
}
}
public override Type UIDataValueType => typeof(List<long>);
protected override void SetValueFrom(List<long> value)
{
if (GetValue() == null)
{
base.SetValueFrom(value);
return;
}
GetValue().Clear();
GetValue().AddRange(value);
}
#region
private bool EqualsList(List<long> value)
{
if (GetValue()?.Count != value.Count)
{
return false;
}
return !GetValue().Where((t, i) => t != value[i]).Any();
}
public bool Equals(UIDataValueListLong other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return EqualsList(other.GetValue());
}
protected override bool EqualsValue(List<long> value)
{
return EqualsList(value);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
var value = (List<long>)obj;
return EqualsList(value);
}
public override int GetHashCode()
{
return GetValue()?.GetHashCode() ?? 0;
}
public static bool operator ==(UIDataValueListLong lhs, UIDataValueListLong rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueListLong lhs, UIDataValueListLong rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueListLong lhs, UIDataValueListLong rhs)
{
return lhs.GetValue().Count > rhs.GetValue().Count;
}
public static bool operator <(UIDataValueListLong lhs, UIDataValueListLong rhs)
{
return lhs.GetValue().Count < rhs.GetValue().Count;
}
public static bool operator >=(UIDataValueListLong lhs, UIDataValueListLong rhs)
{
return lhs.GetValue().Count >= rhs.GetValue().Count;
}
public static bool operator <=(UIDataValueListLong lhs, UIDataValueListLong rhs)
{
return lhs.GetValue().Count <= rhs.GetValue().Count;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 41fd1a4baf474c7bb90adc87eeb79450
timeCreated: 1679583315

View File

@@ -0,0 +1,114 @@
using System;
using Sirenix.OdinInspector;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueLong : UIDataValueBase<long>, IEquatable<UIDataValueLong>
{
public override string ToString()
{
return GetValue().ToString();
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.Long;
public override Type UIDataValueType => typeof(long);
#region
public bool Equals(UIDataValueLong other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
protected override bool EqualsValue(long value)
{
return GetValue() == value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (long)obj;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueLong lhs, UIDataValueLong rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueLong lhs, UIDataValueLong rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueLong lhs, UIDataValueLong rhs)
{
return lhs.GetValue() > rhs.GetValue();
}
public static bool operator <(UIDataValueLong lhs, UIDataValueLong rhs)
{
return lhs.GetValue() < rhs.GetValue();
}
public static bool operator >=(UIDataValueLong lhs, UIDataValueLong rhs)
{
return lhs.GetValue() >= rhs.GetValue();
}
public static bool operator <=(UIDataValueLong lhs, UIDataValueLong rhs)
{
return lhs.GetValue() <= rhs.GetValue();
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a5bde4d61acc4bcd8955d30712faa70d
timeCreated: 1679583315

View File

@@ -0,0 +1,114 @@
using System;
using Sirenix.OdinInspector;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueString : UIDataValueBase<string>, IEquatable<UIDataValueString>
{
public override string ToString()
{
return GetValue() ?? "";
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.String;
public override Type UIDataValueType => typeof(string);
#region
public bool Equals(UIDataValueString other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
protected override bool EqualsValue(string value)
{
return GetValue() == value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (string)obj;
}
public override int GetHashCode()
{
return GetValue()?.GetHashCode() ?? 0;
}
public static bool operator ==(UIDataValueString lhs, UIDataValueString rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueString lhs, UIDataValueString rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueString lhs, UIDataValueString rhs)
{
return false;
}
public static bool operator <(UIDataValueString lhs, UIDataValueString rhs)
{
return false;
}
public static bool operator >=(UIDataValueString lhs, UIDataValueString rhs)
{
return false;
}
public static bool operator <=(UIDataValueString lhs, UIDataValueString rhs)
{
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bc9f07aba4c941f8b06777f5d5f79d18
timeCreated: 1679583315

View File

@@ -0,0 +1,114 @@
using System;
using Sirenix.OdinInspector;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueUInt : UIDataValueBase<uint>, IEquatable<UIDataValueUInt>
{
public override string ToString()
{
return GetValue().ToString();
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.Uint;
public override Type UIDataValueType => typeof(uint);
#region
public bool Equals(UIDataValueUInt other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
protected override bool EqualsValue(uint value)
{
return GetValue() == value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (uint)obj;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueUInt lhs, UIDataValueUInt rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueUInt lhs, UIDataValueUInt rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueUInt lhs, UIDataValueUInt rhs)
{
return lhs.GetValue() > rhs.GetValue();
}
public static bool operator <(UIDataValueUInt lhs, UIDataValueUInt rhs)
{
return lhs.GetValue() < rhs.GetValue();
}
public static bool operator >=(UIDataValueUInt lhs, UIDataValueUInt rhs)
{
return lhs.GetValue() >= rhs.GetValue();
}
public static bool operator <=(UIDataValueUInt lhs, UIDataValueUInt rhs)
{
return lhs.GetValue() <= rhs.GetValue();
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a103c87bd9584f2d8ca12020827c6563
timeCreated: 1679583315

View File

@@ -0,0 +1,116 @@
using System;
using Sirenix.OdinInspector;
using UnityEngine;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueVector2 : UIDataValueBase<Vector2>, IEquatable<UIDataValueVector2>
{
public override string ToString()
{
var value = GetValue();
return $"X:{value.x} Y:{value.y}";
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.Vector2;
public override Type UIDataValueType => typeof(Vector2);
#region
public bool Equals(UIDataValueVector2 other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
protected override bool EqualsValue(Vector2 value)
{
return GetValue() == value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (Vector2)obj;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueVector2 lhs, UIDataValueVector2 rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueVector2 lhs, UIDataValueVector2 rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueVector2 lhs, UIDataValueVector2 rhs)
{
return false;
}
public static bool operator <(UIDataValueVector2 lhs, UIDataValueVector2 rhs)
{
return false;
}
public static bool operator >=(UIDataValueVector2 lhs, UIDataValueVector2 rhs)
{
return false;
}
public static bool operator <=(UIDataValueVector2 lhs, UIDataValueVector2 rhs)
{
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a812200c3fb54a1f907e85cd68898b09
timeCreated: 1681455154

View File

@@ -0,0 +1,116 @@
using System;
using Sirenix.OdinInspector;
using UnityEngine;
namespace YIUIBind
{
[HideLabel]
[HideReferenceObjectPicker]
[Serializable]
public class UIDataValueVector3 : UIDataValueBase<Vector3>, IEquatable<UIDataValueVector3>
{
public override string ToString()
{
var value = GetValue();
return $"X:{value.x} Y:{value.y} Z:{value.z}";
}
public override EUIBindDataType UIBindDataType => EUIBindDataType.Vector3;
public override Type UIDataValueType => typeof(Vector3);
#region
public bool Equals(UIDataValueVector3 other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return GetValue() == other.GetValue();
}
protected override bool EqualsValue(Vector3 value)
{
return GetValue() == value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != UIDataValueType)
{
return false;
}
return GetValue() == (Vector3)obj;
}
public override int GetHashCode()
{
return GetValue().GetHashCode();
}
public static bool operator ==(UIDataValueVector3 lhs, UIDataValueVector3 rhs)
{
if (ReferenceEquals(lhs, null))
{
if (ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(UIDataValueVector3 lhs, UIDataValueVector3 rhs)
{
return !(lhs == rhs);
}
public static bool operator >(UIDataValueVector3 lhs, UIDataValueVector3 rhs)
{
return false;
}
public static bool operator <(UIDataValueVector3 lhs, UIDataValueVector3 rhs)
{
return false;
}
public static bool operator >=(UIDataValueVector3 lhs, UIDataValueVector3 rhs)
{
return false;
}
public static bool operator <=(UIDataValueVector3 lhs, UIDataValueVector3 rhs)
{
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9a8fb99560ac4c53826f4db26c68eee8
timeCreated: 1679583315

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5d8ae2bcdfa64f4cacd201fb9f56622f
timeCreated: 1679126162

View File

@@ -0,0 +1,19 @@
using Sirenix.OdinInspector;
namespace YIUIBind
{
/// <summary>
/// 布尔 逻辑 或 与 非s
/// </summary>
[LabelText("布尔逻辑")]
public enum UIBooleanLogic
{
[LabelText("And 与")]
And,
[LabelText("Or 或")]
Or,
//没有非 变量中有非的选择
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a62d23487d144d678877a1e3ef6354f1
timeCreated: 1679149550

View File

@@ -0,0 +1,26 @@
using Sirenix.OdinInspector;
namespace YIUIBind
{
/// <summary>
/// 比较运算枚举y
/// </summary>
[LabelText("比较运算")]
public enum UICompareModeEnum
{
[LabelText("< 小于")]
Less,
[LabelText("≤ 小于等于")]
LessEqual,
[LabelText("= 等于")]
Equal, //取反就是不等于
[LabelText("> 大于")]
Great,
[LabelText("≥ 大于等于")]
GreatEqual,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8d00431ebace461387dd884fa1972a83
timeCreated: 1679149686

View File

@@ -0,0 +1,20 @@
using Sirenix.OdinInspector;
namespace YIUIBind
{
[LabelText("过度")]
public enum UITransitionModeEnum
{
[LabelText("立即")]
Instant,
[LabelText("淡入淡出")]
Fade,
[LabelText("淡入")]
FadeIn,
[LabelText("淡出")]
FadeOut,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1971c6ae7adb4c068a8668c4eddbed8a
timeCreated: 1679150922

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
namespace YIUIBind
{
/// <summary>
/// 添加UIData前的准备数据
/// 过度用@lsy
/// </summary>
public sealed class UINewData
{
[LabelText("名称")]
[Delayed]
public string Name;
[HideLabel]
public UIDataValue Data;
}
[Serializable]
[HideLabel]
[HideReferenceObjectPicker]
public sealed partial class UIData
{
[LabelText("名称")]
[SerializeField]
[ReadOnly]
#if UNITY_EDITOR
[InfoBox("此数据没有任何关联", InfoMessageType.Error, "ShowIfBindsTips")]
#endif
private string m_Name;
/// <summary>
/// 当前变量名称
/// </summary>
public string Name => m_Name;
[SerializeField]
[ReadOnly]
[LabelText("唯一ID")]
[HideInInspector]
private int m_DataGuid;
public int DataGuid => m_DataGuid;
[OdinSerialize]
private UIDataValue m_DataValue;
public UIDataValue DataValue => m_DataValue;
private UIData()
{
}
public UIData(string name, UIDataValue dataValue)
{
m_Name = name;
m_DataValue = dataValue;
m_DataGuid = Guid.NewGuid().GetHashCode();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 80a8346a0f0f49e29cbfe1e193bbc084
timeCreated: 1679587043

View File

@@ -0,0 +1,281 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public static class UIDataHelper
{
#region New
/// <summary>
/// 根据类型获取一个新的数据
/// </summary>
public static UIDataValue GetNewDataValue(EUIBindDataType dataType)
{
//这个类型不会无限扩展所以暂时用这个方法
//如果有更好的方法可以修改
switch (dataType)
{
case EUIBindDataType.Bool:
return new UIDataValueBool();
case EUIBindDataType.String:
return new UIDataValueString();
case EUIBindDataType.Int:
return new UIDataValueInt();
case EUIBindDataType.Float:
return new UIDataValueFloat();
case EUIBindDataType.Vector3:
return new UIDataValueVector3();
case EUIBindDataType.List_Int:
return new UIDataValueListInt();
case EUIBindDataType.List_Long:
return new UIDataValueListLong();
case EUIBindDataType.Long:
return new UIDataValueLong();
case EUIBindDataType.Uint:
return new UIDataValueUInt();
case EUIBindDataType.Vector2:
return new UIDataValueVector2();
case EUIBindDataType.Color:
return new UIDataValueColor();
case EUIBindDataType.Double:
//其他类型还没需求就没写@L李
case EUIBindDataType.List_String:
case EUIBindDataType.Ulong:
default:
Logger.LogError($"没有实现这个类型 {dataType}");
return new UIDataValueInt();
}
}
public static UIDataValue GetNewDataValue(UIDataValue dataValue)
{
return GetNewDataValue(dataValue.UIBindDataType);
}
#endregion
#region Get/Set Value
private static UIDataValueBase<T> GetDataValueBase<T>(this UIDataValue self)
{
if (self is UIDataValueBase<T> finalResult) return finalResult;
Logger.LogError($"获取值转型失败,当前类型是: {self.UIDataValueType} 不是:{typeof(T)}");
return null;
}
public static T GetValue<T>(this UIData self)
{
return self.DataValue.GetValue<T>();
}
public static T GetValue<T>(this UIDataValue self)
{
var finalResult = GetDataValueBase<T>(self);
return finalResult != null ? finalResult.GetValue() : default;
}
public static T GetValue<T>(this UIData self, T defaultValue)
{
return self.DataValue.GetValue<T>(defaultValue);
}
public static T GetValue<T>(this UIDataValue self, T defaultValue)
{
var finalResult = GetDataValueBase<T>(self);
return finalResult != null ? finalResult.GetValue() : defaultValue;
}
public static string GetValueToString(this UIData self)
{
return GetValueToString(self.DataValue);
}
public static string GetValueToString(this UIDataValue self)
{
//由每个泛型子类实现ToString方法;
return self.ToString();
//以下为老的值tosytring 可能会存在某些引用类型无效的情况
//保留不删除
/*
switch (self.UIBindDataType)
{
case EUIBindDataType.Bool:
return self.GetValue<bool>().ToString();
case EUIBindDataType.String:
return self.GetValue<string>().ToString();
case EUIBindDataType.Int:
return self.GetValue<int>().ToString();
case EUIBindDataType.Float:
return self.GetValue<float>().ToString();
case EUIBindDataType.Vector3:
return self.GetValue<Vector3>().ToString();
case EUIBindDataType.List_Int:
return self.GetValue<List<int>>().ToString();
case EUIBindDataType.List_Long:
return self.GetValue<List<long>>().ToString();
case EUIBindDataType.List_String:
return self.GetValue<List<string>>().ToString();
case EUIBindDataType.Long:
return self.GetValue<long>().ToString();
case EUIBindDataType.Uint:
return self.GetValue<uint>().ToString();
case EUIBindDataType.Ulong:
return self.GetValue<ulong>().ToString();
case EUIBindDataType.Double:
return self.GetValue<double>().ToString();
case EUIBindDataType.Vector2:
return self.GetValue<Vector2>().ToString();
case EUIBindDataType.Color:
return self.GetValue<Color>().ToString();
default:
Logger.LogError($"此类型未实现 {self.UIBindDataType}");
return "null";
}
*/
}
public static object GetValueObject(this UIData self)
{
return GetValueObject(self.DataValue);
}
public static object GetValueObject(this UIDataValue self)
{
switch (self.UIBindDataType)
{
case EUIBindDataType.Bool:
return self.GetValue<bool>();
case EUIBindDataType.String:
return self.GetValue<string>();
case EUIBindDataType.Int:
return self.GetValue<int>();
case EUIBindDataType.Float:
return self.GetValue<float>();
case EUIBindDataType.Vector3:
return self.GetValue<Vector3>();
case EUIBindDataType.List_Int:
return self.GetValue<List<int>>();
case EUIBindDataType.List_Long:
return self.GetValue<List<long>>();
case EUIBindDataType.List_String:
return self.GetValue<List<string>>();
case EUIBindDataType.Long:
return self.GetValue<long>();
case EUIBindDataType.Uint:
return self.GetValue<uint>();
case EUIBindDataType.Ulong:
return self.GetValue<ulong>();
case EUIBindDataType.Double:
return self.GetValue<double>();
case EUIBindDataType.Vector2:
return self.GetValue<Vector2>();
case EUIBindDataType.Color:
return self.GetValue<Color>();
default:
Logger.LogError($"此类型未实现 {self.UIBindDataType}");
return "null";
}
}
public static bool Set<T>(this UIData self, T value, bool force = false)
{
return self.DataValue.Set(value, force);
}
public static bool Set<T>(this UIDataValue self, T value, bool force = false)
{
var finalResult = GetDataValueBase<T>(self);
if (finalResult == null) return false;
finalResult.SetValue(value, force);
return true;
}
public static bool SetValueFrom(this UIData self, UIDataValue dataValue)
{
return self.DataValue.SetValueFrom(dataValue);
}
public static bool SetValueFrom<T>(this UIData self, UIDataValue dataValue, bool force = false)
{
return self.DataValue.SetValueFrom<T>(dataValue, force);
}
public static bool SetValueFrom<T>(this UIDataValue self, UIDataValue dataValue, bool force = false)
{
var finalResult = GetDataValueBase<T>(self);
if (finalResult == null) return false;
finalResult.SetValueFrom(dataValue, force);
return true;
}
#endregion
#region ChangeAction
public static void AddValueChangeAction(this UIData self, Action action)
{
if (self.DataValue == null)
{
Logger.LogError($"{self.Name} 这个数据没有值");
return;
}
self.DataValue.AddValueChangeAction(action);
}
public static void RemoveValueChangeAction(this UIData self, Action action)
{
if (self.DataValue == null)
{
Logger.LogError($"{self.Name} 这个数据没有值");
return;
}
self.DataValue.RemoveValueChangeAction(action);
}
public static void AddValueChangeAction<T>(this UIData self, Action<T, T> action) where T : struct
{
if (self.DataValue == null)
{
Logger.LogError($"{self.Name} 这个数据没有值");
return;
}
if (self.DataValue is UIDataValueBase<T> dataBase)
{
dataBase.AddValueChangeAction(action);
}
else
{
Logger.LogError($"{self.Name} 这个数据值类型不是 {typeof(T).Name}");
}
}
public static void RemoveValueChangeAction<T>(this UIData self, Action<T, T> action) where T : struct
{
if (self.DataValue == null)
{
Logger.LogError($"{self.Name} 这个数据没有值");
return;
}
if (self.DataValue is UIDataValueBase<T> dataBase)
{
dataBase.RemoveValueChangeAction(action);
}
else
{
Logger.LogError($"{self.Name} 这个数据值类型不是 {typeof(T).Name}");
}
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 162d2a19977c4b3090160c49dd4f7f85
timeCreated: 1679641550

View File

@@ -0,0 +1,99 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public sealed partial class UIData
{
public event Action<UIData> OnDataChangAction;
public void OnDataChange(string name)
{
m_Name = name;
try
{
OnDataChangAction?.Invoke(this);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
//移除注册
[HideInInspector]
public Action<UIData> OnDataRemoveAction;
[GUIColor(0, 1, 1)]
[Button("移除")]
[PropertyOrder(100)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private void OnRemoveDataClick()
{
try
{
OnDataRemoveAction?.Invoke(this);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
//确定移除
public void OnDataRemoveCallBack()
{
if (m_Binds == null || m_Binds.Count <= 0)
{
return;
}
for (var i = m_Binds.Count - 1; i >= 0; i--)
{
m_Binds[i].RemoveBindData(this);
}
}
private bool ShowIfBindsTips => m_Binds.Count <= 0;
private bool ShowIfBinds => m_Binds.Count >= 1;
[SerializeField]
[HideReferenceObjectPicker]
[LabelText("所有绑定关联")]
[ReadOnly]
[PropertyOrder(101)]
[ShowIf("ShowIfBinds")]
private List<UIDataBind> m_Binds = new List<UIDataBind>();
public int GetBindCount()
{
return m_Binds?.Count ?? 0;
}
internal void AddBind(UIDataBind bind)
{
if (m_Binds?.IndexOf(bind) == -1)
{
m_Binds?.Add(bind);
}
}
internal void RemoveBind(UIDataBind bind)
{
m_Binds?.Remove(bind);
}
internal void ClearBinds()
{
m_Binds?.Clear();
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f243a017586246a1828ba9b82b0f984b
timeCreated: 1685517794

View File

@@ -0,0 +1,114 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
//[DetailedInfoBox("UI 数据表 点击展开详细介绍", @"李胜扬")]
[LabelText("UI 数据表")]
[Serializable]
[AddComponentMenu("YIUIBind/★★★UI Data Table 数据表★★★")]
public sealed partial class UIBindDataTable : SerializedMonoBehaviour
{
[OdinSerialize]
[HideLabel]
[ShowInInspector]
[Title("所有数据", TitleAlignment = TitleAlignments.Centered)]
[DictionaryDrawerSettings(KeyLabel = "数据名称", ValueLabel = "数据内容", IsReadOnly = true,
DisplayMode = DictionaryDisplayOptions.ExpandedFoldout)]
private Dictionary<string, UIData> m_DataDic = new Dictionary<string, UIData>();
public IReadOnlyDictionary<string, UIData> DataDic => m_DataDic;
private void Awake()
{
InitDataTable();
}
public UIData FindData(string dataName)
{
if (string.IsNullOrEmpty(dataName)) return null;
return m_DataDic.TryGetValue(dataName, out var data) ? data : null;
}
public T FindDataValue<T>(string dataName) where T : UIDataValue
{
var uiData = FindData(dataName);
if (uiData == null)
{
Logger.LogErrorContext(this, $"{name} 未找到这个数据请检查 {dataName}");
return default;
}
if (uiData.DataValue == null)
{
Logger.LogErrorContext(this, $"{name} 数据没有初始化没有值 {dataName}");
return default;
}
return (T)uiData.DataValue;
}
#region
private void InitDataTable()
{
InitializeBinds(transform);
}
private static void InitializeBinds(Transform transform)
{
#if YIUIMACRO_BIND_INITIALIZE
Logger.LogErrorContext(transform,$"{transform.name} 初始化调用所有子类 UIDataBind 绑定");
#endif
var binds = ListPool<UIDataBind>.Get();
transform.GetComponents(binds);
foreach (var bind in binds)
{
bind.Initialize(true);
}
ListPool<UIDataBind>.Put(binds);
foreach (Transform child in transform)
{
InitializeBindsDeep(child);
}
}
private static void InitializeBindsDeep(Transform transform)
{
if (transform.HasComponent<UIBindDataTable>())
{
return;
}
var binds = ListPool<UIDataBind>.Get();
transform.GetComponents(binds);
foreach (var bind in binds)
{
bind.Initialize(true);
}
ListPool<UIDataBind>.Put(binds);
foreach (Transform child in transform)
{
InitializeBindsDeep(child);
}
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e653f1c5ec04766b7a16c1a9b9ff51e
timeCreated: 1679040675

View File

@@ -0,0 +1,201 @@
#if UNITY_EDITOR
using System;
using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
//Editor
public sealed partial class UIBindDataTable
{
[GUIColor(1, 1, 0)]
[Button("自动检查", 30)]
[PropertyOrder(-100)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
public void AutoCheck()
{
if (!UIOperationHelper.CheckUIOperation(this)) return;
var dicKey = m_DataDic.Keys.ToList();
foreach (var oldName in dicKey)
{
if (string.IsNullOrEmpty(oldName))
{
continue;
}
var uiData = m_DataDic[oldName];
if (uiData?.DataValue == null)
{
Debug.LogError($"数据 {oldName} 为空 已移除请重新添加");
m_DataDic.Remove(oldName);
continue;
}
var newName = oldName;
if (!oldName.CheckFirstName(NameUtility.DataName))
{
newName = $"{NameUtility.FirstName}{NameUtility.DataName}{oldName}";
}
newName = newName.ChangeToBigName(NameUtility.DataName);
if (oldName != newName)
{
m_DataDic.Remove(oldName);
m_DataDic.Add(newName, uiData);
}
}
OnValidate();
}
[DetailedInfoBox("添加新数据 说明",
@"如果出现点击添加一个新的数据界面闪一下
然后什么都没加上的情况
这是由于预制件嵌套刷新问题
需要进入到预制件内部进行添加 外部无法操作
为了防止你莫名其妙的吧一个预制件之外的东西拖进来")]
[ShowInInspector]
[BoxGroup("添加新数据")]
[HideReferenceObjectPicker]
[HideLabel]
[PropertyOrder(-99)]
[Delayed]
[NonSerialized]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private UINewData m_AddUINewData = new UINewData();
[GUIColor(0, 1, 0)]
[BoxGroup("添加新数据")]
[Button("添加",40)]
[PropertyOrder(-98)]
[ShowIf("@UIOperationHelper.CommonShowIf()")]
private void AddNewData()
{
if (string.IsNullOrEmpty(m_AddUINewData.Name))
{
UnityTipsHelper.ShowError($"必须填写名称才可以添加");
return;
}
if (m_DataDic.ContainsKey(m_AddUINewData.Name))
{
UnityTipsHelper.ShowError($"已存在同名数据 请修改 {m_AddUINewData.Name}");
return;
}
if (m_AddUINewData.Data == null)
{
UnityTipsHelper.ShowError($"必须选择数据类型才可以添加 请修改 {m_AddUINewData.Name}");
return;
}
var data = new UIData(m_AddUINewData.Name, m_AddUINewData.Data);
m_DataDic.Add(data.Name, data);
m_AddUINewData = new UINewData();
AutoCheck();
}
[BoxGroup("添加新数据")]
[Button("重置",20)]
[PropertyOrder(-97)]
[ShowIf("ShowIfResetNewData")]
private void ResetNewData()
{
var lastName = m_AddUINewData.Name;
m_AddUINewData = new UINewData();
m_AddUINewData.Name = lastName;
}
private bool ShowIfResetNewData()
{
return UIOperationHelper.CommonShowIf() && m_AddUINewData?.Data != null;
}
private void RemoveCallBack(UIData data)
{
data.OnDataRemoveCallBack();
if (m_DataDic.ContainsKey(data.Name))
{
m_DataDic.Remove(data.Name);
}
else
{
OnRemoveDataByGuid(data);
}
}
private bool OnRemoveDataByGuid(UIData uiData)
{
foreach (var cData in m_DataDic)
{
if (cData.Value.DataGuid == uiData.DataGuid)
{
m_DataDic.Remove(cData.Key);
Logger.LogError($"移除了一个不符合规范的数据 {cData.Key}");
return true;
}
}
return false;
}
private void OnRemoveData(UIData uiData)
{
if (string.IsNullOrEmpty(uiData.Name))
{
OnRemoveDataByGuid(uiData);
return;
}
if (!m_DataDic.ContainsKey(uiData.Name))
{
OnRemoveDataByGuid(uiData);
return;
}
var data = m_DataDic[uiData.Name];
//如果已经有绑定了 需要提醒是否移除
if (data.GetBindCount() >= 1)
{
var callBackTips = $"{data.Name} 已绑定 {data.GetBindCount()}个目标\n移除会强制清楚所有绑定 请确认是否需要移除!!!";
UnityTipsHelper.CallBack(callBackTips, () => { RemoveCallBack(data); });
return;
}
RemoveCallBack(data);
}
private void OnValidate()
{
if (UIOperationHelper.IsPlaying())
{
return;
}
foreach (var data in m_DataDic)
{
if (data.Value == null)
{
continue;
}
data.Value.ClearBinds();
data.Value.OnDataChange(data.Key);
data.Value.OnDataRemoveAction = OnRemoveData;
}
InitDataTable();
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3eef3a529f7a4b1e92e420bee7df872e
timeCreated: 1685501030

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 17e0e8b6ff3c401ebf7fe1194d0ecc95
timeCreated: 1681134271

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e36eb4db1f7c466f916dabfd76d7658e
timeCreated: 1681186230

View File

@@ -0,0 +1,112 @@
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
[ExecuteInEditMode]
public abstract partial class UIEventBind : SerializedMonoBehaviour
{
[OdinSerialize]
[ReadOnly]
[HideReferenceObjectPicker]
[Required("必须选择")]
[HideLabel]
[PropertyOrder(-999)]
private UIBindEventTable m_EventTable;
public UIBindEventTable EventTable => m_EventTable;
[OdinSerialize]
[LabelText("事件名称")]
#if UNITY_EDITOR
[ValueDropdown("GetEventNameKeys")]
[OnValueChanged("OnEventNameSelected")]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
#endif
[PropertyOrder(-99)]
protected string m_EventName = null;
/// <summary>
/// 当前的UI事件
/// </summary>
[OdinSerialize]
[HideInInspector]
protected UIEventBase m_UIEvent;
private UIEventBase GetEvent(string eventName)
{
if (string.IsNullOrEmpty(eventName))
{
//Logger.LogErrorContext(this,$"{name} 尝试获取一个空名称的事件 请检查");
return null;
}
if (m_EventTable == null)
{
Logger.LogErrorContext(this, $"{name} 事件表==ull 请检查");
return null;
}
var uiEvent = m_EventTable.FindEvent(eventName);
if (uiEvent == null)
{
Logger.LogErrorContext(this, $"{name}没找到这个事件 {eventName} 请检查配置");
}
return uiEvent;
}
protected abstract bool IsTaskEvent { get; }
protected abstract List<EUIEventParamType> GetFilterParamType();
private bool m_Binded;
internal void Initialize(bool refresh = false)
{
if (!refresh && m_Binded) return;
m_Binded = true;
OnRefreshEvent();
}
private void RefreshEventName()
{
if (m_UIEvent != null)
{
m_EventName = m_UIEvent.EventName;
}
}
protected virtual void RefreshBind()
{
}
private void OnRefreshEvent()
{
RefreshEventTable();
#if UNITY_EDITOR
UnbindEvent();
#endif
RefreshEventName();
m_UIEvent = GetEvent(m_EventName);
RefreshEventName();
#if UNITY_EDITOR
BindEvent();
#endif
RefreshBind();
}
private void RefreshEventTable()
{
if (m_EventTable == null)
{
m_EventTable = this.GetComponentInParentHard<UIBindEventTable>();
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bce0f8affbf546f190239bca8a759b32
timeCreated: 1681141568

View File

@@ -0,0 +1,130 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Sirenix.OdinInspector;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public abstract partial class UIEventBind
{
[GUIColor(0, 1, 1)]
[Button("响应点击 只能响应无参方法", 20)]
[PropertyOrder(-100)]
private void TestOnClick()
{
if (m_UIEvent == null)
{
Logger.LogError($"未选择事件");
return;
}
try
{
if (m_UIEvent.IsTaskEvent)
{
m_UIEvent.InvokeAsync().Forget();
}
else
{
m_UIEvent.Invoke();
}
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
private const string c_ErrorTips = "当前事件表中无符合参数条件的事件";
private IEnumerable<string> GetEventNameKeys()
{
if (m_EventTable == null)
{
Logger.LogErrorContext(this, $"{name} 请检查未设置 事件表");
return null;
}
var list = m_EventTable.GetFilterParamTypeEventName(GetFilterParamType(), IsTaskEvent);
for (var i = list.Count - 1; i >= 0; i--)
{
var eventName = list[i];
if (string.IsNullOrEmpty(eventName))
{
list.RemoveAt(i);
}
}
if (list.Count <= 0)
{
list.Add(c_ErrorTips);
}
else
{
list.Add(""); //为了清空当前选择的事件用的 否则无法取消当前绑定的事件
}
return list;
}
private void OnEventNameSelected()
{
if (m_EventName == c_ErrorTips)
{
m_EventName = "";
Logger.LogError($"{c_ErrorTips} 请创建 提示: {GetFilterParamType().GetAllParamTypeTips()}");
}
UnbindEvent();
m_UIEvent = null;
}
/// <summary>
/// 绑定
/// </summary>
private void BindEvent()
{
m_UIEvent?.AddBind(this);
}
/// <summary>
/// 解绑
/// </summary>
private void UnbindEvent()
{
m_UIEvent?.RemoveBind(this);
}
/// <summary>
/// 对应的需要处理相关关联绑定
/// </summary>
public virtual void RemoveBind(UIEventBase uiEvent)
{
if (uiEvent == m_UIEvent)
{
m_EventName = null;
m_UIEvent = null;
}
else
{
Logger.LogError($"移除与当前不一致 请检查 当前{m_UIEvent.EventName} 移除{uiEvent.EventName}");
}
}
protected void OnDestroy()
{
UnbindEvent();
}
protected void OnValidate()
{
OnRefreshEvent();
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2d4f6c3c5ecf4a9fb2b091f82592e397
timeCreated: 1685515617

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e3f1d543656f461893897f6fc0b05646
timeCreated: 1681180107

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d566d5886afb40eeae69042689185196
timeCreated: 1681181247

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5262e65e850a47d08640df6a6e910391
timeCreated: 1682393343

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public class UIEventP0 : UIEventBase, IUIEventInvoke
{
public override bool IsTaskEvent => false;
private LinkedList<UIEventHandleP0> m_UIEventDelegates;
public LinkedList<UIEventHandleP0> UIEventDelegates => m_UIEventDelegates;
public UIEventP0()
{
}
public UIEventP0(string name) : base(name)
{
}
public void Invoke()
{
if (m_UIEventDelegates == null)
{
Logger.LogWarning($"{EventName} 未绑定任何事件");
return;
}
var itr = m_UIEventDelegates.First;
while (itr != null)
{
var next = itr.Next;
var value = itr.Value;
try
{
value.UIEventParamDelegate?.Invoke();
}
catch (Exception e)
{
Logger.LogError(e);
}
itr = next;
}
}
public override bool Clear()
{
if (m_UIEventDelegates == null) return false;
var first = m_UIEventDelegates.First;
while (first != null)
{
PublicUIEventP0.HandlerPool.Release(first.Value);
first = m_UIEventDelegates.First;
}
LinkedListPool<UIEventHandleP0>.Release(m_UIEventDelegates);
m_UIEventDelegates = null;
return true;
}
public UIEventHandleP0 Add(UIEventDelegate callback)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP0>.Get();
if (callback == null)
{
Logger.LogError($"{EventName} 添加了一个空回调");
}
var handler = PublicUIEventP0.HandlerPool.Get();
var node = m_UIEventDelegates.AddLast(handler);
return handler.Init(m_UIEventDelegates, node, callback);
}
public bool Remove(UIEventHandleP0 handle)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP0>.Get();
if (handle == null)
{
Logger.LogError($"{EventName} UIEventParamHandle == null");
return false;
}
return m_UIEventDelegates.Remove(handle);
}
#if UNITY_EDITOR
public override string GetEventType()
{
return "UIEventP0";
}
public override string GetEventHandleType()
{
return "UIEventHandleP0";
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 98a8cb71dd534d2c98e5203ad33f2e16
timeCreated: 1681179383

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public class UIEventP1<P1> : UIEventBase, IUIEventInvoke<P1>
{
public override bool IsTaskEvent => false;
private LinkedList<UIEventHandleP1<P1>> m_UIEventDelegates;
public LinkedList<UIEventHandleP1<P1>> UIEventDelegates => m_UIEventDelegates;
public UIEventP1()
{
}
public UIEventP1(string name) : base(name)
{
}
public void Invoke(P1 p1)
{
if (m_UIEventDelegates == null)
{
Logger.LogWarning($"{EventName} 未绑定任何事件");
return;
}
var itr = m_UIEventDelegates.First;
while (itr != null)
{
var next = itr.Next;
var value = itr.Value;
try
{
value.UIEventParamDelegate?.Invoke(p1);
}
catch (Exception e)
{
Logger.LogError(e);
}
itr = next;
}
}
public override bool Clear()
{
if (m_UIEventDelegates == null) return false;
var first = m_UIEventDelegates.First;
while (first != null)
{
PublicUIEventP1<P1>.HandlerPool.Release(first.Value);
first = m_UIEventDelegates.First;
}
LinkedListPool<UIEventHandleP1<P1>>.Release(m_UIEventDelegates);
m_UIEventDelegates = null;
return true;
}
public UIEventHandleP1<P1> Add(UIEventDelegate<P1> callback)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP1<P1>>.Get();
if (callback == null)
{
Logger.LogError($"{EventName} 添加了一个空回调");
}
var handler = PublicUIEventP1<P1>.HandlerPool.Get();
var node = m_UIEventDelegates.AddLast(handler);
return handler.Init(m_UIEventDelegates, node, callback);
}
public bool Remove(UIEventHandleP1<P1> handle)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP1<P1>>.Get();
if (handle == null)
{
Logger.LogError($"{EventName} UIEventParamHandle == null");
return false;
}
return m_UIEventDelegates.Remove(handle);
}
#if UNITY_EDITOR
public override string GetEventType()
{
return $"UIEventP1<{GetParamTypeString(0)}>";
}
public override string GetEventHandleType()
{
return $"UIEventHandleP1<{GetParamTypeString(0)}>";
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d9a0d3d00a174dad920d251c6ba6d551
timeCreated: 1681135630

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public class UIEventP2<P1, P2> : UIEventBase, IUIEventInvoke<P1, P2>
{
public override bool IsTaskEvent => false;
private LinkedList<UIEventHandleP2<P1, P2>> m_UIEventDelegates;
public LinkedList<UIEventHandleP2<P1, P2>> UIEventDelegates => m_UIEventDelegates;
public UIEventP2()
{
}
public UIEventP2(string name) : base(name)
{
}
public void Invoke(P1 p1, P2 p2)
{
if (m_UIEventDelegates == null)
{
Logger.LogWarning($"{EventName} 未绑定任何事件");
return;
}
var itr = m_UIEventDelegates.First;
while (itr != null)
{
var next = itr.Next;
var value = itr.Value;
try
{
value.UIEventParamDelegate?.Invoke(p1, p2);
}
catch (Exception e)
{
Logger.LogError(e);
}
itr = next;
}
}
public override bool Clear()
{
if (m_UIEventDelegates == null) return false;
var first = m_UIEventDelegates.First;
while (first != null)
{
PublicUIEventP2<P1, P2>.HandlerPool.Release(first.Value);
first = m_UIEventDelegates.First;
}
LinkedListPool<UIEventHandleP2<P1, P2>>.Release(m_UIEventDelegates);
m_UIEventDelegates = null;
return true;
}
public UIEventHandleP2<P1, P2> Add(UIEventDelegate<P1, P2> callback)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP2<P1, P2>>.Get();
if (callback == null)
{
Logger.LogError($"{EventName} 添加了一个空回调");
}
var handler = PublicUIEventP2<P1, P2>.HandlerPool.Get();
var node = m_UIEventDelegates.AddLast(handler);
return handler.Init(m_UIEventDelegates, node, callback);
}
public bool Remove(UIEventHandleP2<P1, P2> handle)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP2<P1, P2>>.Get();
if (handle == null)
{
Logger.LogError($"{EventName} UIEventParamHandle == null");
return false;
}
return m_UIEventDelegates.Remove(handle);
}
#if UNITY_EDITOR
public override string GetEventType()
{
return $"UIEventP2<{GetParamTypeString(0)},{GetParamTypeString(1)}>";
}
public override string GetEventHandleType()
{
return $"UIEventHandleP2<{GetParamTypeString(0)},{GetParamTypeString(1)}>";
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 59823fd1af6f4f72b7b92de8aa961a93
timeCreated: 1681179577

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public class UIEventP3<P1, P2, P3> : UIEventBase, IUIEventInvoke<P1, P2, P3>
{
public override bool IsTaskEvent => false;
private LinkedList<UIEventHandleP3<P1, P2, P3>> m_UIEventDelegates;
public LinkedList<UIEventHandleP3<P1, P2, P3>> UIEventDelegates => m_UIEventDelegates;
public UIEventP3()
{
}
public UIEventP3(string name) : base(name)
{
}
public void Invoke(P1 p1, P2 p2, P3 p3)
{
if (m_UIEventDelegates == null)
{
Logger.LogWarning($"{EventName} 未绑定任何事件");
return;
}
var itr = m_UIEventDelegates.First;
while (itr != null)
{
var next = itr.Next;
var value = itr.Value;
try
{
value.UIEventParamDelegate?.Invoke(p1, p2, p3);
}
catch (Exception e)
{
Logger.LogError(e);
}
itr = next;
}
}
public override bool Clear()
{
if (m_UIEventDelegates == null) return false;
var first = m_UIEventDelegates.First;
while (first != null)
{
PublicUIEventP3<P1, P2, P3>.HandlerPool.Release(first.Value);
first = m_UIEventDelegates.First;
}
LinkedListPool<UIEventHandleP3<P1, P2, P3>>.Release(m_UIEventDelegates);
m_UIEventDelegates = null;
return true;
}
public UIEventHandleP3<P1, P2, P3> Add(UIEventDelegate<P1, P2, P3> callback)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP3<P1, P2, P3>>.Get();
if (callback == null)
{
Logger.LogError($"{EventName} 添加了一个空回调");
}
var handler = PublicUIEventP3<P1, P2, P3>.HandlerPool.Get();
var node = m_UIEventDelegates.AddLast(handler);
return handler.Init(m_UIEventDelegates, node, callback);
}
public bool Remove(UIEventHandleP3<P1, P2, P3> handle)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP3<P1, P2, P3>>.Get();
if (handle == null)
{
Logger.LogError($"{EventName} UIEventParamHandle == null");
return false;
}
return m_UIEventDelegates.Remove(handle);
}
#if UNITY_EDITOR
public override string GetEventType()
{
return $"UIEventP3<{GetParamTypeString(0)},{GetParamTypeString(1)},{GetParamTypeString(2)}>";
}
public override string GetEventHandleType()
{
return $"UIEventHandleP3<{GetParamTypeString(0)},{GetParamTypeString(1)},{GetParamTypeString(2)}>";
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: add790c22edb4f8fae88195f7ce99ffb
timeCreated: 1681179672

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public class UIEventP4<P1, P2, P3, P4> : UIEventBase, IUIEventInvoke<P1, P2, P3, P4>
{
public override bool IsTaskEvent => false;
private LinkedList<UIEventHandleP4<P1, P2, P3, P4>> m_UIEventDelegates;
public LinkedList<UIEventHandleP4<P1, P2, P3, P4>> UIEventDelegates => m_UIEventDelegates;
public UIEventP4()
{
}
public UIEventP4(string name) : base(name)
{
}
public void Invoke(P1 p1, P2 p2, P3 p3, P4 p4)
{
if (m_UIEventDelegates == null)
{
Logger.LogWarning($"{EventName} 未绑定任何事件");
return;
}
var itr = m_UIEventDelegates.First;
while (itr != null)
{
var next = itr.Next;
var value = itr.Value;
try
{
value.UIEventParamDelegate?.Invoke(p1, p2, p3, p4);
}
catch (Exception e)
{
Logger.LogError(e);
}
itr = next;
}
}
public override bool Clear()
{
if (m_UIEventDelegates == null) return false;
var first = m_UIEventDelegates.First;
while (first != null)
{
PublicUIEventP4<P1, P2, P3, P4>.HandlerPool.Release(first.Value);
first = m_UIEventDelegates.First;
}
LinkedListPool<UIEventHandleP4<P1, P2, P3, P4>>.Release(m_UIEventDelegates);
m_UIEventDelegates = null;
return true;
}
public UIEventHandleP4<P1, P2, P3, P4> Add(UIEventDelegate<P1, P2, P3, P4> callback)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP4<P1, P2, P3, P4>>.Get();
if (callback == null)
{
Logger.LogError($"{EventName} 添加了一个空回调");
}
var handler = PublicUIEventP4<P1, P2, P3, P4>.HandlerPool.Get();
var node = m_UIEventDelegates.AddLast(handler);
return handler.Init(m_UIEventDelegates, node, callback);
}
public bool Remove(UIEventHandleP4<P1, P2, P3, P4> handle)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP4<P1, P2, P3, P4>>.Get();
if (handle == null)
{
Logger.LogError($"{EventName} UIEventParamHandle == null");
return false;
}
return m_UIEventDelegates.Remove(handle);
}
#if UNITY_EDITOR
public override string GetEventType()
{
return $"UIEventP4<{GetParamTypeString(0)},{GetParamTypeString(1)},{GetParamTypeString(2)},{GetParamTypeString(3)}>";
}
public override string GetEventHandleType()
{
return $"UIEventHandleP4<{GetParamTypeString(0)},{GetParamTypeString(1)},{GetParamTypeString(2)},{GetParamTypeString(3)}>";
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 123ca6f84cc44b848b9522ea89408899
timeCreated: 1681179676

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using YIUIFramework;
using Logger = YIUIFramework.Logger;
namespace YIUIBind
{
public class UIEventP5<P1, P2, P3, P4, P5> : UIEventBase, IUIEventInvoke<P1, P2, P3, P4, P5>
{
public override bool IsTaskEvent => false;
private LinkedList<UIEventHandleP5<P1, P2, P3, P4, P5>> m_UIEventDelegates;
public LinkedList<UIEventHandleP5<P1, P2, P3, P4, P5>> UIEventDelegates => m_UIEventDelegates;
public UIEventP5()
{
}
public UIEventP5(string name) : base(name)
{
}
public void Invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
{
if (m_UIEventDelegates == null)
{
Logger.LogWarning($"{EventName} 未绑定任何事件");
return;
}
var itr = m_UIEventDelegates.First;
while (itr != null)
{
var next = itr.Next;
var value = itr.Value;
try
{
value.UIEventParamDelegate?.Invoke(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Logger.LogError(e);
}
itr = next;
}
}
public override bool Clear()
{
if (m_UIEventDelegates == null) return false;
var first = m_UIEventDelegates.First;
while (first != null)
{
PublicUIEventP5<P1, P2, P3, P4, P5>.HandlerPool.Release(first.Value);
first = m_UIEventDelegates.First;
}
LinkedListPool<UIEventHandleP5<P1, P2, P3, P4, P5>>.Release(m_UIEventDelegates);
m_UIEventDelegates = null;
return true;
}
public UIEventHandleP5<P1, P2, P3, P4, P5> Add(UIEventDelegate<P1, P2, P3, P4, P5> callback)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP5<P1, P2, P3, P4, P5>>.Get();
if (callback == null)
{
Logger.LogError($"{EventName} 添加了一个空回调");
}
var handler = PublicUIEventP5<P1, P2, P3, P4, P5>.HandlerPool.Get();
var node = m_UIEventDelegates.AddLast(handler);
return handler.Init(m_UIEventDelegates, node, callback);
}
public bool Remove(UIEventHandleP5<P1, P2, P3, P4, P5> handle)
{
m_UIEventDelegates ??= LinkedListPool<UIEventHandleP5<P1, P2, P3, P4, P5>>.Get();
if (handle == null)
{
Logger.LogError($"{EventName} UIEventParamHandle == null");
return false;
}
return m_UIEventDelegates.Remove(handle);
}
#if UNITY_EDITOR
public override string GetEventType()
{
return $"UIEventP5<{GetParamTypeString(0)},{GetParamTypeString(1)},{GetParamTypeString(2)},{GetParamTypeString(3)},{GetParamTypeString(4)}>";
}
public override string GetEventHandleType()
{
return $"UIEventHandleP5<{GetParamTypeString(0)},{GetParamTypeString(1)},{GetParamTypeString(2)},{GetParamTypeString(3)},{GetParamTypeString(4)}>";
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a261fc9fbaf74eb9b8bdd15a2f78d013
timeCreated: 1681179680

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e9adc5b2913b4ce68f997d91e8a2f453
timeCreated: 1682393357

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using YIUIFramework;
namespace YIUIBind
{
/// <summary>
/// UI事件全局对象池
/// </summary>
public static class PublicUIEventP0
{
public static readonly ObjectPool<UIEventHandleP0> HandlerPool = new ObjectPool<UIEventHandleP0>(
null, handler => handler.Dispose());
}
/// <summary>
/// UI事件 无参数
/// </summary>
public sealed class UIEventHandleP0
{
private LinkedList<UIEventHandleP0> m_UIEventList;
private LinkedListNode<UIEventHandleP0> m_UIEventNode;
private UIEventDelegate m_UIEventParamDelegate;
public UIEventDelegate UIEventParamDelegate => m_UIEventParamDelegate;
public UIEventHandleP0()
{
}
internal UIEventHandleP0 Init(
LinkedList<UIEventHandleP0> uiEventList,
LinkedListNode<UIEventHandleP0> uiEventNode,
UIEventDelegate uiEventDelegate)
{
m_UIEventList = uiEventList;
m_UIEventNode = uiEventNode;
m_UIEventParamDelegate = uiEventDelegate;
return this;
}
public void Dispose()
{
if (m_UIEventList == null || m_UIEventNode == null) return;
m_UIEventList.Remove(m_UIEventNode);
m_UIEventNode = null;
m_UIEventList = null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a0eb6037629f4fd7b675382402787fed
timeCreated: 1681179493

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using YIUIFramework;
namespace YIUIBind
{
/// <summary>
/// UI事件全局对象池
/// </summary>
public static class PublicUIEventP1<P1>
{
public static readonly ObjectPool<UIEventHandleP1<P1>> HandlerPool = new ObjectPool<UIEventHandleP1<P1>>(
null, handler => handler.Dispose());
}
/// <summary>
/// UI事件 1个泛型参数
/// </summary>
public sealed class UIEventHandleP1<P1>
{
private LinkedList<UIEventHandleP1<P1>> m_UIEventList;
private LinkedListNode<UIEventHandleP1<P1>> m_UIEventNode;
private UIEventDelegate<P1> m_UIEventParamDelegate;
public UIEventDelegate<P1> UIEventParamDelegate => m_UIEventParamDelegate;
public UIEventHandleP1()
{
}
internal UIEventHandleP1<P1> Init(
LinkedList<UIEventHandleP1<P1>> uiEventList,
LinkedListNode<UIEventHandleP1<P1>> uiEventNode,
UIEventDelegate<P1> uiEventDelegate)
{
m_UIEventList = uiEventList;
m_UIEventNode = uiEventNode;
m_UIEventParamDelegate = uiEventDelegate;
return this;
}
public void Dispose()
{
if (m_UIEventList == null || m_UIEventNode == null) return;
m_UIEventList.Remove(m_UIEventNode);
m_UIEventNode = null;
m_UIEventList = null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b586fca33f8f4b5fad014a0866919f5d
timeCreated: 1681134333

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using YIUIFramework;
namespace YIUIBind
{
/// <summary>
/// UI事件全局对象池
/// </summary>
public static class PublicUIEventP2<P1, P2>
{
public static readonly ObjectPool<UIEventHandleP2<P1, P2>> HandlerPool =
new ObjectPool<UIEventHandleP2<P1, P2>>(
null, handler => handler.Dispose());
}
/// <summary>
/// UI事件 2个泛型参数
/// </summary>
public sealed class UIEventHandleP2<P1, P2>
{
private LinkedList<UIEventHandleP2<P1, P2>> m_UIEventList;
private LinkedListNode<UIEventHandleP2<P1, P2>> m_UIEventNode;
private UIEventDelegate<P1, P2> m_UIEventParamDelegate;
public UIEventDelegate<P1, P2> UIEventParamDelegate => m_UIEventParamDelegate;
public UIEventHandleP2()
{
}
internal UIEventHandleP2<P1, P2> Init(
LinkedList<UIEventHandleP2<P1, P2>> uiEventList,
LinkedListNode<UIEventHandleP2<P1, P2>> uiEventNode,
UIEventDelegate<P1, P2> uiEventDelegate)
{
m_UIEventList = uiEventList;
m_UIEventNode = uiEventNode;
m_UIEventParamDelegate = uiEventDelegate;
return this;
}
public void Dispose()
{
if (m_UIEventList == null || m_UIEventNode == null) return;
m_UIEventList.Remove(m_UIEventNode);
m_UIEventNode = null;
m_UIEventList = null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 343d36f6835d434b9e222aef2c175203
timeCreated: 1681179723

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using YIUIFramework;
namespace YIUIBind
{
/// <summary>
/// UI事件全局对象池
/// </summary>
public static class PublicUIEventP3<P1, P2, P3>
{
public static readonly ObjectPool<UIEventHandleP3<P1, P2, P3>> HandlerPool =
new ObjectPool<UIEventHandleP3<P1, P2, P3>>(
null, handler => handler.Dispose());
}
/// <summary>
/// UI事件 3个泛型参数
/// </summary>
public sealed class UIEventHandleP3<P1, P2, P3>
{
private LinkedList<UIEventHandleP3<P1, P2, P3>> m_UIEventList;
private LinkedListNode<UIEventHandleP3<P1, P2, P3>> m_UIEventNode;
private UIEventDelegate<P1, P2, P3> m_UIEventParamDelegate;
public UIEventDelegate<P1, P2, P3> UIEventParamDelegate => m_UIEventParamDelegate;
public UIEventHandleP3()
{
}
internal UIEventHandleP3<P1, P2, P3> Init(
LinkedList<UIEventHandleP3<P1, P2, P3>> uiEventList,
LinkedListNode<UIEventHandleP3<P1, P2, P3>> uiEventNode,
UIEventDelegate<P1, P2, P3> uiEventDelegate)
{
m_UIEventList = uiEventList;
m_UIEventNode = uiEventNode;
m_UIEventParamDelegate = uiEventDelegate;
return this;
}
public void Dispose()
{
if (m_UIEventList == null || m_UIEventNode == null) return;
m_UIEventList.Remove(m_UIEventNode);
m_UIEventNode = null;
m_UIEventList = null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5f63a6ae806240378371e21d9bbc1d9e
timeCreated: 1681179767

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using YIUIFramework;
namespace YIUIBind
{
/// <summary>
/// UI事件全局对象池
/// </summary>
public static class PublicUIEventP4<P1, P2, P3, P4>
{
public static readonly ObjectPool<UIEventHandleP4<P1, P2, P3, P4>> HandlerPool =
new ObjectPool<UIEventHandleP4<P1, P2, P3, P4>>(
null, handler => handler.Dispose());
}
/// <summary>
/// UI事件 4个泛型参数
/// </summary>
public sealed class UIEventHandleP4<P1, P2, P3, P4>
{
private LinkedList<UIEventHandleP4<P1, P2, P3, P4>> m_UIEventList;
private LinkedListNode<UIEventHandleP4<P1, P2, P3, P4>> m_UIEventNode;
private UIEventDelegate<P1, P2, P3, P4> m_UIEventParamDelegate;
public UIEventDelegate<P1, P2, P3, P4> UIEventParamDelegate => m_UIEventParamDelegate;
public UIEventHandleP4()
{
}
internal UIEventHandleP4<P1, P2, P3, P4> Init(
LinkedList<UIEventHandleP4<P1, P2, P3, P4>> uiEventList,
LinkedListNode<UIEventHandleP4<P1, P2, P3, P4>> uiEventNode,
UIEventDelegate<P1, P2, P3, P4> uiEventDelegate)
{
m_UIEventList = uiEventList;
m_UIEventNode = uiEventNode;
m_UIEventParamDelegate = uiEventDelegate;
return this;
}
public void Dispose()
{
if (m_UIEventList == null || m_UIEventNode == null) return;
m_UIEventList.Remove(m_UIEventNode);
m_UIEventNode = null;
m_UIEventList = null;
}
}
}

Some files were not shown because too many files have changed in this diff Show More