您的位置:首页 > 游戏 > 游戏 > 官方网站下载zoom_it行业职位薪资一览表_帮平台做推广怎么赚钱_深圳营销策划公司十强

官方网站下载zoom_it行业职位薪资一览表_帮平台做推广怎么赚钱_深圳营销策划公司十强

2024/11/18 10:28:21 来源:https://blog.csdn.net/u010125551/article/details/142380016  浏览:    关键词:官方网站下载zoom_it行业职位薪资一览表_帮平台做推广怎么赚钱_深圳营销策划公司十强
官方网站下载zoom_it行业职位薪资一览表_帮平台做推广怎么赚钱_深圳营销策划公司十强

20240918. 新增 BindableList

BindableProperty 很好用,但是不支持 List 等集合。

而 Bindable List 功能群友呼吁了很久了。

应群友要求,笔者实现了 Bindable List。

基本使用方式如下:

using System;
using UnityEngine;
using UnityEngine.UI;namespace QFramework.Example
{public class BindableListExample : MonoBehaviour{private BindableList<string> mNameList = new BindableList<string>();public Text NameTextTemplate;public Transform ContentRoot;private void Start(){NameTextTemplate.Hide();mNameList.OnCountChanged.Register(count =>{print("count:" + count);}).UnRegisterWhenGameObjectDestroyed(gameObject);mNameList.OnAdd.Register((index, newName) =>{print("add:" + index + "," + newName);NameTextTemplate.InstantiateWithParent(ContentRoot).SiblingIndex(index).Show().text = newName;}).UnRegisterWhenGameObjectDestroyed(gameObject);mNameList.OnMove.Register((oldIndex, newIndex, nameItem) =>{print("move:" + oldIndex + "," + newIndex + "," + nameItem);ContentRoot.GetChild(oldIndex).SiblingIndex(newIndex);}).UnRegisterWhenGameObjectDestroyed(gameObject);mNameList.OnRemove.Register((index, nameItem) =>{print("remove:" + index + "," + nameItem);ContentRoot.GetChild(index).DestroyGameObjGracefully();}).UnRegisterWhenGameObjectDestroyed(gameObject);mNameList.OnReplace.Register((index,oldName, newName) =>{print("replace:" + index + "," + oldName + "," + newName);ContentRoot.GetChild(index).GetComponent<Text>().text = newName;}).UnRegisterWhenGameObjectDestroyed(gameObject);mNameList.OnClear.Register(() =>{print("clear");ContentRoot.DestroyChildren();}).UnRegisterWhenGameObjectDestroyed(gameObject);}private string mNameToRemove = null;private void OnGUI(){IMGUIHelper.SetDesignResolution(640,360);GUILayout.Label("count:" + mNameList.Count);GUILayout.BeginVertical("box");foreach (var nameItem in mNameList){GUILayout.BeginHorizontal("box");GUILayout.Label(nameItem);if (GUILayout.Button("-")){mNameToRemove = nameItem;}GUILayout.EndHorizontal();}if (mNameToRemove.IsNotNullAndEmpty()){mNameList.Remove(mNameToRemove);mNameToRemove = null;}GUILayout.EndVertical();if (GUILayout.Button("add")){mNameList.Add("liangxie" + UnityEngine.Random.Range(0,100));}if (mNameList.Count > 0){if (GUILayout.Button("remove at 0")){mNameList.RemoveAt(0);}if (GUILayout.Button("replace at 0")){mNameList[0] = "replaced name" + UnityEngine.Random.Range(0, 100);}if (mNameList.Count > 1){if (GUILayout.Button("move 0 -> 1")){mNameList.Move(0, 1);}}if (GUILayout.Button("clear")){mNameList.Clear();}}}}
}

运行结果如下:

bindable_list

本文由 《QFramework 教程年会员》赞助,298 元,9 套教程一年内随便看。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com