Example #1
0
        public override void OnLabelDragged(InspectorField field)
        {
            if (InspectorPreferences.IsDragControl(InspectorPreferences.ValueScroll))
            {
                object result      = field.GetValues()[0];
                double sensitivity = CalculateDragSensitivity(result);
                result = Convert.ToDouble(result) + (double)(sensitivity * HandleUtility.niceMouseDelta);

                RangeValueAttribute rangeValue = field.GetAttribute <RangeValueAttribute>();
                if (rangeValue != null)
                {
                    result = Math.Min(Math.Max((double)result, rangeValue.Min), rangeValue.Max);
                }

                RangeAttribute range = field.GetAttribute <RangeAttribute>();
                if (range != null)
                {
                    result = Math.Min(Math.Max((double)result, range.min), range.max);
                }

                try
                {
                    result = Convert.ChangeType(result, field.Type);
                    field.SetValue(result);
                }
                catch (Exception)
                {
                    return;
                }
            }
        }
Example #2
0
        public override void OnLabelDragged(InspectorField field)
        {
            if (InspectorPreferences.IsDragControl(InspectorPreferences.ValueScroll))
            {
                object result = field.GetValues()[0];
                long   value  = Convert.ToInt64(result);
                result = (long)Math.Round(value + (CalculateDragSensitivity(value) * HandleUtility.niceMouseDelta * 0.1f));

                RangeValueAttribute rangeValue = field.GetAttribute <RangeValueAttribute>();
                if (rangeValue != null)
                {
                    result = Math.Min(Math.Max((long)result, (long)rangeValue.Min), (long)rangeValue.Max);
                }

                RangeAttribute range = field.GetAttribute <RangeAttribute>();
                if (range != null)
                {
                    result = Math.Min(Math.Max((long)result, (long)range.min), (long)range.max);
                }

                try
                {
                    result = Convert.ChangeType(result, field.Type);
                    field.SetValue(result);
                }
                catch (Exception)
                {
                    return;
                }
            }
        }
