Example #1
0
        private void DrawTopBar()
        {
            Rect rect = SirenixEditorGUI.BeginHorizontalToolbar();

            {
                var iconRect = rect.AlignLeft(SerializationInfoMenuItem.IconSize).AlignMiddle(SerializationInfoMenuItem.IconSize);
                iconRect.x += SerializationInfoMenuItem.IconSpacing * 2;
                GUI.color   = (this.backendFlags & SerializationBackendFlags.Odin) != 0 ? Color.white : new Color(1f, 1f, 1f, 0.2f);
                GUI.DrawTexture(iconRect.Padding(2), EditorIcons.OdinInspectorLogo, ScaleMode.ScaleToFit);
                iconRect.x += SerializationInfoMenuItem.IconSize + SerializationInfoMenuItem.IconSpacing * 2;
                GUI.color   = (this.backendFlags & SerializationBackendFlags.Unity) != 0 ? Color.white : new Color(1f, 1f, 1f, 0.2f);
                GUI.DrawTexture(iconRect.Padding(2), EditorIcons.UnityLogo, ScaleMode.ScaleToFit);
                GUI.color = Color.white;

                var typeName = "   " + (this.targetType == null ? "Select Type" : this.targetType.GetNiceName().SplitPascalCase()) + "   ";
                GUILayout.Space(iconRect.xMax + 3);
                bool selectB = SirenixEditorGUI.ToolbarButton(new GUIContent(typeName));
                GUILayout.FlexibleSpace();
                bool selectA = SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleDown);

                if (selectA || selectB)
                {
                    var btnRect = GUIHelper.GetCurrentLayoutRect().HorizontalPadding(20).AlignTop(20);
                    btnRect = btnRect.AlignRight(400);
                    var source = AssemblyUtilities.GetTypes(AssemblyTypeFlags.CustomTypes)
                                 .Where(x => !x.IsAbstract && x.IsClass && x.InheritsFrom <UnityEngine.Object>())
                                 .Where(x => !x.Assembly.FullName.StartsWith("Sirenix"))
                                 .OrderBy(x => x.Assembly.GetAssemblyTypeFlag())
                                 .OrderBy(x => x.Assembly.GetAssemblyTypeFlag())
                                 .ThenBy(x => x.Namespace)
                                 .ThenByDescending(x => x.Name);

                    var p = new TypeSelector(source, false);

                    p.SelectionChanged += (types) =>
                    {
                        var t = types.FirstOrDefault();
                        if (t != null)
                        {
                            this.targetType  = t;
                            this.odinContext = this.targetType.IsDefined <ShowOdinSerializedPropertiesInInspectorAttribute>(true);
                            this.CreateMenuTree(true);
                        }
                    };

                    p.SetSelection(this.targetType);
                    p.ShowInPopup(300);
                }
            }
            SirenixEditorGUI.EndHorizontalToolbar();
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GUILayout.Space(15);

            if (GUILayout.Button("Set group type"))
            {
                var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes())
                            .Where(t => typeof(ScriptableObject).IsAssignableFrom(t));

                var selectedTypes = new List <Type>();
                var selector      = new TypeSelector(types, false);
                selector.SetSelection(selectedTypes);
                selector.SelectionConfirmed += selection => source.SetGroupType(selection.FirstOrDefault());
                selector.ShowInPopup();
            }

            if (GUILayout.Button("Verify group"))
            {
                source.VerifyGroup();
            }
        }
Example #3
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
        {
            Context context;

            if (entry.Context.Get(this, "context", out context))
            {
                context.UniqueControlName = Guid.NewGuid().ToString();
            }

            if (!context.IsValid)
            {
                GUIHelper.PushColor(Color.red);
            }

            GUI.SetNextControlName(context.UniqueControlName);

            Rect rect = EditorGUILayout.GetControlRect();

            if (label != null)
            {
                rect = EditorGUI.PrefixLabel(rect, label);
            }

            Rect fieldRect    = rect;
            Rect dropdownRect = rect.AlignRight(18);

            // Dropdown button.
            EditorGUIUtility.AddCursorRect(dropdownRect, MouseCursor.Arrow);
            if (GUI.Button(dropdownRect, GUIContent.none, GUIStyle.none))
            {
                TypeSelector selector = new TypeSelector(AssemblyTypeFlags.All, false);

                selector.SelectionConfirmed += t =>
                {
                    var type = t.FirstOrDefault();

                    entry.Property.Tree.DelayAction(() =>
                    {
                        entry.WeakSmartValue = type;
                        context.IsValid      = true;
                        entry.ApplyChanges();
                    });
                };

                selector.SetSelection(entry.SmartValue);
                selector.ShowInPopup(rect, 350);
            }

            // Reset type name.
            if (Event.current.type == EventType.Layout)
            {
                context.TypeNameTemp = entry.SmartValue != null?Binder.BindToName(entry.SmartValue) : null;
            }

            EditorGUI.BeginChangeCheck();
            context.TypeNameTemp = SirenixEditorFields.DelayedTextField(fieldRect, context.TypeNameTemp);

            // Draw dropdown button.
            EditorIcons.TriangleDown.Draw(dropdownRect);

            if (!context.IsValid)
            {
                GUIHelper.PopColor();
            }

            bool isFocused = GUI.GetNameOfFocusedControl() == context.UniqueControlName;
            bool defocused = false;

            if (isFocused != context.WasFocusedControl)
            {
                defocused = !isFocused;
                context.WasFocusedControl = isFocused;
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (string.IsNullOrEmpty(context.TypeNameTemp.Trim()))
                {
                    // String is empty
                    entry.SmartValue = null;
                    context.IsValid  = true;
                }
                else
                {
                    Type type = Binder.BindToType(context.TypeNameTemp);

                    if (type == null)
                    {
                        type = AssemblyUtilities.GetTypeByCachedFullName(context.TypeNameTemp);
                    }

                    if (type == null)
                    {
                        context.IsValid = false;
                    }
                    else
                    {
                        // Use WeakSmartValue in case of a different Type-derived instance showing up somehow, so we don't get cast errors
                        entry.WeakSmartValue = type;
                        context.IsValid      = true;
                    }
                }
            }

            if (defocused)
            {
                // Ensure we show the full type name when the control is defocused
                context.TypeNameTemp = entry.SmartValue == null ? "" : Binder.BindToName(entry.SmartValue);
                context.IsValid      = true;
            }
        }