首页 > 其他分享 >QFramework v1.0 使用指南 架构篇:17. 内置工具:BindableProperty

QFramework v1.0 使用指南 架构篇:17. 内置工具:BindableProperty

时间:2022-10-17 11:58:26浏览次数:83  
标签:17 mName QFramework v1.0 mSomeValue https com BindableProperty

在此篇介绍 BindableProperty。

BindableProperty 提供 数据 + 数据变更事件 的一个对象。

基本使用

using UnityEngine;

namespace QFramework.Example
{
    public class BindablePropertyExample : MonoBehaviour
    {
        private BindableProperty<int> mSomeValue = new BindableProperty<int>(0);

        private BindableProperty<string> mName = new BindableProperty<string>("QFramework");
        
        void Start()
        {
            mSomeValue.Register(newValue =>
            {
                Debug.Log(newValue);
            }).UnRegisterWhenGameObjectDestroyed(gameObject);

            mName.RegisterWithInitValue(newName =>
            {
                Debug.Log(mName);
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
        }
        
        void Update()
        {

            if (Input.GetMouseButtonDown(0))
            {
                mSomeValue.Value++;
            }
        }
    }
}


// 输出结果
// QFramework
// 按下鼠标左键,输出:
// 1
// 按下鼠标左键,输出:
// 2

非常简单。

关于 BindableProperty,在之前写 CounterApp 的时候有介绍过,所以这篇就介绍到这里。

更多内容

标签:17,mName,QFramework,v1.0,mSomeValue,https,com,BindableProperty
From: https://www.cnblogs.com/liangxiegame/p/16798672.html

相关文章