Example #3
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            RangeValueAttribute range = field.GetAttribute <RangeValueAttribute>();

            if (range == null)
            {
                return;
            }

            EditorGUILayout.BeginHorizontal();

            RangeFloat[] ranges = field.GetValues <RangeFloat>();

            float[] mins      = new float[ranges.Length];
            float[] maxs      = new float[ranges.Length];
            float   min       = ranges[0].min;
            float   max       = ranges[0].max;
            bool    different = false;

            for (int i = 0; i < ranges.Length; i++)
            {
                mins[i] = ranges[i].min;
                maxs[i] = ranges[i].max;
                if (ranges[i].min != min || ranges[0].max != max)
                {
                    different = true;
                }
            }

            if (FloatEditor.DrawFloat("", mins, out min, GUILayout.Width(64)))
            {
                for (int i = 0; i < field.Instances.Length; i++)
                {
                    field.SetValue(field.Instances[i], new RangeFloat(min, ranges[i].max));
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = different;
            EditorGUILayout.MinMaxSlider(ref min, ref max, range.Min, range.Max);
            if (EditorGUI.EndChangeCheck() && min < max)
            {
                for (int i = 0; i < field.Instances.Length; i++)
                {
                    field.SetValue(field.Instances[i], new RangeFloat(min, max));
                }
            }

            if (FloatEditor.DrawFloat("", maxs, out max, GUILayout.Width(64)))
            {
                for (int i = 0; i < field.Instances.Length; i++)
                {
                    field.SetValue(field.Instances[i], new RangeFloat(ranges[i].min, max));
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Example #4
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            RangeValueAttribute rangeValue = field.GetAttribute <RangeValueAttribute>();
            RangeAttribute      range      = field.GetAttribute <RangeAttribute>();

            if (range != null && rangeValue == null)
            {
                rangeValue = new RangeValueAttribute(range.min, range.max);
            }

            AngleAttribute angle = field.GetAttribute <AngleAttribute>();

            object result;

            if (DrawFloatingNumber(new GUIContent(""), field.GetValues(), rangeValue, angle, style, out result))
            {
                field.SetValue(result);
            }
        }
        public override void Draw(InspectorField field, GUIStyle style)
        {
            EnumAttribute display = field.GetAttribute <EnumAttribute>();

            EditorGUI.showMixedValue = field.Mixed;

            EditorGUI.BeginChangeCheck();

            object result = null;
            long   value  = Convert.ToInt64(GetValue(field));

            if (display == null || !display.Masked)
            {
                if (display == null || display.Display == EnumDisplay.DropDown)
                {
                    result = DrawDropDown(field.Type, value, style, false);
                }
                else if (display.Display == EnumDisplay.Button)
                {
                    result = DrawEnum(field.Type, value, display.MaxItemsPerRow, style == null ? EditorStyles.toolbarButton : style);
                }
                else if (display.Display == EnumDisplay.Checkbox)
                {
                    result = DrawEnum(field.Type, value, display.MaxItemsPerRow, style == null ? EditorStyles.toggle : style);
                }
            }
            else
            {
                if (display == null || display.Display == EnumDisplay.DropDown)
                {
                    result = DrawDropDown(field.Type, value, style, true);
                }
                else if (display.Display == EnumDisplay.Button)
                {
                    result = DrawMasked(field.Type, value, display.MaxItemsPerRow, style == null ? EditorStyles.toolbarButton : style);
                }
                else if (display.Display == EnumDisplay.Checkbox)
                {
                    result = DrawMasked(field.Type, value, display.MaxItemsPerRow, style == null ? EditorStyles.toggle : style);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                field.SetValue(result);
            }
        }
Example #6
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            IPicker picker = field.GetAttribute <IPicker>();

            if (picker != null && !picker.IsPickingAvailable(field.Instances, field.GetValues()))
            {
                object obj = field.GetValue();
                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else if (obj == null)
                {
                    GUILayout.Label("None");
                }
                else if (field.OverloadToString)
                {
                    GUILayout.Label(obj.ToString());
                }
                else if (field.Type != null)
                {
                    GUILayout.Label(field.Type.Name);
                }

                return;
            }

            if (validator == null)
            {
                validator = typeof(EditorGUI).GetNestedType("ObjectFieldValidator", BindingFlags.NonPublic);
            }

            if (doObjectField == null)
            {
                doObjectField = typeof(EditorGUI).GetMethod("DoObjectField", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(Rect), typeof(Rect), typeof(int),
                                                                                                                                              typeof(UnityEngine.Object), typeof(Type), typeof(SerializedProperty), validator, typeof(bool), typeof(GUIStyle) }, null);
            }

            DontAllowSceneObjectAttribute dontAllow = field.GetAttribute <DontAllowSceneObjectAttribute>();;

            UnityEngine.Object value = (UnityEngine.Object)GetValue(field);

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();

            Type type = field.Type;

            if (value != null && AdvancedInspectorControl.ShowIconPreview)
            {
                if (previewIconStyle == null)
                {
                    previewIconStyle         = new GUIStyle();
                    previewIconStyle.margin  = new RectOffset(4, 2, 2, 2);
                    previewIconStyle.padding = new RectOffset(0, 0, 0, 0);
                }

                Texture2D preview = AssetPreview.GetAssetPreview(value);
                if (preview != null)
                {
                    int previewSize;
                    switch (AdvancedInspectorControl.IconPreviewSize)
                    {
                    case IconPreviewSize.Smallest:
                        previewSize = 16;
                        break;

                    case IconPreviewSize.Small:
                        previewSize = 24;
                        break;

                    case IconPreviewSize.Normal:
                        previewSize = 32;
                        break;

                    case IconPreviewSize.Large:
                        previewSize = 48;
                        break;

                    case IconPreviewSize.Largest:
                        previewSize = 64;
                        break;

                    default:
                        previewSize = 16;
                        break;
                    }

                    GUILayout.Label(preview, previewIconStyle, GUILayout.Width(previewSize), GUILayout.Height(previewSize));
                }
            }

            UnityEngine.Object result = null;

            if (type.IsInterface)
            {
                Rect     position   = EditorGUILayout.GetControlRect(false, 16f);
                int      id         = GUIUtility.GetControlID(s_ObjectFieldHash, EditorGUIUtility.native, position);
                Delegate validation = Delegate.CreateDelegate(validator, typeof(ObjectEditor).GetMethod("ValidateObjectFieldAssignment", BindingFlags.NonPublic | BindingFlags.Static));

                result = doObjectField.Invoke(null, new object[] { position, position, id, value, type, null, validation, dontAllow == null, EditorStyles.objectField }) as UnityEngine.Object;
            }
            else
            {
                result = EditorGUILayout.ObjectField(value, type, dontAllow == null);
            }

            if (EditorGUI.EndChangeCheck())
            {
                field.SetValue(result);
            }

            if (dontAllow == null && (field.Type == typeof(GameObject) ||
                                      typeof(Component).IsAssignableFrom(field.Type) || field.Type.IsAssignableFrom(typeof(Component))))
            {
                if (GUILayout.Button(Picker, GUIStyle.none, GUILayout.Width(18), GUILayout.Height(18)))
                {
                    InspectorEditor.StartPicking(Picked, field);
                }
            }

            EditorGUILayout.EndHorizontal();

            DrawObjectSelector(field);
        }
Example #7
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            GUILayout.BeginHorizontal();

            float width = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 0;

            TextFieldAttribute text      = field.GetAttribute <TextFieldAttribute>();
            MultilineAttribute multiline = field.GetAttribute <MultilineAttribute>();
            TextAreaAttribute  area      = field.GetAttribute <TextAreaAttribute>();

            object value = GetValue(field);

            EditorGUI.BeginChangeCheck();
            GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive);

            string result = "";

            if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard))
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextField((string)value);
                }
            }
            else if (multiline != null || area != null || text.Type == TextFieldType.Area)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextArea((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextArea((string)value);
                }
            }
            else if (text.Type == TextFieldType.Password)
            {
                if (style != null)
                {
                    result = EditorGUILayout.PasswordField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.PasswordField((string)value);
                }
            }
            else if (text.Type == TextFieldType.Tag)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TagField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TagField((string)value);
                }
            }
            else if (text.Type == TextFieldType.File)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension);
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }
            else if (text.Type == TextFieldType.Folder)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFolderPanel(text.Title, "", "");
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }

            //Custom
            else if (text.Type == TextFieldType.Prefab)
            {
                if (String.IsNullOrEmpty(text.Path))
                {
                    string prefabRemoved = field.GetValue <string>().Replace("Prefabs/", "");
                    //string prefabRemoved = field.GetValue<string>();
                    string[] PrefabListNoPrefix = UnityDrawerStatics.PrefabList
                                                  .Select(x => x.Replace("Prefabs/", ""))
                                                  .ToArray();
                    PrefabListNoPrefix = AddNoneToStringArray(PrefabListNoPrefix);

                    //int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.PrefabList, prefabRemoved), 0);
                    int sel = Math.Max(Array.IndexOf(PrefabListNoPrefix, prefabRemoved), 0);
                    int idx = EditorGUILayout.Popup(sel, PrefabListNoPrefix);
                    //result = "Prefabs/" + UnityDrawerStatics.PrefabList[idx];
                    //result = UnityDrawerStatics.PrefabList[idx];
                    result = "Prefabs/" + PrefabListNoPrefix[idx];
                }
                else
                {
                    //Debug.Log($"Pruning by {text.Path}");
                    string[] pruned = PrunePrefabListByPath(UnityDrawerStatics.PrefabList, text.Path);
                    pruned = AddNoneToStringArray(pruned);
                    string prefabRemoved = field.GetValue <string>().Replace("Prefabs/", "");
                    int    sel           = Math.Max(Array.IndexOf(pruned, prefabRemoved), 0);
                    int    idx           = EditorGUILayout.Popup(sel, pruned);
                    result = "Prefabs/" + pruned[idx];
                    //Debug.Log($"Result of prune is {result}");
                }
            }
            else if (text.Type == TextFieldType.Entity)
            {
                int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.EntityList, field.GetValue <string>()), 0);

                int idx = EditorGUILayout.Popup(sel, UnityDrawerStatics.EntityList);
                result = UnityDrawerStatics.EntityList[idx];
            }
            else if (text.Type == TextFieldType.Component)
            {
                int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.ComponentList, field.GetValue <string>()), 0);

                int idx = EditorGUILayout.Popup(sel, UnityDrawerStatics.ComponentList);
                result = UnityDrawerStatics.ComponentList[idx];
            }

            if (EditorGUI.EndChangeCheck())
            {
                field.SetValue(result);
            }

            EditorGUIUtility.labelWidth = width;

            GUILayout.EndHorizontal();
        }
