/// <inheritdoc/> protected internal override void AddEntry(object key, object value) { StartUndo(); SerializableProperty keyProperty = (SerializableProperty)key; SerializableProperty valueProperty = (SerializableProperty)value; dictionary.Add(keyProperty.GetValue <object>(), valueProperty.GetValue <object>()); numElements = dictionary.Count; EndUndo(); UpdateKeys(); }
/// <summary> /// Constructs a new empty inspectable list GUI. /// </summary> /// <param name="parent">Parent Inspector this field belongs to.</param> /// <param name="title">Label to display on the list GUI title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties). /// </param> /// <param name="property">Serializable property referencing a list.</param> /// <param name="layout">Layout to which to append the list GUI elements to.</param> /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple /// nested containers whose backgrounds are overlaping. Also determines background style, /// depths divisible by two will use an alternate style.</param> public InspectableListGUI(Inspector parent, LocString title, string path, SerializableProperty property, GUILayout layout, int depth) : base(title, layout, depth) { this.property = property; this.parent = parent; this.path = path; list = property.GetValue <IList>(); if (list != null) { numElements = list.Count; } }
/// <summary> /// Constructs a new inspectable array GUI. /// </summary> /// <param name="parent">Parent Inspector this field belongs to.</param> /// <param name="title">Label to display on the list GUI title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties). /// </param> /// <param name="property">Serializable property referencing a single-dimensional array.</param> /// <param name="layout">Layout to which to append the list GUI elements to.</param> /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple /// nested containers whose backgrounds are overlaping. Also determines background style, /// depths divisible by two will use an alternate style.</param> public InspectableArrayGUI(Inspector parent, LocString title, string path, SerializableProperty property, GUILayout layout, int depth) : base(title, layout, depth) { this.property = property; this.parent = parent; this.path = path; array = property.GetValue <Array>(); if (array != null) { numElements = array.Length; } }
/// <summary> /// Constructs a new inspectable array GUI. /// </summary> /// <param name="context">Context shared by all inspectable fields created by the same parent.</param> /// <param name="title">Label to display on the list GUI title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties). /// </param> /// <param name="property">Serializable property referencing a single-dimensional array.</param> /// <param name="layout">Layout to which to append the list GUI elements to.</param> /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple /// nested containers whose backgrounds are overlaping. Also determines background style, /// depths divisible by two will use an alternate style.</param> /// <param name="style">Information that can be used for customizing field rendering and behaviour.</param> public InspectableArrayGUI(InspectableContext context, LocString title, string path, SerializableProperty property, GUILayout layout, int depth, InspectableFieldStyleInfo style) : base(title, layout, depth) { this.property = property; this.context = context; this.path = path; this.style = style; array = property.GetValue <Array>(); if (array != null) { numElements = array.Length; } }
/// <summary> /// Constructs a new dictionary GUI. /// </summary> /// <param name="context">Context shared by all inspectable fields created by the same parent.</param> /// <param name="title">Label to display on the list GUI title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties). /// </param> /// <param name="property">Serializable property referencing a dictionary</param> /// <param name="layout">Layout to which to append the list GUI elements to.</param> /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple /// nested containers whose backgrounds are overlaping. Also determines background style, /// depths divisible by two will use an alternate style.</param> protected InspectableDictionaryGUI(InspectableContext context, LocString title, string path, SerializableProperty property, GUILayout layout, int depth = 0) : base(title, layout, depth) { this.property = property; this.context = context; this.path = path; dictionary = property.GetValue <IDictionary>(); if (dictionary != null) { numElements = dictionary.Count; } UpdateKeys(); }
/// <summary> /// Tests serializable properties used for inspection. /// </summary> static void UnitTest2_SerializableProperties() { SerializableObject obj = new SerializableObject(typeof(UT1_SerzCls), new UT1_SerzCls()); SerializableProperty prop = obj.Fields[0].GetProperty(); prop.SetValue(33); DebugUnit.Assert(prop.GetValue <int>() == 33); SerializableProperty prop2 = obj.Fields[2].GetProperty(); UT1_SerzCls child = new UT1_SerzCls(); child.anotherValue2 = "potato"; prop2.SetValue <UT1_SerzCls>(child); DebugUnit.Assert(prop2.GetValue <UT1_SerzCls>() != null); DebugUnit.Assert(prop2.GetValue <UT1_SerzCls>().anotherValue2 == "potato"); }
public void Write(IWriteMessage msg, object overrideValue = null) { if (overrideValue == null) { overrideValue = property.GetValue(parentObject); } switch (typeString) { case "float": msg.WriteVariableUInt32(4); msg.Write((float)overrideValue); break; case "int": msg.WriteVariableUInt32(4); msg.Write((int)overrideValue); break; case "vector2": msg.WriteVariableUInt32(8); msg.Write(((Vector2)overrideValue).X); msg.Write(((Vector2)overrideValue).Y); break; case "vector3": msg.WriteVariableUInt32(12); msg.Write(((Vector3)overrideValue).X); msg.Write(((Vector3)overrideValue).Y); msg.Write(((Vector3)overrideValue).Z); break; case "vector4": msg.WriteVariableUInt32(16); msg.Write(((Vector4)overrideValue).X); msg.Write(((Vector4)overrideValue).Y); msg.Write(((Vector4)overrideValue).Z); msg.Write(((Vector4)overrideValue).W); break; case "color": msg.WriteVariableUInt32(4); msg.Write(((Color)overrideValue).R); msg.Write(((Color)overrideValue).G); msg.Write(((Color)overrideValue).B); msg.Write(((Color)overrideValue).A); break; case "rectangle": msg.WriteVariableUInt32(16); msg.Write(((Rectangle)overrideValue).X); msg.Write(((Rectangle)overrideValue).Y); msg.Write(((Rectangle)overrideValue).Width); msg.Write(((Rectangle)overrideValue).Height); break; default: string strVal = overrideValue.ToString(); msg.Write(strVal); break; } }
/// <inheritdoc/> protected internal override bool Contains(object key) { SerializableProperty keyProperty = (SerializableProperty)key; return(dictionary.Contains(keyProperty.GetValue <object>()));; }
/// <summary> /// Constructs a new dictionary GUI. /// </summary> /// <param name="parent">Parent Inspector this field belongs to.</param> /// <param name="title">Label to display on the list GUI title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties). /// </param> /// <param name="property">Serializable property referencing a dictionary</param> /// <param name="layout">Layout to which to append the list GUI elements to.</param> /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple /// nested containers whose backgrounds are overlaping. Also determines background style, /// depths divisible by two will use an alternate style.</param> protected InspectableDictionaryGUI(Inspector parent, LocString title, string path, SerializableProperty property, GUILayout layout, int depth = 0) : base(title, layout, depth) { this.property = property; this.parent = parent; this.path = path; dictionary = property.GetValue<IDictionary>(); if (dictionary != null) numElements = dictionary.Count; UpdateKeys(); }
/// <summary> /// Constructs a new empty inspectable list GUI. /// </summary> /// <param name="parent">Parent Inspector this field belongs to.</param> /// <param name="title">Label to display on the list GUI title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties). /// </param> /// <param name="property">Serializable property referencing a list.</param> /// <param name="layout">Layout to which to append the list GUI elements to.</param> /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple /// nested containers whose backgrounds are overlaping. Also determines background style, /// depths divisible by two will use an alternate style.</param> public InspectableListGUI(Inspector parent, LocString title, string path, SerializableProperty property, GUILayout layout, int depth) : base(title, layout, depth) { this.property = property; this.parent = parent; this.path = path; list = property.GetValue<IList>(); if (list != null) numElements = list.Count; }
/// <summary> /// Builds a list of properties that will be animated using float animation curves. /// </summary> /// <param name="clip">Clip to retrieve the float animation curves from.</param> partial void RebuildFloatProperties(RRef <AnimationClip> clip) { if (clip == null) { floatProperties = null; return; } AnimationCurves curves = clip.Value.Curves; List <FloatCurvePropertyInfo> newFloatProperties = new List <FloatCurvePropertyInfo>(); for (int i = 0; i < curves.Generic.Length; i++) { bool isMorphCurve = curves.Generic[i].flags.HasFlag(AnimationCurveFlags.MorphWeight) || curves.Generic[i].flags.HasFlag(AnimationCurveFlags.MorphFrame); if (isMorphCurve) { continue; } string suffix; SerializableProperty property = FindProperty(SceneObject, curves.Generic[i].name, out suffix); if (property == null) { continue; } int elementIdx = 0; if (!string.IsNullOrEmpty(suffix)) { PropertySuffixInfo suffixInfo; if (PropertySuffixInfos.TryGetValue(suffix, out suffixInfo)) { elementIdx = suffixInfo.elementIdx; } } Action <float> setter = null; Type internalType = property.InternalType; switch (property.Type) { case SerializableProperty.FieldType.Vector2: if (internalType == typeof(Vector2)) { setter = f => { Vector2 value = property.GetValue <Vector2>(); value[elementIdx] = f; property.SetValue(value); }; } break; case SerializableProperty.FieldType.Vector3: if (internalType == typeof(Vector3)) { setter = f => { Vector3 value = property.GetValue <Vector3>(); value[elementIdx] = f; property.SetValue(value); }; } break; case SerializableProperty.FieldType.Vector4: setter = f => { Vector4 value = property.GetValue <Vector4>(); value[elementIdx] = f; property.SetValue(value); }; break; case SerializableProperty.FieldType.Color: if (internalType == typeof(Color)) { setter = f => { Color value = property.GetValue <Color>(); value[elementIdx] = f; property.SetValue(value); }; } break; case SerializableProperty.FieldType.Bool: setter = f => { bool value = f > 0.0f; property.SetValue(value); }; break; case SerializableProperty.FieldType.Int: setter = f => { int value = (int)f; property.SetValue(value); }; break; case SerializableProperty.FieldType.Float: setter = f => { property.SetValue(f); }; break; } if (setter == null) { continue; } FloatCurvePropertyInfo propertyInfo = new FloatCurvePropertyInfo(); propertyInfo.curveIdx = i; propertyInfo.setter = setter; newFloatProperties.Add(propertyInfo); } floatProperties = newFloatProperties.ToArray(); }