Example #1
0
            protected override void DrawPropertyLayout(IPropertyValueEntry <TypeEntry> entry, GUIContent label)
            {
                var value        = entry.SmartValue;
                var valueChanged = false;
                var rect         = EditorGUILayout.GetControlRect();
                var toggleRect   = rect.SetWidth(20);

                rect.xMin += 20;

                // Init
                if (string.IsNullOrEmpty(value.NiceTypeName) && value.Type != null)
                {
                    value.NiceTypeName = value.Type.GetNiceName();
                }

                if (value.IsNew || value.IsCustom || value.Type == null)
                {
                    rect.xMax -= 78;
                }

                // Toggle
                GUIHelper.PushGUIEnabled(value.Type != null);
                valueChanged = value.Emit != (value.Emit = EditorGUI.Toggle(toggleRect, value.Emit));
                GUIHelper.PopGUIEnabled();

                // TextField
                rect.y += 2;
                GUI.SetNextControlName(entry.Property.Path);
                bool isEditing = GUI.GetNameOfFocusedControl() == entry.Property.Path || value.Type == null;

                GUIHelper.PushColor(isEditing ? Color.white : new Color(0, 0, 0, 0));
                var newName = EditorGUI.TextField(rect, value.TypeName, EditorStyles.textField);

                GUIHelper.PopColor();

                // TextField overlay
                if (!isEditing)
                {
                    GUI.Label(rect, value.NiceTypeName);
                }

                if (value.IsNew || value.IsCustom || value.Type == null)
                {
                    rect.xMin  = rect.xMax + 3;
                    rect.width = 75;
                }

                // Labels
                if (value.Type == null)
                {
                    EditorGUI.LabelField(rect, GUIHelper.TempContent("MISSING"), MissingLabelStyle);
                }
                else if (value.IsNew)
                {
                    EditorGUI.LabelField(rect, GUIHelper.TempContent("NEW"), NewLabelStyle);
                }
                else if (value.IsCustom)
                {
                    EditorGUI.LabelField(rect, GUIHelper.TempContent("MODIFIED"), ChangedLabelStyle);
                }

                // Set values
                if ((newName ?? "") != (value.TypeName ?? ""))
                {
                    value.TypeName     = newName;
                    value.IsCustom     = true;
                    value.Type         = TypeBinder.BindToType(value.TypeName);
                    value.NiceTypeName = value.Type == null ? value.TypeName : value.Type.GetNiceName();
                    valueChanged       = true;
                }

                if (valueChanged)
                {
                    value.IsCustom = true;
                    entry.Values.ForceMarkDirty();
                }
            }
Example #2
0
            protected override void DrawPropertyLayout(GUIContent label)
            {
                var entry        = this.ValueEntry;
                var value        = entry.SmartValue;
                var valueChanged = false;
                var rect         = EditorGUILayout.GetControlRect();
                var toggleRect   = rect.SetWidth(20);

                rect.xMin += 20;

                if (value.Type == null)
                {
                    this.isEditing = true;
                }

                bool wasEditing = this.isEditing;

                // Init
                if (string.IsNullOrEmpty(value.NiceTypeName) && value.Type != null)
                {
                    value.NiceTypeName = value.Type.GetNiceName();
                }

                // Toggle
                GUIHelper.PushGUIEnabled(value.Type != null);
                valueChanged = value.Emit != (value.Emit = EditorGUI.Toggle(toggleRect, value.Emit));
                GUIHelper.PopGUIEnabled();

                rect.y     += 2;
                rect.width -= 30;

                var textBoxRect = rect;

                if (value.IsNew || value.IsCustom || value.Type == null)
                {
                    textBoxRect.xMax -= 78;
                }

                // Labels
                //if (value.IsNew || value.IsCustom || value.Type == null)
                {
                    var lblRect = rect;

                    lblRect.xMin  = lblRect.xMax - 75;
                    lblRect.width = 75;

                    if (value.Type == null)
                    {
                        EditorGUI.LabelField(lblRect, GUIHelper.TempContent("MISSING"), MissingLabelStyle);
                    }
                    else if (value.IsCustom)
                    {
                        EditorGUI.LabelField(lblRect, GUIHelper.TempContent("MODIFIED"), ChangedLabelStyle);
                    }
                    else if (value.IsNew)
                    {
                        EditorGUI.LabelField(lblRect, GUIHelper.TempContent("NEW"), NewLabelStyle);
                    }
                    else
                    {
                        EditorGUI.LabelField(lblRect, GUIHelper.TempContent(""));
                    }
                }

                var newName = value.TypeName;

                if (this.isEditing)
                {
                    GUI.SetNextControlName(entry.Property.Path);

                    // TextField
                    newName = EditorGUI.TextField(textBoxRect, value.TypeName, EditorStyles.textField);

                    if (GUI.GetNameOfFocusedControl() == entry.Property.Path && (Event.current.Equals(Event.KeyboardEvent("return")) || Event.current.OnKeyUp(KeyCode.Return)))
                    {
                        this.isEditing = false;
                    }
                }
                else
                {
                    // TextField overlay
                    if (GUI.Button(textBoxRect, value.NiceTypeName, EditorStyles.label))
                    {
                        this.isEditing = true;
                    }

                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        EditorIcons.Pen.Draw(rect.AlignRight(30).AddX(30), 16);
                    }
                }

                //GUIHelper.PushColor(new Color(0.2f, 1, 0.2f, 1));
                if (this.isEditing && SirenixEditorGUI.IconButton(rect.AlignRight(30).AddX(30), EditorIcons.Checkmark))
                {
                    this.isEditing = false;
                }
                //GUIHelper.PopColor();

                // Set values
                if ((newName ?? "") != (value.TypeName ?? ""))
                {
                    value.TypeName     = newName;
                    value.IsCustom     = true;
                    value.Type         = TypeBinder.BindToType(value.TypeName);
                    value.NiceTypeName = value.Type == null ? value.TypeName : value.Type.GetNiceName();
                    valueChanged       = true;
                }

                if (wasEditing && !this.isEditing)
                {
                    if (value.Type != null)
                    {
                        value.TypeName = TypeBinder.BindToName(value.Type);
                    }

                    entry.Values.ForceMarkDirty();
                }

                if (valueChanged)
                {
                    value.IsCustom = true;
                    entry.Values.ForceMarkDirty();
                }
            }