本文整理汇总了C#中UnityEditor.FindPropertyRelative方法的典型用法代码示例。如果您正苦于以下问题:C# UnityEditor.FindPropertyRelative方法的具体用法?C# UnityEditor.FindPropertyRelative怎么用?C# UnityEditor.FindPropertyRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor
的用法示例。
在下文中一共展示了UnityEditor.FindPropertyRelative方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnGUI
public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
{
string fieldName;
bool notifyPropertyChanged;
{
var attr = this.attribute as InspectorDisplayAttribute;
fieldName = (attr == null) ? "value" : attr.FieldName;
notifyPropertyChanged = (attr == null) ? true : attr.NotifyPropertyChanged;
}
if (notifyPropertyChanged)
{
EditorGUI.BeginChangeCheck();
}
var targetSerializedProperty = property.FindPropertyRelative(fieldName);
if (targetSerializedProperty == null)
{
UnityEditor.EditorGUI.LabelField(position, label, new GUIContent() { text = "InspectorDisplay can't find target:" + fieldName });
if (notifyPropertyChanged)
{
EditorGUI.EndChangeCheck();
}
return;
}
else
{
EmitPropertyField(position, targetSerializedProperty, label);
}
if (notifyPropertyChanged)
{
if (EditorGUI.EndChangeCheck())
{
var propInfo = fieldInfo.FieldType.GetProperty(fieldName, BindingFlags.IgnoreCase | BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
property.serializedObject.ApplyModifiedProperties(); // deserialize to field
var paths = property.propertyPath.Split('.'); // X.Y.Z...
var attachedComponent = property.serializedObject.targetObject;
var targetProp = (paths.Length == 1)
? fieldInfo.GetValue(attachedComponent)
: GetValueRecursive(attachedComponent, 0, paths);
var modifiedValue = propInfo.GetValue(targetProp, null); // retrieve new value
var methodInfo = fieldInfo.FieldType.GetMethod("SetValueAndForceNotify", BindingFlags.IgnoreCase | BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (methodInfo != null)
{
methodInfo.Invoke(targetProp, new object[] { modifiedValue });
}
}
else
{
property.serializedObject.ApplyModifiedProperties();
}
}
}