Example #1
0
        /// <summary>
        /// Returns an icon that can be used for displaying a resource of the specified type.
        /// </summary>
        /// <param name="path">Path to the project library entry to display data for.</param>
        /// <param name="size">Size of the icon to retrieve, in pixels.</param>
        /// <returns>Icon to display for the specified entry.</returns>
        private static SpriteTexture GetIcon(string path, int size)
        {
            LibraryEntry entry = ProjectLibrary.GetEntry(path);

            if (entry.Type == LibraryEntryType.Directory)
            {
                return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Folder, size));
            }
            else
            {
                ResourceMeta meta = ProjectLibrary.GetMeta(path);
                switch (meta.ResType)
                {
                case ResourceType.Font:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Font, size));

                case ResourceType.Mesh:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Mesh, size));

                case ResourceType.Texture:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Texture, size));

                case ResourceType.PlainText:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PlainText, size));

                case ResourceType.ScriptCode:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.ScriptCode, size));

                case ResourceType.SpriteTexture:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.SpriteTexture, size));

                case ResourceType.Shader:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size));

                case ResourceType.ShaderInclude:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size));

                case ResourceType.Material:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Material, size));

                case ResourceType.Prefab:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Prefab, size));

                case ResourceType.GUISkin:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.GUISkin, size));

                case ResourceType.PhysicsMaterial:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PhysicsMaterial, size));

                case ResourceType.PhysicsMesh:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PhysicsMesh, size));

                case ResourceType.AudioClip:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.AudioClip, size));
                }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// (Re)creates all row GUI elements.
        /// </summary>
        internal protected void BuildGUI()
        {
            contentLayout.Clear();

            GUILayoutX externalTitleLayout = CreateGUI(contentLayout);

            if (localTitleLayout || (titleLayout != null && titleLayout == externalTitleLayout))
            {
                return;
            }

            if (externalTitleLayout != null)
            {
                localTitleLayout = false;
                titleLayout      = externalTitleLayout;
            }
            else
            {
                GUILayoutY buttonCenter = rowLayout.AddLayoutY();
                buttonCenter.AddFlexibleSpace();
                titleLayout = buttonCenter.AddLayoutX();
                buttonCenter.AddFlexibleSpace();

                localTitleLayout = true;
            }

            GUIContent cloneIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clone),
                                                  new LocEdString("Clone"));
            GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete),
                                                   new LocEdString("Delete"));
            GUIContent moveUp = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveUp),
                                               new LocEdString("Move up"));
            GUIContent moveDown = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.MoveDown),
                                                 new LocEdString("Move down"));

            GUIButton cloneBtn    = new GUIButton(cloneIcon, GUIOption.FixedWidth(30));
            GUIButton deleteBtn   = new GUIButton(deleteIcon, GUIOption.FixedWidth(30));
            GUIButton moveUpBtn   = new GUIButton(moveUp, GUIOption.FixedWidth(30));
            GUIButton moveDownBtn = new GUIButton(moveDown, GUIOption.FixedWidth(30));

            cloneBtn.OnClick    += () => parent.OnCloneButtonClicked(seqIndex);
            deleteBtn.OnClick   += () => parent.OnDeleteButtonClicked(seqIndex);
            moveUpBtn.OnClick   += () => parent.OnMoveUpButtonClicked(seqIndex);
            moveDownBtn.OnClick += () => parent.OnMoveDownButtonClicked(seqIndex);

            titleLayout.AddElement(cloneBtn);
            titleLayout.AddElement(deleteBtn);
            titleLayout.AddElement(moveUpBtn);
            titleLayout.AddElement(moveDownBtn);
        }
        /// <summary>
        /// (Re)creates all row GUI elements.
        /// </summary>
        internal protected void BuildGUI()
        {
            keyLayout.Clear();
            valueLayout.Clear();

            GUILayoutX externalTitleLayout = CreateKeyGUI(keyLayout);

            CreateValueGUI(valueLayout);
            if (localTitleLayout || (titleLayout != null && titleLayout == externalTitleLayout))
            {
                return;
            }

            if (externalTitleLayout != null)
            {
                localTitleLayout = false;
                titleLayout      = externalTitleLayout;
            }
            else
            {
                GUILayoutY buttonCenter = keyRowLayout.AddLayoutY();
                buttonCenter.AddFlexibleSpace();
                titleLayout = buttonCenter.AddLayoutX();
                buttonCenter.AddFlexibleSpace();

                localTitleLayout = true;
            }

            GUIContent cloneIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clone),
                                                  new LocEdString("Clone"));
            GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete),
                                                   new LocEdString("Delete"));
            GUIContent editIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Edit),
                                                 new LocEdString("Edit"));

            cloneBtn  = new GUIButton(cloneIcon, GUIOption.FixedWidth(30));
            deleteBtn = new GUIButton(deleteIcon, GUIOption.FixedWidth(30));
            editBtn   = new GUIButton(editIcon, GUIOption.FixedWidth(30));

            cloneBtn.OnClick  += () => parent.OnCloneButtonClicked(rowIdx);
            deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(rowIdx);
            editBtn.OnClick   += () => parent.OnEditButtonClicked(rowIdx);

            titleLayout.AddElement(cloneBtn);
            titleLayout.AddElement(deleteBtn);
            titleLayout.AddSpace(10);
            titleLayout.AddElement(editBtn);

            EditMode = editMode;
        }
        /// <summary>
        /// Returns an icon that can be used for displaying a resource of the specified type.
        /// </summary>
        /// <param name="entry">Project library entry of the resource to retrieve icon for.</param>
        /// <param name="size">Size of the icon to retrieve, in pixels.</param>
        /// <returns>Icon to display for the specified entry.</returns>
        private static SpriteTexture GetIcon(LibraryEntry entry, int size)
        {
            if (entry.Type == LibraryEntryType.Directory)
            {
                return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Folder, size));
            }
            else
            {
                FileEntry fileEntry = (FileEntry)entry;
                switch (fileEntry.ResType)
                {
                case ResourceType.Font:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Font, size));

                case ResourceType.Mesh:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Mesh, size));

                case ResourceType.Texture:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Texture, size));

                case ResourceType.PlainText:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PlainText, size));

                case ResourceType.ScriptCode:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.ScriptCode, size));

                case ResourceType.SpriteTexture:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.SpriteTexture, size));

                case ResourceType.Shader:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size));

                case ResourceType.ShaderInclude:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size));

                case ResourceType.Material:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Material, size));

                case ResourceType.Prefab:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Prefab, size));

                case ResourceType.GUISkin:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.GUISkin, size));
                }
            }

            return(null);
        }
        /// <summary>
        /// Registers a set of rows for all components in a <see cref="SceneObject"/>, as well as its transform and
        /// child objects.
        /// </summary>
        /// <param name="parent">Row element under which to create the new rows.</param>
        private void AddSceneObjectRows(Element parent)
        {
            string soName = "!" + parent.so.Name;

            Component[] components = parent.so.GetComponents();

            parent.children = new Element[components.Length + 2];

            SpriteTexture soIcon   = EditorBuiltin.GetEditorIcon(EditorIcon.SceneObject);
            SpriteTexture compIcon = EditorBuiltin.GetEditorIcon(EditorIcon.Component);

            // Add transform
            parent.children[0] = AddFoldoutRow(parent.childLayout, soIcon, "Transform", parent.so,
                                               null, parent.path + "/" + soName, ToggleTransformFoldout);

            // Add components
            for (int i = 0; i < components.Length; i++)
            {
                Component childComponent = components[i];
                Action <Element, bool> toggleCallback =
                    (toggleParent, expand) =>
                {
                    SerializableObject componentObject = new SerializableObject(childComponent.GetType(), null);
                    ToggleObjectFoldout(toggleParent, componentObject, expand);
                };

                string name = childComponent.GetType().Name;
                string path = parent.path + "/" + soName + "/:" + name;
                parent.children[i + 1] = AddFoldoutRow(parent.childLayout, compIcon, name, parent.so, childComponent, path,
                                                       toggleCallback);
            }

            // Add children
            if (parent.so.GetNumChildren() > 0)
            {
                parent.children[parent.children.Length - 1] = AddFoldoutRow(parent.childLayout, soIcon, "Children",
                                                                            parent.so, null, parent.path + "/" + soName, ToggleChildFoldout);
            }
        }
        /// <summary>
        /// Expands or collapses the set of rows displaying all <see cref="SceneObject"/> children of a
        /// <see cref="SceneObject"/>.
        /// </summary>
        /// <param name="parent">Parent row element whose children to expand/collapse.</param>
        /// <param name="expand">True to expand, false to collapse.</param>
        private void ToggleChildFoldout(Element parent, bool expand)
        {
            parent.childLayout.Clear();
            parent.children = null;

            parent.indentLayout.Active = expand;

            if (expand)
            {
                int numChildren = parent.so.GetNumChildren();

                parent.children = new Element[numChildren];

                for (int i = 0; i < numChildren; i++)
                {
                    SceneObject child = parent.so.GetChild(i);

                    SpriteTexture soIcon = EditorBuiltin.GetEditorIcon(EditorIcon.SceneObject);
                    parent.children[i] = AddFoldoutRow(parent.childLayout, soIcon, child.Name, child, null, parent.path,
                                                       ToggleSceneObjectFoldout);
                }
            }
        }