Example #8
0
        public override void Draw(InspectorField field, GUIStyle style)
        {
            GUILayout.BeginHorizontal();

            float width = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 0;

            TextFieldAttribute text      = field.GetAttribute <TextFieldAttribute>();
            MultilineAttribute multiline = field.GetAttribute <MultilineAttribute>();
            TextAreaAttribute  area      = field.GetAttribute <TextAreaAttribute>();

            object value = GetValue(field);

            EditorGUI.BeginChangeCheck();
            GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive);

            string result = "";

            if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard))
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextField((string)value);
                }
            }
            else if (multiline != null || area != null || text.Type == TextFieldType.Area)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TextArea((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TextArea((string)value);
                }
            }
            else if (text.Type == TextFieldType.Password)
            {
                if (style != null)
                {
                    result = EditorGUILayout.PasswordField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.PasswordField((string)value);
                }
            }
            else if (text.Type == TextFieldType.Tag)
            {
                if (style != null)
                {
                    result = EditorGUILayout.TagField((string)value, style);
                }
                else
                {
                    result = EditorGUILayout.TagField((string)value);
                }
            }
            else if (text.Type == TextFieldType.File)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension);
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }
            else if (text.Type == TextFieldType.Folder)
            {
                if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
                {
                    result = EditorUtility.OpenFolderPanel(text.Title, "", "");
                }

                if (field.Mixed)
                {
                    GUILayout.Label("---");
                }
                else
                {
                    GUILayout.Label((string)value);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                field.SetValue(result);
            }

            EditorGUIUtility.labelWidth = width;

            GUILayout.EndHorizontal();
        }