5 Star 23 Fork 3

NikaidoShinku / YukiFrameWork

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
11.BindableProperty.md 1.40 KB
一键复制 编辑 原始数据 按行查看 历史

工具类BindableProperty:

普通属性绑定类 BindableProperty API如下:

- ///绑定事件
- IUnRegister Register(Action<TValue> action);
- ///绑定事件并自动初始化
- IUnRegister RegisterWithInitValue(Action<TValue> action);    
- ///注销事件,如没有传递事件则清空
- void UnRegisterEvent(Action<T> onEvent = null);
- ///绑定Mono生命周期,当Mono类销毁时自动注销
- void UnRegisterWaitGameObjectDestroy<TComponent>(TComponent component,Action callBack = null) where TComponent : UnityEngine.Component

数据强化,可自带回调 使用方式如下

public class TestScript
{
    public BindableProperty<int> Num = new BindableProperty<int>(5);

    public void Start()
    {
        Num.Register(value => Debug.Log(value));
    }
}

额外拓展:

  • 极速列表:FastList
  • 线程安全的极速列表:FastListSafe

using YukiFrameWork;

public class TestScript : MonoBehaviour
{
	void Start()
	{
		FastList<string> list = new FastList<string>();

		///正常享受List的API:

		//绑定事件(参数为列表的对象)
		list.Register((value) => { });

		//绑定事件并自动调用一次(这里会遍历列表里所有的数据都调用一次)
		list.RegisterWithInitValue((value) => { });

		//添加键值,自动调用注册的事件
		list.Add("第一个");		

		在使用上FastList拥有比List更快的速度。
	}
}
C#
1
https://gitee.com/NikaidoShinku/YukiFrameWork.git
git@gitee.com:NikaidoShinku/YukiFrameWork.git
NikaidoShinku
YukiFrameWork
YukiFrameWork
master

搜索帮助