Example #7
0
            /// <inheritdoc/>
            public override void UpdateContents(int index, ConsoleEntryData data)
            {
                if (index != sSelectedElementIdx)
                {
                    if (index % 2 != 0)
                    {
                        background.Visible = true;
                        background.SetTint(BG_COLOR);
                    }
                    else
                    {
                        background.Visible = false;
                    }
                }
                else
                {
                    background.Visible = true;
                    background.SetTint(SELECTION_COLOR);
                }

                switch (data.type)
                {
                case DebugMessageType.Info:
                    icon.SetTexture(EditorBuiltin.GetLogIcon(LogIcon.Info, 32, false));
                    break;

                case DebugMessageType.Warning:
                case DebugMessageType.CompilerWarning:
                    icon.SetTexture(EditorBuiltin.GetLogIcon(LogIcon.Warning, 32, false));
                    break;

                case DebugMessageType.Error:
                case DebugMessageType.CompilerError:
                    icon.SetTexture(EditorBuiltin.GetLogIcon(LogIcon.Error, 32, false));
                    break;
                }

                messageLabel.SetContent(new LocEdString(data.message));

                string method = "";

                if (data.callstack != null && data.callstack.Length > 0)
                {
                    string filePath        = data.callstack[0].file;
                    bool   isFilePathValid = filePath.IndexOfAny(Path.GetInvalidPathChars()) == -1;

                    if (isFilePathValid)
                    {
                        file = Path.GetFileName(data.callstack[0].file);
                    }
                    else
                    {
                        file = "<unknown file>";
                    }

                    line = data.callstack[0].line;

                    if (string.IsNullOrEmpty(data.callstack[0].method))
                    {
                        method = "\tin " + file + ":" + line;
                    }
                    else
                    {
                        method = "\t" + data.callstack[0].method + " in " + file + ":" + line;
                    }
                }
                else
                {
                    file = "";
                    line = 0;
                }

                functionLabel.SetContent(new LocEdString(method));

                entryIdx = index;
            }
Example #8
0
 private static void DrawIcon(Light light)
 {
     Gizmos.DrawIcon(light.SceneObject.Position, EditorBuiltin.GetSceneViewIcon(SceneViewIcon.Light), false);
 }
