/// <summary> /// Displays the property field in the center of the window. /// This method distinguishes between certain properties. /// The GameObject tag, for example, shouldn't be displayed with a regular string field. /// </summary> /// <param name="p">The SerializedProerty to display</param> /// <param name="width">The width of the whole thing in the ui</param> private void PropertyField(SerializedProperty p, float width = 170) { if(p.IsRealArray()) { DisplayArrayProperty(p, width); } else { var oldValue = p.GetValue(); if(fieldname == "GameObject.TagString") { var oldTag = oldValue as string; var newTag = EditorGUILayout.TagField("", oldTag, GUILayout.Width(width)); if(newTag != oldTag) { p.SetValue(newTag); } } else if(fieldname == "GameObject.StaticEditorFlags") { DisplayStaticFlagChooser(p, width); } else { EditorGUILayout.PropertyField(p, new GUIContent(""), GUILayout.Width(width)); } if(!object.Equals(p.GetValue(), oldValue)) { p.serializedObject.ApplyModifiedProperties(); UsedNew(); } } }
private string SerializedValueString(SerializedProperty p) { if(fieldname == "GameObject.StaticEditorFlags") { switch(p.intValue) { case 0: return "Not static"; case -1: return "Static"; default: return "Mixed static"; } } else if(p.IsRealArray()) { return "Array[" + p.arraySize + "]"; } return ValueString(p.GetValue()); }
/// <summary> /// Returns true when the two properties have different values, false otherwise. /// </summary> private static bool DifferentValues(SerializedProperty ourProperty, SerializedProperty theirProperty) { if(!ourProperty.IsRealArray()) { //Regular single-value property if(DifferentValuesFlat(ourProperty, theirProperty)) { return true; } } else { //Array property if(ourProperty.arraySize != theirProperty.arraySize) { return true; } var op = ourProperty.Copy(); var tp = theirProperty.Copy(); op.Next(true); op.Next(true); tp.Next(true); tp.Next(true); for(int i = 0; i < ourProperty.arraySize; ++i) { op.Next(false); tp.Next(false); if(DifferentValuesFlat(op, tp)) { return true; } } } return false; }