Version: 2020.1
public SerializedProperty FindProperty (string propertyPath);

描述

按名称查找序列化属性。

您可以使用此函数来查找目标对象中的特定属性。

另请参阅:GetIteratorSerializedProperty

using UnityEngine;
using UnityEditor;

public class MyObject : ScriptableObject { public int myInt = 42; }

public class SerializedPropertyTest : MonoBehaviour { void Start() { MyObject obj = ScriptableObject.CreateInstance<MyObject>(); SerializedObject serializedObject = new UnityEditor.SerializedObject(obj);

SerializedProperty serializedPropertyMyInt = serializedObject.FindProperty("myInt");

Debug.Log("myInt " + serializedPropertyMyInt.intValue); } }