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));
     }
 }
        public static DrawFunction CreateDrawFunction <T>(Func <T, T> drawFunction)
        {
            return((label, value, parameters) =>
            {
                var labelWidth = GUILayout.Width(InternalPropertyDrawer.CalculateLabelWidth());
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(label, labelWidth);
                var newValue = drawFunction((T)value);
                EditorGUILayout.EndHorizontal();

                return newValue;
            });
        }
 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));
     }
 }
        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);
        }
 public static bool GetDrawFunction <T>(out DrawFunction drawFunction)
 {
     return(InternalPropertyDrawer.GetDrawFunction(typeof(T), out drawFunction));
 }