SerializedProperty.GetFixedBufferElementAtIndex

切换到手册
public SerializedProperty GetFixedBufferElementAtIndex (int index);

描述

返回固定缓冲区中指定索引处的元素。

另请参阅:isFixedBufferfixedBufferSize

using UnityEngine;
using UnityEditor;

[System.Serializable] public unsafe struct TestStruct { public fixed int intBuffer[7]; }

public unsafe class TestScript : MonoBehaviour { public TestStruct testStruct;

void Start() { fixed(int* buffer = testStruct.intBuffer) { for (int i = 0; i < 7; ++i) buffer[i] = 3 + i; }

var so = new SerializedObject(this); var prop = so.FindProperty("testStruct.intBuffer");

Debug.Log("isFixedBuffer = " + prop.isFixedBuffer); Debug.Log("fixedBufferSize = " + prop.fixedBufferSize);

var elemProp = prop.GetFixedBufferElementAtIndex(2);

Debug.Log("GetFixedBufferElementAtIndex(2) = " + elemProp.intValue);

elemProp.intValue = 42;

so.ApplyModifiedProperties();

fixed(int* buffer = testStruct.intBuffer) { Debug.Log("intBuffer[2] = " + buffer[2]); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961