Example #9
0
        /// <summary>
        /// Rebuilds the GUI object header if needed.
        /// </summary>
        /// <param name="layoutIndex">Index at which to insert the GUI elements.</param>
        protected void BuildGUI(int layoutIndex)
        {
            Action BuildEmptyGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                guiInternalTitleLayout.AddElement(new GUILabel(title));
                guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100)));

                if (!property.IsValueType)
                {
                    GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create),
                                                           new LocEdString("Create"));
                    guiCreateBtn          = new GUIButton(createIcon, GUIOption.FixedWidth(30));
                    guiCreateBtn.OnClick += OnCreateButtonClicked;
                    guiInternalTitleLayout.AddElement(guiCreateBtn);
                }
            };

            Action BuildFilledGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
                guiFoldout.Value           = isExpanded;
                guiFoldout.AcceptsKeyFocus = false;
                guiFoldout.OnToggled      += OnFoldoutToggled;
                guiInternalTitleLayout.AddElement(guiFoldout);

                if (!style.StyleFlags.HasFlag(InspectableFieldStyleFlags.NotNull))
                {
                    GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear),
                                                          new LocEdString("Clear"));
                    GUIButton clearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(20));
                    clearBtn.OnClick += OnClearButtonClicked;
                    guiInternalTitleLayout.AddElement(clearBtn);
                }

                if (isExpanded)
                {
                    SerializableObject  serializableObject = property.GetObject();
                    SerializableField[] fields             = serializableObject.Fields;

                    if (fields.Length > 0)
                    {
                        guiChildLayout = guiLayout.AddLayoutX();
                        guiChildLayout.AddSpace(IndentAmount);

                        GUIPanel   guiContentPanel  = guiChildLayout.AddPanel();
                        GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
                        guiIndentLayoutX.AddSpace(IndentAmount);
                        GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                        guiIndentLayoutY.AddSpace(IndentAmount);
                        GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
                        guiIndentLayoutY.AddSpace(IndentAmount);
                        guiIndentLayoutX.AddSpace(IndentAmount);
                        guiChildLayout.AddSpace(IndentAmount);

                        short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                        string bgPanelStyle    = depth % 2 == 0
                           ? EditorStylesInternal.InspectorContentBgAlternate
                           : EditorStylesInternal.InspectorContentBg;
                        GUIPanel   backgroundPanel    = guiContentPanel.AddPanel(backgroundDepth);
                        GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                        backgroundPanel.AddElement(inspectorContentBg);

                        int currentIndex = 0;
                        foreach (var field in fields)
                        {
                            if (!field.Flags.HasFlag(SerializableFieldAttributes.Inspectable))
                            {
                                continue;
                            }

                            string childPath = path + "/" + field.Name;

                            InspectableField inspectable = CreateInspectable(parent, field.Name, childPath,
                                                                             currentIndex, depth + 1, new InspectableFieldLayout(guiContentLayout), field.GetProperty(), InspectableFieldStyle.Create(field));

                            children.Add(inspectable);
                            currentIndex += inspectable.GetNumLayoutElements();
                        }
                    }
                }
                else
                {
                    guiChildLayout = null;
                }
            };

            if (state == State.None)
            {
                if (propertyValue != null)
                {
                    BuildFilledGUI();
                    state = State.Filled;
                }
                else
                {
                    BuildEmptyGUI();

                    state = State.Empty;
                }
            }
            else if (state == State.Empty)
            {
                if (propertyValue != null)
                {
                    guiInternalTitleLayout.Destroy();
                    guiCreateBtn = null;

                    BuildFilledGUI();
                    state = State.Filled;
                }
            }
            else if (state == State.Filled)
            {
                foreach (var child in children)
                {
                    child.Destroy();
                }

                children.Clear();
                guiInternalTitleLayout.Destroy();
                guiCreateBtn = null;

                if (guiChildLayout != null)
                {
                    guiChildLayout.Destroy();
                    guiChildLayout = null;
                }

                if (propertyValue == null)
                {
                    BuildEmptyGUI();
                    state = State.Empty;
                }
                else
                {
                    BuildFilledGUI();
                }
            }
        }
Example #10
0
        /// <summary>
        /// Returns an icon that can be used for displaying a resource of the specified type.
        /// </summary>
        /// <param name="path">Path to the project library entry to display data for.</param>
        /// <param name="size">Size of the icon to retrieve, in pixels.</param>
        /// <returns>Icon to display for the specified entry.</returns>
        private static SpriteTexture GetIcon(string path, int size)
        {
            LibraryEntry entry = ProjectLibrary.GetEntry(path);

            if (entry.Type == LibraryEntryType.Directory)
            {
                return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Folder, size));
            }
            else
            {
                ResourceMeta         meta  = ProjectLibrary.GetMeta(path);
                ProjectResourceIcons icons = meta.Icons;

                Texture icon;
                if (size <= 16)
                {
                    icon = icons.icon16;
                }
                else if (size <= 32)
                {
                    icon = icons.icon32;
                }
                else if (size <= 48)
                {
                    icon = icons.icon48;
                }
                else
                {
                    icon = icons.icon64;
                }

                if (icon != null)
                {
                    return(new SpriteTexture(icon));
                }

                switch (meta.ResType)
                {
                case ResourceType.Font:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Font, size));

                case ResourceType.Mesh:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Mesh, size));

                case ResourceType.Texture:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Texture, size));

                case ResourceType.PlainText:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PlainText, size));

                case ResourceType.ScriptCode:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.ScriptCode, size));

                case ResourceType.SpriteTexture:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.SpriteTexture, size));

                case ResourceType.Shader:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size));

                case ResourceType.ShaderInclude:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Shader, size));

                case ResourceType.Material:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Material, size));

                case ResourceType.Prefab:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.Prefab, size));

                case ResourceType.GUISkin:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.GUISkin, size));

                case ResourceType.PhysicsMaterial:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PhysicsMaterial, size));

                case ResourceType.PhysicsMesh:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.PhysicsMesh, size));

                case ResourceType.AudioClip:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.AudioClip, size));

                case ResourceType.AnimationClip:
                    return(EditorBuiltin.GetLibraryItemIcon(LibraryItemIcon.AnimationClip, size));
                }
            }

            return(null);
        }
