private void DrawMember(MemberReference member, ShowInInspectorAttribute attribute) { FlaiGUI.PushGuiEnabled(!attribute.IsReadOnly && (attribute.IsEditableWhenNotPlaying || Application.isPlaying) && member.CanWrite); if (!this.TryDrawMember(member, attribute)) { DrawFunction drawFunction; if (InternalPropertyDrawer.GetDrawFunction(member, attribute, out drawFunction)) { this.DrawMember(member, attribute, drawFunction); } else { var value = member.GetValue(this.Target); if (value is UnityObject) // simple special case.. not sure what I needed this for though... :| { this.DrawMember(member, attribute, (n, v, o) => EditorGUILayout.ObjectField(n, (UnityObject)v, typeof(UnityObject), true)); } else { FlaiGUI.PushGuiEnabled(false); this.DrawMember(member, attribute, (n, v, o) => EditorGUILayout.TextField(n + " (unkown type)", (v == null) ? "" : v.ToString()), true); FlaiGUI.PopGuiEnabled(); } } } FlaiGUI.PopGuiEnabled(); }
private void DrawMember(MemberReference memberReference, ShowInInspectorAttribute attribute, DrawFunction drawFunction, bool forceReadOnly) { var newValue = drawFunction(this.GetName(memberReference, attribute), memberReference.GetValue(this.Target), null); if (GUI.changed && memberReference.CanWrite && !forceReadOnly) { memberReference.SetValue(this.Target, newValue); } }
public static bool GetDrawFunction(MemberReference member, ShowInInspectorAttribute attribute, out DrawFunction drawFunction) { if (InternalPropertyDrawer.GetDrawFunction(member.InnerType, member, attribute, out drawFunction)) { return(true); } drawFunction = null; return(false); }
public static DrawFunction GenerateFloat(MemberReference member, ShowInInspectorAttribute attribute) { if (member.HasValue && member.MemberInfo.HasCustomAttribute <ShowAsFloatSliderAttribute>()) { var sliderAttribute = member.MemberInfo.GetCustomAttribute <ShowAsFloatSliderAttribute>(); return((label, value, parameters) => EditorGUILayout.Slider(label, (float)value, sliderAttribute.Min, sliderAttribute.Max, parameters)); } else { return(InternalPropertyDrawer.CreateDrawFunction <float>(EditorGUILayout.FloatField)); } }
private void DrawMethod(MethodInfo method, ShowInInspectorAttribute attribute) { if (method.ContainsGenericParameters || method.GetParameters().Length > 0) { FlaiDebug.LogWarningWithTypeTag <DefaultInspector>("Method '{0}' has parameters or generic parameters. It cannot be called", method.Name); return; } FlaiGUI.PushGuiEnabled(!attribute.IsReadOnly && (attribute.IsEditableWhenNotPlaying || Application.isPlaying)); if (GUILayout.Button(this.GetName(method.Name, attribute))) { method.Invoke(this.Target, null); } FlaiGUI.PopGuiEnabled(); }
public static DrawFunction GenerateInt(MemberReference member, ShowInInspectorAttribute attribute) { if (member.HasValue && member.MemberInfo.HasCustomAttribute <ShowAsIntSliderAttribute>()) { var sliderAttribute = member.MemberInfo.GetCustomAttribute <ShowAsIntSliderAttribute>(); return((label, value, parameters) => EditorGUILayout.IntSlider(label, (int)value, sliderAttribute.Min, sliderAttribute.Max, parameters)); } else if (member.HasValue && Attribute.IsDefined(member.MemberInfo, typeof(ShowAsLayerAttribute))) { return(InternalPropertyDrawer.CreateDrawFunction <int>(EditorGUILayout.LayerField)); } else { return(InternalPropertyDrawer.CreateDrawFunction <int>(EditorGUILayout.IntField)); } }
private void DrawMember(MemberReference member, ShowInInspectorAttribute attribute, DrawFunction drawFunction) { this.DrawMember(member, attribute, drawFunction, false); }
protected virtual bool TryDrawMember(MemberReference memberReference, ShowInInspectorAttribute attribute) { return(false); }
private string GetName(string memberName, ShowInInspectorAttribute attribute) { return(attribute.Name ?? Common.AddSpaceBeforeCaps(memberName)); }
private string GetName(MemberReference member, ShowInInspectorAttribute attribute) { return(this.GetName(member.Name, attribute)); }
public static bool GetDrawFunction(Type type, MemberReference memberReference, ShowInInspectorAttribute attribute, out DrawFunction drawFunction) { if (_drawFunctions.TryGetValue(type, out drawFunction)) { return(true); } DrawFunctionGenerator generator; if (_drawFunctionGenerators.TryGetValue(type, out generator)) { drawFunction = generator(memberReference, attribute); return(true); } if (type.IsEnum) { drawFunction = (n, v, o) => EditorGUILayout.EnumPopup(n, (Enum)v, o); return(true); } else if (typeof(UnityObject).IsAssignableFrom(type)) { drawFunction = (n, v, o) => EditorGUILayout.ObjectField(n, (UnityObject)v, type, true, o); return(true); } else if (type.IsArray) { Type elementType = type.GetElementType(); DrawFunction elementDrawFunction; if (InternalPropertyDrawer.GetDrawFunction(elementType, out elementDrawFunction)) { drawFunction = (label, value, parameters) => { const int IndentationAmount = 20; Array array = (Array)value; // draw the name of the array EditorGUILayout.LabelField(label, EditorStyles.boldLabel); // draw the length (and '+' & '-' buttons) EditorGUILayout.BeginHorizontal(); GUILayout.Space(IndentationAmount); int newLength = EditorGUILayout.IntField("Length", array.Length); if (GUILayout.Button("+", GUILayout.Width(24))) { newLength++; } else if (GUILayout.Button("-", GUILayout.Width(24))) { newLength = FlaiMath.Max(0, newLength - 1); } EditorGUILayout.EndHorizontal(); // if the size has been changed, then update it if (newLength != array.Length && newLength > 0) { Array newArray = (Array)Activator.CreateInstance(array.GetType(), newLength); if (array.Length > 0) { for (int i = 0; i < newArray.Length; i++) { var elementValue = (i >= array.Length) ? array.GetValue(array.Length - 1) : array.GetValue(i); newArray.SetValue(elementValue, i); } } array = newArray; } // draw all the elements for (int i = 0; i < array.Length; i++) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(IndentationAmount); array.SetValue(elementDrawFunction("Element " + i, array.GetValue(i), null), i); EditorGUILayout.EndHorizontal(); } return(array); }; return(true); } } return(false); }