/// <inheritdoc/> protected override void CreateList() { array = property.CreateArrayInstance(new int[1] { 0 }); property.SetValue(array); numElements = 0; }
/// <inheritdoc/> protected override void CreateList() { RecordStateForUndo(); list = property.CreateListInstance(0); property.SetValue(list); numElements = 0; }
/// <inheritdoc/> protected override void CreateList() { StartUndo(); list = property.CreateListInstance(0); property.SetValue(list); numElements = 0; EndUndo(); }
/// <summary> /// Creates a new inspectable object GUI for the specified property. /// </summary> /// <param name="context">Context shared by all inspectable fields created by the same parent.</param> /// <param name="title">Name of the property, or some other value to set as the title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties).</param> /// <param name="depth">Determines how deep within the inspector nesting hierarchy is this field. Some fields may /// contain other fields, in which case you should increase this value by one.</param> /// <param name="layout">Parent layout that all the field elements will be added to.</param> /// <param name="property">Serializable property referencing the object whose contents to display.</param> /// <param name="style">Information that can be used for customizing field rendering and behaviour.</param> public InspectableObject(InspectableContext context, string title, string path, int depth, InspectableFieldLayout layout, SerializableProperty property, InspectableFieldStyleInfo style) : base(context, title, path, SerializableProperty.FieldType.Object, depth, layout, property) { this.style = style; isExpanded = context.Persistent.GetBool(path + "_Expanded"); isInline = style != null && style.StyleFlags.HasFlag(InspectableFieldStyleFlags.Inline); // Builds a context menu that lets the user create objects to assign to this field. bool hasCreateButton = !property.IsValueType && !isInline; if (hasCreateButton) { instantiableTypes = GetInstantiableTypes(property.InternalType); if (instantiableTypes.Length > 1) { createContextMenu = new ContextMenu(); Array.Sort(instantiableTypes, (x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal)); bool showNamespace = false; string ns = instantiableTypes[0].Namespace; for (int i = 1; i < instantiableTypes.Length; i++) { if (instantiableTypes[i].Namespace != ns) { showNamespace = true; break; } } foreach (var type in instantiableTypes) { string prefix = ""; if (showNamespace) { prefix = type.Namespace + "."; } createContextMenu.AddItem(prefix + type.Name, () => { StartUndo(); property.SetValue(Activator.CreateInstance(type)); EndUndo(); }); } } } }
/// <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"); }
/// <inheritdoc/> protected internal override object GetValue(int seqIndex) { SerializableArray serzArray = property.GetArray(); // Create a property wrapper for native arrays so we get notified when the array values change if (style.StyleFlags.HasFlag(InspectableFieldStyleFlags.NativeWrapper)) { SerializableProperty.Getter getter = () => { Array array = property.GetValue <Array>(); if (array != null) { return(array.GetValue(seqIndex)); } else { return(null); } }; SerializableProperty.Setter setter = (object value) => { Array array = property.GetValue <Array>(); if (array != null) { array.SetValue(value, seqIndex); property.SetValue(array); } }; return(new SerializableProperty(serzArray.ElementPropertyType, serzArray.ElementType, getter, setter)); } else { return(serzArray.GetProperty(seqIndex)); } }
/// <summary> /// Creates a new inspectable array GUI for the specified property. /// </summary> /// <param name="parent">Parent Inspector this field belongs to.</param> /// <param name="title">Name of the property, or some other value to set as the title.</param> /// <param name="path">Full path to this property (includes name of this property and all parent properties).</param> /// <param name="depth">Determines how deep within the inspector nesting hierarchy is this field. Some fields may /// contain other fields, in which case you should increase this value by one.</param> /// <param name="layout">Parent layout that all the field elements will be added to.</param> /// <param name="property">Serializable property referencing the object whose contents to display.</param> public InspectableObject(Inspector parent, string title, string path, int depth, InspectableFieldLayout layout, SerializableProperty property) : base(parent, title, path, SerializableProperty.FieldType.Object, depth, layout, property) { isExpanded = parent.Persistent.GetBool(path + "_Expanded"); // Builds a context menu that lets the user create objects to assign to this field. Type[] types = GetInstantiableTypes(property.InternalType); if (types.Length > 0) { createContextMenu = new ContextMenu(); Array.Sort(types, (x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal)); foreach (var type in types) { createContextMenu.AddItem(type.Namespace + "." + type.Name, () => property.SetValue(Activator.CreateInstance(type))); } } }
/// <inheritdoc/> protected override void CreateList() { list = property.CreateListInstance(0); property.SetValue(list); numElements = 0; }
public void Read(IReadMessage msg) { int oldPos = msg.BitPosition; UInt32 size = msg.ReadVariableUInt32(); float x; float y; float z; float w; byte r; byte g; byte b; byte a; int ix; int iy; int width; int height; switch (typeString) { case "float": if (size != 4) { break; } property.SetValue(parentObject, msg.ReadSingle()); return; case "int": if (size != 4) { break; } property.SetValue(parentObject, msg.ReadInt32()); return; case "vector2": if (size != 8) { break; } x = msg.ReadSingle(); y = msg.ReadSingle(); property.SetValue(parentObject, new Vector2(x, y)); return; case "vector3": if (size != 12) { break; } x = msg.ReadSingle(); y = msg.ReadSingle(); z = msg.ReadSingle(); property.SetValue(parentObject, new Vector3(x, y, z)); return; case "vector4": if (size != 16) { break; } x = msg.ReadSingle(); y = msg.ReadSingle(); z = msg.ReadSingle(); w = msg.ReadSingle(); property.SetValue(parentObject, new Vector4(x, y, z, w)); return; case "color": if (size != 4) { break; } r = msg.ReadByte(); g = msg.ReadByte(); b = msg.ReadByte(); a = msg.ReadByte(); property.SetValue(parentObject, new Color(r, g, b, a)); return; case "rectangle": if (size != 16) { break; } ix = msg.ReadInt32(); iy = msg.ReadInt32(); width = msg.ReadInt32(); height = msg.ReadInt32(); property.SetValue(parentObject, new Rectangle(ix, iy, width, height)); return; default: msg.BitPosition = oldPos; //reset position to properly read the string string incVal = msg.ReadString(); property.TrySetValue(parentObject, incVal); return; } //size didn't match: skip this msg.BitPosition += (int)(8 * size); }
/// <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(); }