Example #11
0
        private void OnInitialize()
        {
            mainLayout = GUI.AddLayoutY();

            GUIContent viewIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.View), 
                new LocEdString("View"));
            GUIContent moveIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Move), 
                new LocEdString("Move"));
            GUIContent rotateIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Rotate), 
                new LocEdString("Rotate"));
            GUIContent scaleIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Scale), 
                new LocEdString("Scale"));

            GUIContent localIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Local), 
                new LocEdString("Local"));
            GUIContent worldIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.World), 
                new LocEdString("World"));

            GUIContent pivotIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Pivot), 
                new LocEdString("Pivot"));
            GUIContent centerIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Center), 
                new LocEdString("Center"));

            GUIContent moveSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.MoveSnap), 
                new LocEdString("Move snap"));
            GUIContent rotateSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.RotateSnap), 
                new LocEdString("Rotate snap"));

            GUIToggleGroup handlesTG = new GUIToggleGroup();
            viewButton = new GUIToggle(viewIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            moveButton = new GUIToggle(moveIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            rotateButton = new GUIToggle(rotateIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            scaleButton = new GUIToggle(scaleIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));

            GUIToggleGroup coordModeTG = new GUIToggleGroup();
            localCoordButton = new GUIToggle(localIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75));
            worldCoordButton = new GUIToggle(worldIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75));

            GUIToggleGroup pivotModeTG = new GUIToggleGroup();
            pivotButton = new GUIToggle(pivotIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            centerButton = new GUIToggle(centerIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));

            moveSnapButton = new GUIToggle(moveSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            moveSnapInput = new GUIFloatField("", GUIOption.FlexibleWidth(35));

            rotateSnapButton = new GUIToggle(rotateSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            rotateSnapInput = new GUIFloatField("", GUIOption.FlexibleWidth(35));

            viewButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.View);
            moveButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Move);
            rotateButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Rotate);
            scaleButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Scale);

            localCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.Local);
            worldCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.World);

            pivotButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Pivot);
            centerButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Center);

            moveSnapButton.OnToggled += (bool active) => OnMoveSnapToggled(active);
            moveSnapInput.OnChanged += (float value) => OnMoveSnapValueChanged(value);

            rotateSnapButton.OnToggled += (bool active) => OnRotateSnapToggled(active);
            rotateSnapInput.OnChanged += (float value) => OnRotateSnapValueChanged(value);

            GUILayout handlesLayout = mainLayout.AddLayoutX();
            handlesLayout.AddElement(viewButton);
            handlesLayout.AddElement(moveButton);
            handlesLayout.AddElement(rotateButton);
            handlesLayout.AddElement(scaleButton);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(localCoordButton);
            handlesLayout.AddElement(worldCoordButton);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(pivotButton);
            handlesLayout.AddElement(centerButton);
            handlesLayout.AddFlexibleSpace();
            handlesLayout.AddElement(moveSnapButton);
            handlesLayout.AddElement(moveSnapInput);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(rotateSnapButton);
            handlesLayout.AddElement(rotateSnapInput);

            GUIPanel mainPanel = mainLayout.AddPanel();
            rtPanel = mainPanel.AddPanel();

            GUIPanel sceneAxesPanel = mainPanel.AddPanel(-1);
            sceneAxesGUI = new SceneAxesGUI(this, sceneAxesPanel, HandleAxesGUISize, HandleAxesGUISize, ProjectionType.Perspective);

            toggleProfilerOverlayKey = new VirtualButton(ToggleProfilerOverlayBinding);
            viewToolKey = new VirtualButton(ViewToolBinding);
            moveToolKey = new VirtualButton(MoveToolBinding);
            rotateToolKey = new VirtualButton(RotateToolBinding);
            scaleToolKey = new VirtualButton(ScaleToolBinding);
            duplicateKey = new VirtualButton(DuplicateBinding);
            deleteKey = new VirtualButton(DeleteBinding);
            frameKey = new VirtualButton(FrameBinding);

            UpdateRenderTexture(Width, Height - HeaderHeight);
            UpdateProfilerOverlay();
        }
Example #12
0
 private static void DrawIcon(AudioSource source)
 {
     Gizmos.DrawIcon(source.SceneObject.Position,
                     EditorBuiltin.GetSceneViewIcon(SceneViewIcon.AudioSource), false);
 }
Example #13
0
 private static void DrawIcon(AudioListener listener)
 {
     Gizmos.DrawIcon(listener.SceneObject.Position,
                     EditorBuiltin.GetSceneViewIcon(SceneViewIcon.AudioListener), false);
 }
