Skip to content

Latest commit

 

History

History
43 lines (37 loc) · 1.62 KB

TsProperties.md

File metadata and controls

43 lines (37 loc) · 1.62 KB

介绍

一个单独的序列化类, 可用于保存数据丶挂载UnityEngine.Object对象等操作;

定义

[C#]继承: XOR.TsPropertiesUnityEngine.MonoBehaviour

接口详情
方法 描述
XOR.Serializables.ResultPair[] GetProperties() 获取所有序列化成员
void SetProperty(string, object) (EditorOnly)设置键值
void SetPropertyListener(Action<string, object>) (EditorOnly)设置键值更新回调

内置类型

请参照TsComponent内置类型

简单演示

示例场景:projects/Assets/Samples/02_TsProperties
示例typescript代码: projects/TsProject/src/samples/02_TsProperties.ts

image

export function init(target: CS.XOR.TsProperties) {
    let properties = target?.GetProperties();
    if (properties) {
        let stringBuilder: string[] = [];
        for (let i = 0; i < properties.Length; i++) {
            let property = properties.get_Item(i);
            stringBuilder.push(`${property.key}: ${property.value}`);
        }
        console.log(stringBuilder.join("\n"));
    } else {
        console.log("empty");
    }
}

运行后将输出以下语句:
key0: 12
key1: false
key2: null