Example #14
0
        private void OnInitialize()
        {
            GUILayoutY layout      = GUI.AddLayoutY();
            GUILayoutX titleLayout = layout.AddLayoutX();

            GUIContentImages infoImages = new GUIContentImages(
                EditorBuiltin.GetLogIcon(LogIcon.Info, 16, false),
                EditorBuiltin.GetLogIcon(LogIcon.Info, 16, true));

            GUIContentImages warningImages = new GUIContentImages(
                EditorBuiltin.GetLogIcon(LogIcon.Warning, 16, false),
                EditorBuiltin.GetLogIcon(LogIcon.Warning, 16, true));

            GUIContentImages errorImages = new GUIContentImages(
                EditorBuiltin.GetLogIcon(LogIcon.Error, 16, false),
                EditorBuiltin.GetLogIcon(LogIcon.Error, 16, true));

            GUIToggle infoBtn    = new GUIToggle(new GUIContent(infoImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT));
            GUIToggle warningBtn = new GUIToggle(new GUIContent(warningImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT));
            GUIToggle errorBtn   = new GUIToggle(new GUIContent(errorImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT));

            GUIToggle detailsBtn     = new GUIToggle(new LocEdString("Show details"), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT));
            GUIButton clearBtn       = new GUIButton(new LocEdString("Clear"), GUIOption.FixedHeight(TITLE_HEIGHT));
            GUIToggle clearOnPlayBtn = new GUIToggle(new LocEdString("Clear on play"), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT));

            titleLayout.AddElement(infoBtn);
            titleLayout.AddElement(warningBtn);
            titleLayout.AddElement(errorBtn);
            titleLayout.AddFlexibleSpace();
            titleLayout.AddElement(detailsBtn);
            titleLayout.AddElement(clearBtn);
            titleLayout.AddElement(clearOnPlayBtn);

            infoBtn.Value    = filter.HasFlag(EntryFilter.Info);
            warningBtn.Value = filter.HasFlag(EntryFilter.Warning);
            errorBtn.Value   = filter.HasFlag(EntryFilter.Error);

            clearOnPlayBtn.Value = EditorSettings.GetBool(CLEAR_ON_PLAY_KEY, true);

            infoBtn.OnToggled += x =>
            {
                if (x)
                {
                    SetFilter(filter | EntryFilter.Info);
                }
                else
                {
                    SetFilter(filter & ~EntryFilter.Info);
                }
            };

            warningBtn.OnToggled += x =>
            {
                if (x)
                {
                    SetFilter(filter | EntryFilter.Warning);
                }
                else
                {
                    SetFilter(filter & ~EntryFilter.Warning);
                }
            };

            errorBtn.OnToggled += x =>
            {
                if (x)
                {
                    SetFilter(filter | EntryFilter.Error);
                }
                else
                {
                    SetFilter(filter & ~EntryFilter.Error);
                }
            };

            detailsBtn.OnToggled     += ToggleDetailsPanel;
            clearBtn.OnClick         += ClearLog;
            clearOnPlayBtn.OnToggled += ToggleClearOnPlay;

            GUILayoutX mainLayout = layout.AddLayoutX();

            listView = new GUIListView <ConsoleGUIEntry, ConsoleEntryData>(Width, ListHeight, ENTRY_HEIGHT, mainLayout);

            detailsSeparator = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedWidth(SEPARATOR_WIDTH));
            detailsArea      = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow);
            mainLayout.AddElement(detailsSeparator);
            mainLayout.AddElement(detailsArea);
            detailsSeparator.Active = false;
            detailsArea.Active      = false;

            detailsSeparator.SetTint(SEPARATOR_COLOR);

            Refresh();
            Debug.OnAdded += OnEntryAdded;
        }
 private static void DrawIcon(LightProbeVolume volume)
 {
     Gizmos.DrawIcon(volume.SceneObject.Position,
                     EditorBuiltin.GetSceneViewIcon(SceneViewIcon.LightProbes), false);
 }
Example #16
0
 private static void DrawIcon(Camera camera)
 {
     Gizmos.DrawIcon(camera.SceneObject.Position, EditorBuiltin.GetSceneViewIcon(SceneViewIcon.Camera), false);
 }
 private static void DrawIcon(ParticleSystem component)
 {
     Gizmos.DrawIcon(component.SceneObject.Position, EditorBuiltin.GetSceneViewIcon(SceneViewIcon.ParticleSystem), false);
 }
Example #18
0
        private void OnInitialize()
        {
            mainLayout = GUI.AddLayoutY();

            GUIContent viewIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.View),
                                                 new LocEdString("View"));
            GUIContent moveIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Move),
                                                 new LocEdString("Move"));
            GUIContent rotateIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Rotate),
                                                   new LocEdString("Rotate"));
            GUIContent scaleIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Scale),
                                                  new LocEdString("Scale"));

            GUIContent localIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Local),
                                                  new LocEdString("Local"));
            GUIContent worldIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.World),
                                                  new LocEdString("World"));

            GUIContent pivotIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Pivot),
                                                  new LocEdString("Pivot"));
            GUIContent centerIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Center),
                                                   new LocEdString("Center"));

            GUIContent moveSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.MoveSnap),
                                                     new LocEdString("Move snap"));
            GUIContent rotateSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.RotateSnap),
                                                       new LocEdString("Rotate snap"));

            GUIToggleGroup handlesTG = new GUIToggleGroup();

            viewButton   = new GUIToggle(viewIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            moveButton   = new GUIToggle(moveIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            rotateButton = new GUIToggle(rotateIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            scaleButton  = new GUIToggle(scaleIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));

            GUIToggleGroup coordModeTG = new GUIToggleGroup();

            localCoordButton = new GUIToggle(localIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75));
            worldCoordButton = new GUIToggle(worldIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75));

            GUIToggleGroup pivotModeTG = new GUIToggleGroup();

            pivotButton  = new GUIToggle(pivotIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            centerButton = new GUIToggle(centerIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));

            moveSnapButton = new GUIToggle(moveSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            moveSnapInput  = new GUIFloatField("", GUIOption.FlexibleWidth(35));

            rotateSnapButton = new GUIToggle(rotateSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            rotateSnapInput  = new GUIFloatField("", GUIOption.FlexibleWidth(35));

            GUIContent cameraOptionsIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.SceneCameraOptions), new LocEdString("Camera options"));

            cameraOptionsButton = new GUIButton(cameraOptionsIcon);

            viewButton.OnClick   += () => OnSceneToolButtonClicked(SceneViewTool.View);
            moveButton.OnClick   += () => OnSceneToolButtonClicked(SceneViewTool.Move);
            rotateButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Rotate);
            scaleButton.OnClick  += () => OnSceneToolButtonClicked(SceneViewTool.Scale);

            localCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.Local);
            worldCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.World);

            pivotButton.OnClick  += () => OnPivotModeButtonClicked(HandlePivotMode.Pivot);
            centerButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Center);

            moveSnapButton.OnToggled += (bool active) => OnMoveSnapToggled(active);
            moveSnapInput.OnChanged  += (float value) => OnMoveSnapValueChanged(value);

            rotateSnapButton.OnToggled += (bool active) => OnRotateSnapToggled(active);
            rotateSnapInput.OnChanged  += (float value) => OnRotateSnapValueChanged(value);

            cameraOptionsButton.OnClick += () => OnCameraOptionsClicked();

            GUILayout handlesLayout = mainLayout.AddLayoutX();

            handlesLayout.AddElement(viewButton);
            handlesLayout.AddElement(moveButton);
            handlesLayout.AddElement(rotateButton);
            handlesLayout.AddElement(scaleButton);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(localCoordButton);
            handlesLayout.AddElement(worldCoordButton);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(pivotButton);
            handlesLayout.AddElement(centerButton);
            handlesLayout.AddFlexibleSpace();
            handlesLayout.AddElement(moveSnapButton);
            handlesLayout.AddElement(moveSnapInput);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(rotateSnapButton);
            handlesLayout.AddElement(rotateSnapInput);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(cameraOptionsButton);
            handlesLayout.SetHeight(viewButton.Bounds.height);

            GUIPanel mainPanel = mainLayout.AddPanel();

            rtPanel = mainPanel.AddPanel();

            // Loading progress
            loadLabel       = new GUILabel(new LocEdString("Loading scene..."));
            loadProgressBar = new GUIProgressBar("", GUIOption.FixedWidth(200));

            progressLayout = mainPanel.AddLayoutY();
            progressLayout.AddFlexibleSpace();
            GUILayout loadLabelLayout = progressLayout.AddLayoutX();

            loadLabelLayout.AddFlexibleSpace();
            loadLabelLayout.AddElement(loadLabel);
            loadLabelLayout.AddFlexibleSpace();

            GUILayout progressBarLayout = progressLayout.AddLayoutX();

            progressBarLayout.AddFlexibleSpace();
            progressBarLayout.AddElement(loadProgressBar);
            progressBarLayout.AddFlexibleSpace();
            progressLayout.AddFlexibleSpace();

            progressLayout.Active = false;

            selectionPanel = mainPanel.AddPanel(-1);

            sceneAxesPanel = mainPanel.AddPanel(-1);
            sceneAxesGUI   = new SceneAxesGUI(this, sceneAxesPanel, HandleAxesGUISize, HandleAxesGUISize, ProjectionType.Perspective);

            focusCatcher = new GUIButton("", EditorStyles.Blank);
            focusCatcher.OnFocusGained += () => hasContentFocus = true;
            focusCatcher.OnFocusLost   += () => hasContentFocus = false;

            GUIPanel focusPanel = GUI.AddPanel(-2);

            focusPanel.AddElement(focusCatcher);

            viewToolKey   = new VirtualButton(ViewToolBinding);
            moveToolKey   = new VirtualButton(MoveToolBinding);
            rotateToolKey = new VirtualButton(RotateToolBinding);
            scaleToolKey  = new VirtualButton(ScaleToolBinding);
            frameKey      = new VirtualButton(FrameBinding);

            UpdateRenderTexture(Width, Height - HeaderHeight);
            UpdateLoadingProgress();
        }
Example #19
0
 private static void DrawIcon(Decal decal)
 {
     Gizmos.DrawIcon(decal.SceneObject.Position,
                     EditorBuiltin.GetSceneViewIcon(SceneViewIcon.Decal), false);
 }
Example #20
0
        /// <summary>
        /// Rebuilds the GUI list header if needed.
        /// </summary>
        protected void UpdateHeaderGUI()
        {
            Action BuildEmptyGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                guiInternalTitleLayout.AddElement(new GUILabel(title));
                guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100)));

                GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create),
                                                       new LocEdString("Create"));
                GUIButton createBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30));
                createBtn.OnClick += OnCreateButtonClicked;
                guiInternalTitleLayout.AddElement(createBtn);
            };

            Action BuildFilledGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
                guiFoldout.Value      = isExpanded;
                guiFoldout.OnToggled += ToggleFoldout;
                guiSizeField          = new GUIIntField("", GUIOption.FixedWidth(50));
                guiSizeField.SetRange(0, int.MaxValue);

                GUIContent resizeIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Resize),
                                                       new LocEdString("Resize"));
                GUIButton guiResizeBtn = new GUIButton(resizeIcon, GUIOption.FixedWidth(30));
                guiResizeBtn.OnClick += OnResizeButtonClicked;

                GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear),
                                                      new LocEdString("Clear"));
                GUIButton guiClearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(30));
                guiClearBtn.OnClick += OnClearButtonClicked;

                guiInternalTitleLayout.AddElement(guiFoldout);
                guiInternalTitleLayout.AddElement(guiSizeField);
                guiInternalTitleLayout.AddElement(guiResizeBtn);
                guiInternalTitleLayout.AddElement(guiClearBtn);

                guiSizeField.Value = GetNumRows();

                guiChildLayout = guiLayout.AddLayoutX();
                guiChildLayout.AddSpace(IndentAmount);
                guiChildLayout.Active = isExpanded;

                GUIPanel   guiContentPanel  = guiChildLayout.AddPanel();
                GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
                guiIndentLayoutX.AddSpace(IndentAmount);
                GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                guiContentLayout = guiIndentLayoutY.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                guiIndentLayoutX.AddSpace(IndentAmount);
                guiChildLayout.AddSpace(IndentAmount);

                short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                string bgPanelStyle    = depth % 2 == 0
                    ? EditorStyles.InspectorContentBgAlternate
                    : EditorStyles.InspectorContentBg;

                GUIPanel   backgroundPanel    = guiContentPanel.AddPanel(backgroundDepth);
                GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                backgroundPanel.AddElement(inspectorContentBg);
            };

            if (state == State.None)
            {
                if (!IsNull())
                {
                    BuildFilledGUI();
                    state = State.Filled;
                }
                else
                {
                    BuildEmptyGUI();

                    state = State.Empty;
                }
            }
            else if (state == State.Empty)
            {
                if (!IsNull())
                {
                    guiInternalTitleLayout.Destroy();
                    BuildFilledGUI();
                    state = State.Filled;
                }
            }
            else if (state == State.Filled)
            {
                if (IsNull())
                {
                    guiInternalTitleLayout.Destroy();
                    guiChildLayout.Destroy();
                    BuildEmptyGUI();

                    state = State.Empty;
                }
            }
        }
 private static void DrawIcon(ReflectionProbe reflProbe)
 {
     Gizmos.DrawIcon(reflProbe.SceneObject.Position,
                     EditorBuiltin.GetSceneViewIcon(SceneViewIcon.ReflectionProbe), false);
 }
Example #22
0
        /// <summary>
        /// Sets a scene object whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
        /// </summary>
        /// <param name="so">Scene object to inspect.</param>
        private void SetObjectToInspect(SceneObject so)
        {
            if (so == null)
            {
                return;
            }

            currentType = InspectorType.SceneObject;
            activeSO    = so;

            inspectorScrollArea = new GUIScrollArea();
            scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture);
            scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR);
            scrollAreaHighlight.Active = false;

            GUI.AddElement(inspectorScrollArea);
            GUIPanel inspectorPanel = inspectorScrollArea.Layout.AddPanel();

            inspectorLayout = inspectorPanel.AddLayoutY();
            highlightPanel  = inspectorPanel.AddPanel(-1);
            highlightPanel.AddElement(scrollAreaHighlight);

            // SceneObject fields
            CreateSceneObjectFields();
            RefreshSceneObjectFields(true);

            // Components
            Component[] allComponents = so.GetComponents();
            for (int i = 0; i < allComponents.Length; i++)
            {
                inspectorLayout.AddSpace(COMPONENT_SPACING);

                InspectorComponent data = new InspectorComponent();
                data.instanceId = allComponents[i].InstanceId;
                data.folded     = false;

                data.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout);
                data.foldout.AcceptsKeyFocus = false;

                SpriteTexture xBtnIcon = EditorBuiltin.GetEditorIcon(EditorIcon.X);
                data.removeBtn = new GUIButton(new GUIContent(xBtnIcon), GUIOption.FixedWidth(30));

                data.title = inspectorLayout.AddLayoutX();
                data.title.AddElement(data.foldout);
                data.title.AddElement(data.removeBtn);
                data.panel = inspectorLayout.AddPanel();

                var persistentProperties = persistentData.GetProperties(allComponents[i].InstanceId);

                data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType());
                data.inspector.Initialize(data.panel, allComponents[i], persistentProperties);

                bool isExpanded = data.inspector.Persistent.GetBool(data.instanceId + "_Expanded", true);
                data.foldout.Value = isExpanded;

                if (!isExpanded)
                {
                    data.inspector.SetVisible(false);
                }

                Type curComponentType = allComponents[i].GetType();
                data.foldout.OnToggled += (bool expanded) => OnComponentFoldoutToggled(data, expanded);
                data.removeBtn.OnClick += () => OnComponentRemoveClicked(curComponentType);

                inspectorComponents.Add(data);
            }

            inspectorLayout.AddFlexibleSpace();

            UpdateDropAreas();
        }
Example #23
0
        private void RebuildGUI()
        {
            GUI.Clear();
            guiCurveEditor  = null;
            guiFieldDisplay = null;

            if (selectedSO == null)
            {
                GUILabel warningLbl = new GUILabel(new LocEdString("Select an object to animate in the Hierarchy or Scene windows."));

                GUILayoutY vertLayout = GUI.AddLayoutY();
                vertLayout.AddFlexibleSpace();
                GUILayoutX horzLayout = vertLayout.AddLayoutX();
                vertLayout.AddFlexibleSpace();

                horzLayout.AddFlexibleSpace();
                horzLayout.AddElement(warningLbl);
                horzLayout.AddFlexibleSpace();

                return;
            }

            // Top button row
            GUIContent playIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Play),
                                                 new LocEdString("Play"));
            GUIContent recordIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Record),
                                                   new LocEdString("Record"));

            GUIContent prevFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameBack),
                                                      new LocEdString("Previous frame"));
            GUIContent nextFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameForward),
                                                      new LocEdString("Next frame"));

            GUIContent addKeyframeIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddKeyframe),
                                                        new LocEdString("Add keyframe"));
            GUIContent addEventIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddEvent),
                                                     new LocEdString("Add event"));

            GUIContent optionsIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Options),
                                                    new LocEdString("Options"));

            playButton   = new GUIButton(playIcon);
            recordButton = new GUIButton(recordIcon);

            prevFrameButton = new GUIButton(prevFrameIcon);
            frameInputField = new GUIIntField();
            nextFrameButton = new GUIButton(nextFrameIcon);

            addKeyframeButton = new GUIButton(addKeyframeIcon);
            addEventButton    = new GUIButton(addEventIcon);

            optionsButton = new GUIButton(optionsIcon);

            playButton.OnClick += () =>
            {
                // TODO
                // - Record current state of the scene object hierarchy
                // - Evaluate all curves manually and update them
                // - On end, restore original values of the scene object hierarchy
            };

            recordButton.OnClick += () =>
            {
                // TODO
                // - Every frame read back current values of all the current curve's properties and assign it to the current frame
            };

            prevFrameButton.OnClick += () =>
            {
                SetCurrentFrame(currentFrameIdx - 1);
            };

            frameInputField.OnChanged += SetCurrentFrame;

            nextFrameButton.OnClick += () =>
            {
                SetCurrentFrame(currentFrameIdx + 1);
            };

            addKeyframeButton.OnClick += () =>
            {
                guiCurveEditor.AddKeyFrameAtMarker();
            };

            addEventButton.OnClick += () =>
            {
                guiCurveEditor.AddEventAtMarker();
            };

            optionsButton.OnClick += () =>
            {
                Vector2I         openPosition = ScreenToWindowPos(Input.PointerPosition);
                AnimationOptions dropDown     = DropDownWindow.Open <AnimationOptions>(this, openPosition);
                dropDown.Initialize(this);
            };

            // Property buttons
            addPropertyBtn = new GUIButton(new LocEdString("Add property"));
            delPropertyBtn = new GUIButton(new LocEdString("Delete selected"));

            addPropertyBtn.OnClick += () =>
            {
                Action openPropertyWindow = () =>
                {
                    Vector2I             windowPos      = ScreenToWindowPos(Input.PointerPosition);
                    FieldSelectionWindow fieldSelection = DropDownWindow.Open <FieldSelectionWindow>(this, windowPos);
                    fieldSelection.OnFieldSelected += OnFieldAdded;
                };

                if (clipInfo.clip == null)
                {
                    LocEdString title   = new LocEdString("Warning");
                    LocEdString message =
                        new LocEdString("Selected object doesn't have an animation clip assigned. Would you like to create" +
                                        " a new animation clip?");

                    DialogBox.Open(title, message, DialogBox.Type.YesNoCancel, type =>
                    {
                        if (type == DialogBox.ResultType.Yes)
                        {
                            string clipSavePath;
                            if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath))
                            {
                                clipSavePath = Path.ChangeExtension(clipSavePath, ".asset");

                                AnimationClip newClip = new AnimationClip();

                                ProjectLibrary.Create(newClip, clipSavePath);
                                LoadAnimClip(newClip);

                                Animation animation = selectedSO.GetComponent <Animation>();
                                if (animation == null)
                                {
                                    animation = selectedSO.AddComponent <Animation>();
                                }

                                animation.DefaultClip = newClip;
                                EditorApplication.SetSceneDirty();

                                openPropertyWindow();
                            }
                        }
                    });
                }
                else
                {
                    if (clipInfo.isImported)
                    {
                        LocEdString title   = new LocEdString("Warning");
                        LocEdString message =
                            new LocEdString("You cannot add/edit/remove curves from animation clips that" +
                                            " are imported from an external file.");

                        DialogBox.Open(title, message, DialogBox.Type.OK);
                    }
                    else
                    {
                        openPropertyWindow();
                    }
                }
            };

            delPropertyBtn.OnClick += () =>
            {
                if (clipInfo.clip == null)
                {
                    return;
                }

                if (clipInfo.isImported)
                {
                    LocEdString title   = new LocEdString("Warning");
                    LocEdString message =
                        new LocEdString("You cannot add/edit/remove curves from animation clips that" +
                                        " are imported from an external file.");

                    DialogBox.Open(title, message, DialogBox.Type.OK);
                }
                else
                {
                    LocEdString title   = new LocEdString("Warning");
                    LocEdString message = new LocEdString("Are you sure you want to remove all selected fields?");

                    DialogBox.Open(title, message, DialogBox.Type.YesNo, x =>
                    {
                        if (x == DialogBox.ResultType.Yes)
                        {
                            RemoveSelectedFields();
                        }
                    });
                }
            };

            GUIPanel mainPanel       = GUI.AddPanel();
            GUIPanel backgroundPanel = GUI.AddPanel(1);

            GUILayout mainLayout = mainPanel.AddLayoutY();

            buttonLayout = mainLayout.AddLayoutX();
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(playButton);
            buttonLayout.AddElement(recordButton);
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(prevFrameButton);
            buttonLayout.AddElement(frameInputField);
            buttonLayout.AddElement(nextFrameButton);
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(addKeyframeButton);
            buttonLayout.AddElement(addEventButton);
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(optionsButton);
            buttonLayout.AddFlexibleSpace();

            buttonLayoutHeight = playButton.Bounds.height;

            GUITexture buttonBackground = new GUITexture(null, EditorStyles.HeaderBackground);

            buttonBackground.Bounds = new Rect2I(0, 0, Width, buttonLayoutHeight);
            backgroundPanel.AddElement(buttonBackground);

            GUILayout contentLayout      = mainLayout.AddLayoutX();
            GUILayout fieldDisplayLayout = contentLayout.AddLayoutY(GUIOption.FixedWidth(FIELD_DISPLAY_WIDTH));

            guiFieldDisplay = new GUIAnimFieldDisplay(fieldDisplayLayout, FIELD_DISPLAY_WIDTH,
                                                      Height - buttonLayoutHeight * 2, selectedSO);
            guiFieldDisplay.OnEntrySelected += OnFieldSelected;

            GUILayout bottomButtonLayout = fieldDisplayLayout.AddLayoutX();

            bottomButtonLayout.AddElement(addPropertyBtn);
            bottomButtonLayout.AddElement(delPropertyBtn);

            horzScrollBar = new GUIResizeableScrollBarH();
            horzScrollBar.OnScrollOrResize += OnHorzScrollOrResize;

            vertScrollBar = new GUIResizeableScrollBarV();
            vertScrollBar.OnScrollOrResize += OnVertScrollOrResize;

            GUITexture separator = new GUITexture(null, EditorStyles.Separator, GUIOption.FixedWidth(3));

            contentLayout.AddElement(separator);

            GUILayout curveLayout         = contentLayout.AddLayoutY();
            GUILayout curveLayoutHorz     = curveLayout.AddLayoutX();
            GUILayout horzScrollBarLayout = curveLayout.AddLayoutX();

            horzScrollBarLayout.AddElement(horzScrollBar);
            horzScrollBarLayout.AddFlexibleSpace();

            editorPanel = curveLayoutHorz.AddPanel();
            curveLayoutHorz.AddElement(vertScrollBar);
            curveLayoutHorz.AddFlexibleSpace();

            scrollBarHeight = horzScrollBar.Bounds.height;
            scrollBarWidth  = vertScrollBar.Bounds.width;

            Vector2I curveEditorSize = GetCurveEditorSize();

            guiCurveEditor = new GUICurveEditor(this, editorPanel, curveEditorSize.x, curveEditorSize.y);
            guiCurveEditor.OnFrameSelected += OnFrameSelected;
            guiCurveEditor.OnEventAdded    += OnEventsChanged;
            guiCurveEditor.OnEventModified += EditorApplication.SetProjectDirty;
            guiCurveEditor.OnEventDeleted  += OnEventsChanged;
            guiCurveEditor.OnCurveModified += EditorApplication.SetProjectDirty;
            guiCurveEditor.Redraw();

            horzScrollBar.SetWidth(curveEditorSize.x);
            vertScrollBar.SetHeight(curveEditorSize.y);

            UpdateScrollBarSize();
        }