Пример #1
0
        /// <summary>
        /// Creates GUI elements required for displaying <see cref="SceneObject"/> fields like name, prefab data and 
        /// transform (position, rotation, scale). Assumes that necessary inspector scroll area layout has already been 
        /// created.
        /// </summary>
        private void CreateSceneObjectFields()
        {
            GUIPanel sceneObjectPanel = inspectorLayout.AddPanel();
            sceneObjectPanel.SetHeight(GetTitleBounds().height);

            GUILayoutY sceneObjectLayout = sceneObjectPanel.AddLayoutY();
            sceneObjectLayout.SetPosition(PADDING, PADDING);

            GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1);

            GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX();
            soActiveToggle = new GUIToggle("");
            soActiveToggle.OnToggled += OnSceneObjectActiveStateToggled;
            GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50));
            soNameInput = new GUITextBox(false, GUIOption.FlexibleWidth(180));
            soNameInput.Text = activeSO.Name;
            soNameInput.OnChanged += OnSceneObjectRename;
            soNameInput.OnConfirmed += OnModifyConfirm;
            soNameInput.OnFocusLost += OnModifyConfirm;

            nameLayout.AddElement(soActiveToggle);
            nameLayout.AddSpace(3);
            nameLayout.AddElement(nameLbl);
            nameLayout.AddElement(soNameInput);
            nameLayout.AddFlexibleSpace();

            soPrefabLayout = sceneObjectLayout.AddLayoutX();

            GUILayoutX positionLayout = sceneObjectLayout.AddLayoutX();
            GUILabel positionLbl = new GUILabel(new LocEdString("Position"), GUIOption.FixedWidth(50));
            soPosX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
            soPosY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
            soPosZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));

            soPosX.OnChanged += (x) => OnPositionChanged(0, x);
            soPosY.OnChanged += (y) => OnPositionChanged(1, y);
            soPosZ.OnChanged += (z) => OnPositionChanged(2, z);

            soPosX.OnConfirmed += OnModifyConfirm;
            soPosY.OnConfirmed += OnModifyConfirm;
            soPosZ.OnConfirmed += OnModifyConfirm;

            soPosX.OnFocusLost += OnModifyConfirm;
            soPosY.OnFocusLost += OnModifyConfirm;
            soPosZ.OnFocusLost += OnModifyConfirm;

            positionLayout.AddElement(positionLbl);
            positionLayout.AddElement(soPosX);
            positionLayout.AddSpace(10);
            positionLayout.AddFlexibleSpace();
            positionLayout.AddElement(soPosY);
            positionLayout.AddSpace(10);
            positionLayout.AddFlexibleSpace();
            positionLayout.AddElement(soPosZ);
            positionLayout.AddFlexibleSpace();

            GUILayoutX rotationLayout = sceneObjectLayout.AddLayoutX();
            GUILabel rotationLbl = new GUILabel(new LocEdString("Rotation"), GUIOption.FixedWidth(50));
            soRotX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
            soRotY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
            soRotZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));

            soRotX.OnChanged += (x) => OnRotationChanged(0, x);
            soRotY.OnChanged += (y) => OnRotationChanged(1, y);
            soRotZ.OnChanged += (z) => OnRotationChanged(2, z);

            soRotX.OnConfirmed += OnModifyConfirm;
            soRotY.OnConfirmed += OnModifyConfirm;
            soRotZ.OnConfirmed += OnModifyConfirm;

            soRotX.OnFocusLost += OnModifyConfirm;
            soRotY.OnFocusLost += OnModifyConfirm;
            soRotZ.OnFocusLost += OnModifyConfirm;

            rotationLayout.AddElement(rotationLbl);
            rotationLayout.AddElement(soRotX);
            rotationLayout.AddSpace(10);
            rotationLayout.AddFlexibleSpace();
            rotationLayout.AddElement(soRotY);
            rotationLayout.AddSpace(10);
            rotationLayout.AddFlexibleSpace();
            rotationLayout.AddElement(soRotZ);
            rotationLayout.AddFlexibleSpace();

            GUILayoutX scaleLayout = sceneObjectLayout.AddLayoutX();
            GUILabel scaleLbl = new GUILabel(new LocEdString("Scale"), GUIOption.FixedWidth(50));
            soScaleX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
            soScaleY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
            soScaleZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));

            soScaleX.OnChanged += (x) => OnScaleChanged(0, x);
            soScaleY.OnChanged += (y) => OnScaleChanged(1, y);
            soScaleZ.OnChanged += (z) => OnScaleChanged(2, z);

            soScaleX.OnConfirmed += OnModifyConfirm;
            soScaleY.OnConfirmed += OnModifyConfirm;
            soScaleZ.OnConfirmed += OnModifyConfirm;

            soScaleX.OnFocusLost += OnModifyConfirm;
            soScaleY.OnFocusLost += OnModifyConfirm;
            soScaleZ.OnFocusLost += OnModifyConfirm;

            scaleLayout.AddElement(scaleLbl);
            scaleLayout.AddElement(soScaleX);
            scaleLayout.AddSpace(10);
            scaleLayout.AddFlexibleSpace();
            scaleLayout.AddElement(soScaleY);
            scaleLayout.AddSpace(10);
            scaleLayout.AddFlexibleSpace();
            scaleLayout.AddElement(soScaleZ);
            scaleLayout.AddFlexibleSpace();

            sceneObjectLayout.AddFlexibleSpace();

            GUITexture titleBg = new GUITexture(null, EditorStyles.InspectorTitleBg);
            sceneObjectBgPanel.AddElement(titleBg);
        }
Пример #2
0
        /// <summary>
        /// Ends the selection outline drag operation. Elements in the outline are selected.
        /// </summary>
        /// <returns>True if the selection outline drag is valid and was ended, false otherwise.</returns>
        private bool EndDragSelection()
        {
            if (!isDraggingSelection)
                return false;

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

            Rect2I selectionArea = CalculateSelectionArea();
            SelectInArea(selectionArea);

            isDraggingSelection = false;
            return false;
        }
Пример #3
0
 private static extern void Internal_CreateInstance(GUITexture instance, SpriteTexture texture,
                                                    GUIImageScaleMode scale, bool transparent, string style, GUIOption[] options);
Пример #4
0
        /// <summary>
        /// Ends the selection outline drag operation. Elements in the outline are selected.
        /// </summary>
        /// <returns>True if the selection outline drag is valid and was ended, false otherwise.</returns>
        private bool EndDragSelection()
        {
            if (!isDraggingSelection)
                return false;

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

            if ((dragSelectionEnd - dragSelectionStart).Length < 1)
            {
                isDraggingSelection = false;
                return false;
            }

            Vector2I min = new Vector2I(Math.Min(dragSelectionStart.x, dragSelectionEnd.x),
                    Math.Min(dragSelectionStart.y, dragSelectionEnd.y));
            Vector2I max = new Vector2I(Math.Max(dragSelectionStart.x, dragSelectionEnd.x),
                Math.Max(dragSelectionStart.y, dragSelectionEnd.y));
            sceneSelection.PickObjects(min, max - min,
                Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl));
            isDraggingSelection = false;
            return true;
        }
Пример #5
0
            /// <summary>
            /// Creates a new color box.
            /// </summary>
            /// <param name="guiTexture">GUI element to display the 2D color range on.</param>
            /// <param name="guiSliderHandle">Texture to be used for displaying the position of the currently selected 
            ///                               color.</param>
            /// <param name="width">Width of the slider in pixels.</param>
            /// <param name="height">Height of the slider in pixels.</param>
            public ColorSlider2D(GUITexture guiTexture, GUITexture guiSliderHandle, int width, int height)
            {
                this.width = width;
                this.height = height;

                this.guiTexture = guiTexture;
                this.guiSliderHandle = guiSliderHandle;

                texture = new Texture2D(width, height);
                spriteTexture = new SpriteTexture(texture);
            }
Пример #6
0
            /// <summary>
            /// Creates a new horizontal slider.
            /// </summary>
            /// <param name="guiTexture">GUI element to display the slider color range on.</param>
            /// <param name="guiSlider">Slider rendered on top of the texture that may be moved by the user to select a 
            ///                         color.</param>
            /// <param name="width">Width of the slider in pixels.</param>
            /// <param name="height">Height of the slider in pixels.</param>
            public ColorSlider1DHorz(GUITexture guiTexture, GUISliderH guiSlider, int width, int height)
            {
                this.width = width;
                this.height = height;
                this.guiTexture = guiTexture;
                this.guiSlider = guiSlider;

                texture = new Texture2D(width, height);
                spriteTexture = new SpriteTexture(texture);
            }
        /// <summary>
        /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
        /// </summary>
        /// <param name="layouts">Layouts to append the GUI elements to.</param>
        /// <param name="path">Path of the curve field.</param>
        /// <param name="color">Color of the path field curve, to display next to the element name.</param>
        /// <param name="child">Determines if the element is a root path, or a child (sub) element.</param>
        public GUIAnimSimpleEntry(GUIAnimFieldLayouts layouts, string path, Color color, bool child = false)
            : base(layouts, path, child, child ? 45 : 30)
        {
            valueDisplay = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
            underlayLayout = layouts.underlay.AddLayoutX();
            underlayLayout.AddSpace(child ? 30 : 15);

            GUITexture colorSquare = new GUITexture(Builtin.WhiteTexture,
                GUIOption.FixedWidth(10), GUIOption.FixedHeight(10));
            colorSquare.SetTint(color);

            underlayLayout.AddElement(colorSquare);
            underlayLayout.AddFlexibleSpace();
            underlayLayout.AddElement(valueDisplay);
            underlayLayout.AddSpace(10);

            overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
            layouts.overlay.AddElement(overlaySpacing);
        }
Пример #8
0
        private void OnInitialize()
        {
            Title = "Project Manager";

            Width = 500;
            Height = 290;

            GUILayout vertLayout = GUI.AddLayoutY();

            vertLayout.AddSpace(5);
            GUILayout firstRow = vertLayout.AddLayoutX();
            vertLayout.AddFlexibleSpace();
            GUILayout secondRow = vertLayout.AddLayoutX();
            vertLayout.AddSpace(5);
            GUILayout thirdRow = vertLayout.AddLayoutX();
            vertLayout.AddFlexibleSpace();
            GUILayout fourthRow = vertLayout.AddLayoutX();
            vertLayout.AddSpace(5);

            projectInputBox = new GUITextField(new LocEdString("Project path"), 70, false, "", GUIOption.FixedWidth(398));
            projectInputBox.Value = EditorSettings.LastOpenProject;

            GUIButton openBtn = new GUIButton(new LocEdString("Open"), GUIOption.FixedWidth(75));
            openBtn.OnClick += OpenProject;

            firstRow.AddSpace(5);
            firstRow.AddElement(projectInputBox);
            firstRow.AddSpace(15);
            firstRow.AddElement(openBtn);
            firstRow.AddSpace(5);

            GUILabel recentProjectsLabel = new GUILabel(new LocEdString("Recent projects:"));

            secondRow.AddSpace(5);
            secondRow.AddElement(recentProjectsLabel);
            secondRow.AddFlexibleSpace();
            GUIButton browseBtn = new GUIButton(new LocEdString("Browse"), GUIOption.FixedWidth(75));
            browseBtn.OnClick += BrowseClicked;
            secondRow.AddElement(browseBtn);
            secondRow.AddSpace(5);

            thirdRow.AddSpace(5);
            GUIPanel recentProjectsPanel = thirdRow.AddPanel();
            thirdRow.AddSpace(15);
            GUILayoutY thirdRowVertical = thirdRow.AddLayoutY();
            GUIButton createBtn = new GUIButton(new LocEdString("Create new"), GUIOption.FixedWidth(75));
            createBtn.OnClick += CreateClicked;
            thirdRowVertical.AddElement(createBtn);
            thirdRowVertical.AddFlexibleSpace();
            thirdRow.AddSpace(5);

            recentProjectsArea = new GUIScrollArea(GUIOption.FixedWidth(385), GUIOption.FixedHeight(170));
            GUILayoutX recentProjectsLayout = recentProjectsPanel.AddLayoutX();
            recentProjectsLayout.AddSpace(10);
            GUILayoutY recentProjectsPanelY = recentProjectsLayout.AddLayoutY();
            recentProjectsPanelY.AddSpace(5);
            recentProjectsPanelY.AddElement(recentProjectsArea);
            recentProjectsPanelY.AddSpace(5);
            recentProjectsLayout.AddFlexibleSpace();

            GUIPanel scrollAreaBgPanel = recentProjectsPanel.AddPanel(1);
            GUITexture scrollAreaBgTex = new GUITexture(null, true, EditorStylesInternal.ScrollAreaBg);
            scrollAreaBgPanel.AddElement(scrollAreaBgTex);

            autoLoadToggle = new GUIToggle("");
            autoLoadToggle.Value = EditorSettings.AutoLoadLastProject;

            GUILabel autoLoadLabel = new GUILabel(new LocEdString("Automatically load last open project"));

            GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"), GUIOption.FixedWidth(75));
            cancelBtn.OnClick += CancelClicked;

            fourthRow.AddSpace(5);
            fourthRow.AddElement(autoLoadToggle);
            fourthRow.AddElement(autoLoadLabel);
            fourthRow.AddFlexibleSpace();
            fourthRow.AddElement(cancelBtn);
            fourthRow.AddSpace(5);

            RefreshRecentProjects();
        }
Пример #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"));
                    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 += OnFoldoutToggled;
               guiInternalTitleLayout.AddElement(guiFoldout);

               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
                           ? EditorStyles.InspectorContentBgAlternate
                           : EditorStyles.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.Inspectable)
                               continue;

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

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

                           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();
                   BuildFilledGUI();
                   state = State.Filled;
               }
               }
               else if (state == State.Filled)
               {
               foreach (var child in children)
                   child.Destroy();

               children.Clear();
               guiInternalTitleLayout.Destroy();

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

               if (propertyValue == null)
               {
                   BuildEmptyGUI();
                   state = State.Empty;
               }
               else
               {
                   BuildFilledGUI();
               }
               }
        }
        /// <summary>
        /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
        /// </summary>
        /// <param name="layouts">Layouts to append the GUI elements to.</param>
        /// <param name="path">Path of the curve field.</param>
        /// <param name="child">Determines if the element is a root path, or a child (sub) element.</param>
        /// <param name="indentAmount">Determines how much to horizontally indent the element, in pixels.</param>
        public GUIAnimFieldEntry(GUIAnimFieldLayouts layouts, string path, bool child, int indentAmount)
        {
            this.path = path;

            GUILayoutX toggleLayout = layouts.main.AddLayoutX();
            toggleLayout.AddSpace(indentAmount);

            selectionBtn = new GUIButton(GetDisplayName(path, child), EditorStyles.Label, GUIOption.FlexibleWidth());
            selectionBtn.OnClick += () =>
            {
                OnEntrySelected?.Invoke(path);
            };

            toggleLayout.AddElement(selectionBtn);

            entryHeight = EditorBuiltin.GUISkin.GetStyle(EditorStyles.Label).Height;

            backgroundTexture = new GUITexture(Builtin.WhiteTexture, GUITextureScaleMode.StretchToFit,
                GUIOption.FlexibleWidth());
            backgroundTexture.SetTint(Color.Transparent);
            backgroundTexture.SetHeight(entryHeight);

            layouts.background.AddElement(backgroundTexture);
        }
Пример #11
0
        /// <summary>
        /// Destroys all inspector GUI elements.
        /// </summary>
        internal void Clear()
        {
            for (int i = 0; i < inspectorComponents.Count; i++)
            {
                inspectorComponents[i].foldout.Destroy();
                inspectorComponents[i].removeBtn.Destroy();
                inspectorComponents[i].inspector.Destroy();
            }

            inspectorComponents.Clear();

            if (inspectorResource != null)
            {
                inspectorResource.inspector.Destroy();
                inspectorResource = null;
            }

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

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

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

            activeSO = null;
            soNameInput = null;
            soActiveToggle = null;
            soPrefabLayout = null;
            soHasPrefab = false;
            soPosX = null;
            soPosY = null;
            soPosZ = null;
            soRotX = null;
            soRotY = null;
            soRotZ = null;
            soScaleX = null;
            soScaleY = null;
            soScaleZ = null;
            dropAreas = new Rect2I[0];

            activeResource = null;
            currentType = InspectorType.None;
        }
Пример #12
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.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout);
                data.removeBtn = new GUIButton(new GUIContent(EditorBuiltin.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();
        }
Пример #13
0
        /// <summary>
        /// Sets a resource whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
        /// </summary>
        /// <param name="resourcePath">Resource path relative to the project of the resource to inspect.</param>
        private void SetObjectToInspect(String resourcePath)
        {
            activeResource = ProjectLibrary.Load<Resource>(resourcePath);

            if (activeResource == null)
                return;

            currentType = InspectorType.Resource;

            inspectorScrollArea = new GUIScrollArea();
            GUI.AddElement(inspectorScrollArea);
            inspectorLayout = inspectorScrollArea.Layout;

            GUIPanel titlePanel = inspectorLayout.AddPanel();
            titlePanel.SetHeight(RESOURCE_TITLE_HEIGHT);

            GUILayoutY titleLayout = titlePanel.AddLayoutY();
            titleLayout.SetPosition(PADDING, PADDING);

            string name = Path.GetFileNameWithoutExtension(resourcePath);
            string type = activeResource.GetType().Name;

            LocString title = new LocEdString(name + " (" + type + ")");
            GUILabel titleLabel = new GUILabel(title);

            titleLayout.AddFlexibleSpace();
            GUILayoutX titleLabelLayout = titleLayout.AddLayoutX();
            titleLabelLayout.AddElement(titleLabel);
            titleLayout.AddFlexibleSpace();

            GUIPanel titleBgPanel = titlePanel.AddPanel(1);

            GUITexture titleBg = new GUITexture(null, EditorStyles.InspectorTitleBg);
            titleBgPanel.AddElement(titleBg);

            inspectorLayout.AddSpace(COMPONENT_SPACING);

            inspectorResource = new InspectorResource();
            inspectorResource.panel = inspectorLayout.AddPanel();

            var persistentProperties = persistentData.GetProperties(activeResource.UUID);

            inspectorResource.inspector = InspectorUtility.GetInspector(activeResource.GetType());
            inspectorResource.inspector.Initialize(inspectorResource.panel, activeResource, persistentProperties);

            inspectorLayout.AddFlexibleSpace();
        }
Пример #14
0
 private static extern void Internal_CreateInstance(GUITexture instance, SpriteTexture texture,
     GUIImageScaleMode scale, bool transparent, string style, GUIOption[] options);
Пример #15
0
        /// <summary>
        /// Initializes the inspector. Must be called after construction.
        /// </summary>
        /// <param name="gui">GUI panel to add the GUI elements to.</param>
        /// <param name="instance">Instance of the object whose fields to display GUI for.</param>
        /// <param name="persistent">A set of properties that the inspector can read/write. They will be persisted even 
        ///                          after the inspector is closed and restored when it is re-opened.</param>
        internal virtual void Initialize(GUIPanel gui, object instance, SerializableProperties persistent)
        {
            rootGUI = gui;
            this.persistent = persistent;

            GUILayout contentLayoutX = gui.AddLayoutX();
            contentLayoutX.AddSpace(5);
            GUILayout contentLayoutY = contentLayoutX.AddLayoutY();
            contentLayoutY.AddSpace(5);
            GUIPanel contentPanel = contentLayoutY.AddPanel();
            contentLayoutY.AddSpace(5);
            contentLayoutX.AddSpace(5);

            GUIPanel backgroundPanel = gui.AddPanel(START_BACKGROUND_DEPTH);
            GUITexture inspectorContentBg = new GUITexture(null, EditorStyles.InspectorContentBg);
            backgroundPanel.AddElement(inspectorContentBg);

            mainPanel = contentPanel;
            layout = GUI.AddLayoutY();
            inspectedObject = instance;

            Initialize();
            Refresh();
        }
Пример #16
0
        /// <summary>
        /// Recreates the entire curve editor GUI depending on the currently selected scene object.
        /// </summary>
        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 GUIToggle(playIcon, EditorStyles.Button);
            recordButton = new GUIToggle(recordIcon, EditorStyles.Button);

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

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

            optionsButton = new GUIButton(optionsIcon);

            playButton.OnToggled += x =>
            {
                if(x)
                    SwitchState(State.Playback);
                else
                    SwitchState(State.Normal);
            };

            recordButton.OnToggled += x =>
            {
                if (x)
                    SwitchState(State.Recording);
                else
                    SwitchState(State.Normal);
            };

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

                switch (state)
                {
                    case State.Recording:
                    case State.Normal:
                        PreviewFrame(currentFrameIdx);
                        break;
                    default:
                        SwitchState(State.Normal);
                        break;
                }
            };

            frameInputField.OnChanged += x =>
            {
                SetCurrentFrame(x);

                switch (state)
                {
                    case State.Recording:
                    case State.Normal:
                        PreviewFrame(currentFrameIdx);
                        break;
                    default:
                        SwitchState(State.Normal);
                        break;
                }
            };

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

                switch (state)
                {
                    case State.Recording:
                    case State.Normal:
                        PreviewFrame(currentFrameIdx);
                        break;
                    default:
                        SwitchState(State.Normal);
                        break;
                }
            };

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

            addEventButton.OnClick += () =>
            {
                SwitchState(State.Normal);
                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))
                            {
                                SwitchState(State.Empty);
                                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();

                                SwitchState(State.Normal);
                                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
                    {
                        SwitchState(State.Normal);
                        openPropertyWindow();
                    }
                }
            };

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

                SwitchState(State.Normal);

                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();
                            ApplyClipChanges();
                        }
                    });
                }
            };

            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 += () =>
            {
                SwitchState(State.Normal);

                ApplyClipChanges();
                PreviewFrame(currentFrameIdx);

                EditorApplication.SetProjectDirty();
            };
            guiCurveEditor.OnClicked += () =>
            {
                if(state != State.Recording)
                    SwitchState(State.Normal);
            };
            guiCurveEditor.Redraw();

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

            UpdateScrollBarSize();
        }
Пример #17
0
        /// <summary>
        /// Clears the underlay GUI element (for example ping, hover, select).
        /// </summary>
        private void ClearUnderlay()
        {
            if (underlay != null)
            {
                underlay.Destroy();
                underlay = null;
            }

            underlayState = UnderlayState.None;
        }
Пример #18
0
        private void OnInitialize()
        {
            GUILayoutY mainLayout = GUI.AddLayoutY();

            string[] aspectRatioTitles = new string[aspectRatios.Length + 1];
            aspectRatioTitles[0] = "Free";

            for (int i = 0; i < aspectRatios.Length; i++)
                aspectRatioTitles[i + 1] = aspectRatios[i].width + ":" + aspectRatios[i].height;

            GUIListBoxField aspectField = new GUIListBoxField(aspectRatioTitles, new LocEdString("Aspect ratio"));
            aspectField.OnSelectionChanged += OnAspectRatioChanged;

            GUILayoutY buttonLayoutVert = mainLayout.AddLayoutY();
            GUILayoutX buttonLayout = buttonLayoutVert.AddLayoutX();
            buttonLayout.AddElement(aspectField);
            buttonLayout.AddFlexibleSpace();
            buttonLayoutVert.AddFlexibleSpace();

            renderTextureGUI = new GUIRenderTexture(null);
            renderTextureBg = new GUITexture(Builtin.WhiteTexture);
            renderTextureBg.SetTint(BG_COLOR);

            noCameraLabel = new GUILabel(new LocEdString("(No main camera in scene)"));

            GUIPanel rtPanel = mainLayout.AddPanel();
            rtPanel.AddElement(renderTextureGUI);

            GUIPanel bgPanel = rtPanel.AddPanel(1);
            bgPanel.AddElement(renderTextureBg);

            GUILayoutY alignLayoutY = rtPanel.AddLayoutY();
            alignLayoutY.AddFlexibleSpace();
            GUILayoutX alignLayoutX = alignLayoutY.AddLayoutX();
            alignLayoutX.AddFlexibleSpace();
            alignLayoutX.AddElement(noCameraLabel);
            alignLayoutX.AddFlexibleSpace();
            alignLayoutY.AddFlexibleSpace();

            UpdateRenderTexture(Width, Height);

            bool hasMainCamera = Scene.Camera != null;

            renderTextureGUI.Active = hasMainCamera;
            noCameraLabel.Active = !hasMainCamera;
        }
Пример #19
0
        /// <summary>
        /// Creates a GUI elements that may be used for underlay effects (for example ping, hover, select).
        /// </summary>
        private void CreateUnderlay()
        {
            if (underlay == null)
            {
                underlay = new GUITexture(Builtin.WhiteTexture);
                underlay.Bounds = Bounds;

                owner.Underlay.AddElement(underlay);
            }
        }
Пример #20
0
        private void OnInitialize()
        {
            guiColor = new GUIColorField("", GUIOption.FixedWidth(100));
            guiSlider2DTex = new GUITexture(null, GUIOption.FixedHeight(ColorBoxHeight), GUIOption.FixedWidth(ColorBoxWidth));
            guiSliderVertTex = new GUITexture(null, GUIOption.FixedHeight(SliderSideHeight), GUIOption.FixedWidth(SliderSideWidth));
            guiSliderRHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));
            guiSliderGHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));
            guiSliderBHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));
            guiSliderAHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));

            guiColorBoxBtn = new GUIButton(colorBoxMode.ToString());
            guiColorModeBtn = new GUIButton(sliderMode.ToString());

            guiSliderVert = new GUISliderV(EditorStylesInternal.ColorSliderVert);
            guiSliderRHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSliderGHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSliderBHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSliderAHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSlider2DHandle = new GUITexture(null, EditorStylesInternal.ColorSlider2DHandle);

            guiLabelR = new GUILabel(new LocEdString("R"));
            guiLabelG = new GUILabel(new LocEdString("G"));
            guiLabelB = new GUILabel(new LocEdString("B"));
            guiLabelA = new GUILabel(new LocEdString("A"));

            guiInputR = new GUIIntField();
            guiInputG = new GUIIntField();
            guiInputB = new GUIIntField();
            guiInputA = new GUIIntField();

            guiOK = new GUIButton(new LocEdString("OK"));
            guiCancel = new GUIButton(new LocEdString("Cancel"));

            guiColorBoxBtn.OnClick += OnColorBoxModeChanged;
            guiColorModeBtn.OnClick += OnSliderModeChanged;

            guiSliderVert.OnChanged += OnSliderVertChanged;
            guiSliderRHorz.OnChanged += OnSliderRHorzChanged;
            guiSliderGHorz.OnChanged += OnSliderGHorzChanged;
            guiSliderBHorz.OnChanged += OnSliderBHorzChanged;
            guiSliderAHorz.OnChanged += OnSliderAHorzChanged;

            guiInputR.OnChanged += OnInputRChanged;
            guiInputG.OnChanged += OnInputGChanged;
            guiInputB.OnChanged += OnInputBChanged;
            guiInputA.OnChanged += OnInputAChanged;

            guiOK.OnClick += OnOK;
            guiCancel.OnClick += OnCancel;

            GUIPanel mainPanel = GUI.AddPanel(0);
            GUILayout v0 = mainPanel.AddLayoutY();

            v0.AddSpace(5);

            GUILayout h0 = v0.AddLayoutX();
            h0.AddSpace(10);
            h0.AddElement(guiColor);
            h0.AddFlexibleSpace();
            h0.AddElement(guiColorBoxBtn);
            h0.AddElement(guiColorModeBtn);
            h0.AddSpace(10);

            v0.AddSpace(10);

            GUILayout h1 = v0.AddLayoutX();
            h1.AddSpace(10);
            h1.AddElement(guiSlider2DTex);
            h1.AddFlexibleSpace();
            h1.AddElement(guiSliderVertTex);
            h1.AddSpace(10);

            v0.AddSpace(10);

            GUILayout h2 = v0.AddLayoutX();
            h2.AddSpace(10);
            h2.AddElement(guiLabelR);
            h2.AddFlexibleSpace();
            h2.AddElement(guiSliderRHorzTex);
            h2.AddFlexibleSpace();
            h2.AddElement(guiInputR);
            h2.AddSpace(10);

            v0.AddSpace(5);

            GUILayout h3 = v0.AddLayoutX();
            h3.AddSpace(10);
            h3.AddElement(guiLabelG);
            h3.AddFlexibleSpace();
            h3.AddElement(guiSliderGHorzTex);
            h3.AddFlexibleSpace();
            h3.AddElement(guiInputG);
            h3.AddSpace(10);

            v0.AddSpace(5);

            GUILayout h4 = v0.AddLayoutX();
            h4.AddSpace(10);
            h4.AddElement(guiLabelB);
            h4.AddFlexibleSpace();
            h4.AddElement(guiSliderBHorzTex);
            h4.AddFlexibleSpace();
            h4.AddElement(guiInputB);
            h4.AddSpace(10);

            v0.AddSpace(5);

            GUILayout h5 = v0.AddLayoutX();
            h5.AddSpace(10);
            h5.AddElement(guiLabelA);
            h5.AddFlexibleSpace();
            h5.AddElement(guiSliderAHorzTex);
            h5.AddFlexibleSpace();
            h5.AddElement(guiInputA);
            h5.AddSpace(10);

            v0.AddSpace(10);

            GUILayout h6 = v0.AddLayoutX();
            h6.AddFlexibleSpace();
            h6.AddElement(guiOK);
            h6.AddSpace(10);
            h6.AddElement(guiCancel);
            h6.AddFlexibleSpace();

            v0.AddSpace(5);

            GUIPanel overlay = GUI.AddPanel(-1);
            overlay.SetWidth(Width);
            overlay.SetHeight(Height);

            overlay.AddElement(guiSliderVert);
            overlay.AddElement(guiSliderRHorz);
            overlay.AddElement(guiSliderGHorz);
            overlay.AddElement(guiSliderBHorz);
            overlay.AddElement(guiSliderAHorz);
            overlay.AddElement(guiSlider2DHandle);

            colorBox = new ColorSlider2D(guiSlider2DTex, guiSlider2DHandle, ColorBoxWidth, ColorBoxHeight);
            sideSlider = new ColorSlider1DVert(guiSliderVertTex, guiSliderVert, SliderSideWidth, SliderSideHeight);

            sliderR = new ColorSlider1DHorz(guiSliderRHorzTex, guiSliderRHorz, SliderIndividualWidth, SliderIndividualHeight);
            sliderG = new ColorSlider1DHorz(guiSliderGHorzTex, guiSliderGHorz, SliderIndividualWidth, SliderIndividualHeight);
            sliderB = new ColorSlider1DHorz(guiSliderBHorzTex, guiSliderBHorz, SliderIndividualWidth, SliderIndividualHeight);
            sliderA = new ColorSlider1DHorz(guiSliderAHorzTex, guiSliderAHorz, SliderIndividualWidth, SliderIndividualHeight);

            colorBox.OnValueChanged += OnColorBoxValueChanged;

            Color startA = new Color(0, 0, 0, 1);
            Color stepA = new Color(1, 1, 1, 0);
            sliderA.UpdateTexture(startA, stepA, false);
            guiInputA.SetRange(0, 255);
            guiInputA.Value = 255;
            guiSliderAHorz.Percent = 1.0f;

            guiColor.Value = SelectedColor;
            UpdateInputBoxValues();
            Update2DSliderValues();
            Update1DSliderValues();
            UpdateSliderMode();
            Update2DSliderTextures();
            Update1DSliderTextures();
        }
Пример #21
0
        /// <summary>
        /// Constructs a new resource tile entry.
        /// </summary>
        /// <param name="owner">Content area this entry is part of.</param>
        /// <param name="parent">Parent layout to add this entry's GUI elements to.</param>
        /// <param name="path">Path to the project library entry to display data for.</param>
        /// <param name="index">Sequential index of the entry in the conent area.</param>
        /// <param name="width">Width of the GUI entry.</param>
        /// <param name="height">Maximum allowed height for the label.</param>"
        /// <param name="type">Type of the entry, which controls its style and/or behaviour.</param>
        public LibraryGUIEntry(LibraryGUIContent owner, GUILayout parent, string path, int index, int width, int height,
            LibraryGUIEntryType type)
        {
            GUILayout entryLayout;

            if (owner.GridLayout)
                entryLayout = parent.AddLayoutY();
            else
                entryLayout = parent.AddLayoutX();

            SpriteTexture iconTexture = GetIcon(path, owner.TileSize);

            icon = new GUITexture(iconTexture, GUIImageScaleMode.ScaleToFit,
                true, GUIOption.FixedHeight(owner.TileSize), GUIOption.FixedWidth(owner.TileSize));

            label = null;

            string name = PathEx.GetTail(path);
            if (owner.GridLayout)
            {
                int labelHeight = height - owner.TileSize;

                label = new GUILabel(name, EditorStyles.MultiLineLabelCentered,
                    GUIOption.FixedWidth(width), GUIOption.FixedHeight(labelHeight));

                switch (type)
                {
                    case LibraryGUIEntryType.Single:
                        break;
                    case LibraryGUIEntryType.MultiFirst:
                        groupUnderlay = new GUITexture(null, LibraryEntryFirstBg);
                        break;
                    case LibraryGUIEntryType.MultiElement:
                        groupUnderlay = new GUITexture(null, LibraryEntryBg);
                        break;
                    case LibraryGUIEntryType.MultiLast:
                        groupUnderlay = new GUITexture(null, LibraryEntryLastBg);
                        break;
                }
            }
            else
            {
                label = new GUILabel(name, GUIOption.FixedWidth(width - owner.TileSize), GUIOption.FixedHeight(height));

                switch (type)
                {
                    case LibraryGUIEntryType.Single:
                        break;
                    case LibraryGUIEntryType.MultiFirst:
                        groupUnderlay = new GUITexture(null, LibraryEntryVertFirstBg);
                        break;
                    case LibraryGUIEntryType.MultiElement:
                        groupUnderlay = new GUITexture(null, LibraryEntryVertBg);
                        break;
                    case LibraryGUIEntryType.MultiLast:
                        groupUnderlay = new GUITexture(null, LibraryEntryVertLastBg);
                        break;
                }
            }

            entryLayout.AddElement(icon);
            entryLayout.AddElement(label);

            if (groupUnderlay != null)
                owner.DeepUnderlay.AddElement(groupUnderlay);

            this.owner = owner;
            this.index = index;
            this.path = path;
            this.bounds = new Rect2I();
            this.underlay = null;
            this.type = type;
            this.width = width;
            this.height = height;
        }
Пример #22
0
            /// <summary>
            /// Builds GUI for the specified GUI element style.
            /// </summary>
            /// <param name="layout">Layout to append the GUI elements to.</param>
            /// <param name="depth">Determines the depth at which the element is rendered.</param>
            public void BuildGUI(GUILayout layout, int depth)
            {
                short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                string bgPanelStyle = depth % 2 == 0
                    ? EditorStyles.InspectorContentBgAlternate
                    : EditorStyles.InspectorContentBg;

                GUIToggle foldout = new GUIToggle(new LocEdString("Style"), EditorStyles.Foldout);
                GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);

                layout.AddElement(foldout);
                GUIPanel panel = layout.AddPanel();
                GUIPanel backgroundPanel = panel.AddPanel(backgroundDepth);

                backgroundPanel.AddElement(inspectorContentBg);

                GUILayoutX guiIndentLayoutX = panel.AddLayoutX();
                guiIndentLayoutX.AddSpace(IndentAmount);
                GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                GUILayoutY contentLayout = guiIndentLayoutY.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                guiIndentLayoutX.AddSpace(IndentAmount);

                fontField = new GUIResourceField(typeof (Font), new LocEdString("Font"));
                fontSizeField = new GUIIntField(new LocEdString("Font size"));
                horzAlignField = new GUIEnumField(typeof (TextHorzAlign), new LocEdString("Horizontal alignment"));
                vertAlignField = new GUIEnumField(typeof(TextVertAlign), new LocEdString("Vertical alignment"));
                imagePositionField = new GUIEnumField(typeof(GUIImagePosition), new LocEdString("Image position"));
                wordWrapField = new GUIToggleField(new LocEdString("Word wrap"));

                contentLayout.AddElement(fontField);
                contentLayout.AddElement(fontSizeField);
                contentLayout.AddElement(horzAlignField);
                contentLayout.AddElement(vertAlignField);
                contentLayout.AddElement(imagePositionField);
                contentLayout.AddElement(wordWrapField);

                normalGUI.BuildGUI(new LocEdString("Normal"), contentLayout);
                hoverGUI.BuildGUI(new LocEdString("Hover"), contentLayout);
                activeGUI.BuildGUI(new LocEdString("Active"), contentLayout);
                focusedGUI.BuildGUI(new LocEdString("Focused"), contentLayout);
                normalOnGUI.BuildGUI(new LocEdString("NormalOn"), contentLayout);
                hoverOnGUI.BuildGUI(new LocEdString("HoverOn"), contentLayout);
                activeOnGUI.BuildGUI(new LocEdString("ActiveOn"), contentLayout);
                focusedOnGUI.BuildGUI(new LocEdString("FocusedOn"), contentLayout);

                borderGUI = new RectOffsetGUI(new LocEdString("Border"), contentLayout);
                marginsGUI = new RectOffsetGUI(new LocEdString("Margins"), contentLayout);
                contentOffsetGUI = new RectOffsetGUI(new LocEdString("Content offset"), contentLayout);

                fixedWidthField = new GUIToggleField(new LocEdString("Fixed width"));
                widthField = new GUIIntField(new LocEdString("Width"));
                minWidthField = new GUIIntField(new LocEdString("Min. width"));
                maxWidthField = new GUIIntField(new LocEdString("Max. width"));

                fixedHeightField = new GUIToggleField(new LocEdString("Fixed height"));
                heightField = new GUIIntField(new LocEdString("Height"));
                minHeightField = new GUIIntField(new LocEdString("Min. height"));
                maxHeightField = new GUIIntField(new LocEdString("Max. height"));

                contentLayout.AddElement(fixedWidthField);
                contentLayout.AddElement(widthField);
                contentLayout.AddElement(minWidthField);
                contentLayout.AddElement(maxWidthField);

                contentLayout.AddElement(fixedHeightField);
                contentLayout.AddElement(heightField);
                contentLayout.AddElement(minHeightField);
                contentLayout.AddElement(maxHeightField);

                foldout.OnToggled += x =>
                {
                    panel.Active = x;
                    isExpanded = x;
                };

                fontField.OnChanged += x =>
                {
                    Font font = Resources.Load<Font>(x);

                    GetStyle().Font = font;
                    MarkAsModified();
                    ConfirmModify();
                };
                fontSizeField.OnChanged += x => { GetStyle().FontSize = x; MarkAsModified(); };
                fontSizeField.OnFocusLost += ConfirmModify;
                fontSizeField.OnConfirmed += ConfirmModify;
                horzAlignField.OnSelectionChanged += x =>
                {
                    GetStyle().TextHorzAlign = (TextHorzAlign)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                vertAlignField.OnSelectionChanged += x =>
                {
                    GetStyle().TextVertAlign = (TextVertAlign)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                imagePositionField.OnSelectionChanged += x =>
                {
                    GetStyle().ImagePosition = (GUIImagePosition)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                wordWrapField.OnChanged += x => { GetStyle().WordWrap = x; MarkAsModified(); ConfirmModify(); };

                normalGUI.OnChanged += x => { GetStyle().Normal = x; MarkAsModified(); ConfirmModify(); };
                hoverGUI.OnChanged += x => { GetStyle().Hover = x; MarkAsModified(); ConfirmModify(); };
                activeGUI.OnChanged += x => { GetStyle().Active = x; MarkAsModified(); ConfirmModify(); };
                focusedGUI.OnChanged += x => { GetStyle().Focused = x; MarkAsModified(); ConfirmModify(); };
                normalOnGUI.OnChanged += x => { GetStyle().NormalOn = x; MarkAsModified(); ConfirmModify(); };
                hoverOnGUI.OnChanged += x => { GetStyle().HoverOn = x; MarkAsModified(); ConfirmModify(); };
                activeOnGUI.OnChanged += x => { GetStyle().ActiveOn = x; MarkAsModified(); ConfirmModify(); };
                focusedOnGUI.OnChanged += x => { GetStyle().FocusedOn = x; MarkAsModified(); ConfirmModify(); };

                borderGUI.OnChanged += x => { GetStyle().Border = x; MarkAsModified(); };
                marginsGUI.OnChanged += x => { GetStyle().Margins = x; MarkAsModified(); };
                contentOffsetGUI.OnChanged += x => { GetStyle().ContentOffset = x; MarkAsModified(); };

                borderGUI.OnConfirmed += ConfirmModify;
                marginsGUI.OnConfirmed += ConfirmModify;
                contentOffsetGUI.OnConfirmed += ConfirmModify;

                fixedWidthField.OnChanged += x => { GetStyle().FixedWidth = x; MarkAsModified(); ConfirmModify(); };
                widthField.OnChanged += x => GetStyle().Width = x;
                widthField.OnFocusLost += ConfirmModify;
                widthField.OnConfirmed += ConfirmModify;
                minWidthField.OnChanged += x => GetStyle().MinWidth = x;
                minWidthField.OnFocusLost += ConfirmModify;
                minWidthField.OnConfirmed += ConfirmModify;
                maxWidthField.OnChanged += x => GetStyle().MaxWidth = x;
                maxWidthField.OnFocusLost += ConfirmModify;
                maxWidthField.OnConfirmed += ConfirmModify;

                fixedHeightField.OnChanged += x => { GetStyle().FixedHeight = x; MarkAsModified(); ConfirmModify(); };
                heightField.OnChanged += x => GetStyle().Height = x;
                heightField.OnFocusLost += ConfirmModify;
                heightField.OnConfirmed += ConfirmModify;
                minHeightField.OnChanged += x => GetStyle().MinHeight = x;
                minHeightField.OnFocusLost += ConfirmModify;
                minHeightField.OnConfirmed += ConfirmModify;
                maxHeightField.OnChanged += x => GetStyle().MaxHeight = x;
                maxHeightField.OnFocusLost += ConfirmModify;
                maxHeightField.OnConfirmed += ConfirmModify;

                foldout.Value = isExpanded;
                panel.Active = isExpanded;
            }
Пример #23
0
        /// <summary>
        /// Registers a new row in the layout. The row cannot be selected as the output field, but rather can be expanded
        /// so it displays child elements.
        /// </summary>
        /// <param name="layout">Layout to append the row GUI elements to.</param>
        /// <param name="icon">Optional icon to display next to the name. Can be null.</param>
        /// <param name="name">Name of the field.</param>
        /// <param name="so">Parent scene object of the field.</param>
        /// <param name="component">Parent component of the field. Can be null if field belongs to <see cref="SceneObject"/>.
        ///                         </param>
        /// <param name="path">Slash separated path to the field from its parent object.</param>
        /// <param name="toggleCallback">Callback to trigger when the user expands or collapses the foldout.</param>
        /// <returns>Element object storing all information about the added field.</returns>
        private Element AddFoldoutRow(GUILayout layout, SpriteTexture icon, string name, SceneObject so, Component component,
            string path, Action<Element, bool> toggleCallback)
        {
            Element element = new Element(so, component, path);

            GUILayoutY elementLayout = layout.AddLayoutY();
            GUILayoutX foldoutLayout = elementLayout.AddLayoutX();

            element.toggle = new GUIToggle("", EditorStyles.Expand);
            element.toggle.OnToggled += x => toggleCallback(element, x);

            foldoutLayout.AddSpace(PADDING);
            foldoutLayout.AddElement(element.toggle);

            if (icon != null)
            {
                GUITexture guiIcon = new GUITexture(icon, GUIOption.FixedWidth(16), GUIOption.FixedWidth(16));
                foldoutLayout.AddElement(guiIcon);
            }

            GUILabel label = new GUILabel(new LocEdString(name));
            foldoutLayout.AddElement(label);
            foldoutLayout.AddFlexibleSpace();

            element.indentLayout = elementLayout.AddLayoutX();
            element.indentLayout.AddSpace(INDENT_AMOUNT);
            element.childLayout = element.indentLayout.AddLayoutY();

            element.indentLayout.Active = false;

            return element;
        }
Пример #24
0
        private void OnInitialize()
        {
            GUILayoutX splitLayout = GUI.AddLayoutX();
            GUIPanel platformPanel = splitLayout.AddPanel();
            GUIPanel platformForeground = platformPanel.AddPanel();
            GUILayoutY platformLayout = platformForeground.AddLayoutY();
            GUIPanel platformBackground = platformPanel.AddPanel(1);
            GUITexture background = new GUITexture(Builtin.WhiteTexture);
            background.SetTint(PLATFORM_BG_COLOR);

            splitLayout.AddSpace(5);
            GUILayoutY optionsLayout = splitLayout.AddLayoutY();

            GUILabel platformsLabel = new GUILabel(new LocEdString("Platforms"), EditorStyles.LabelCentered);
            platformLayout.AddSpace(5);
            platformLayout.AddElement(platformsLabel);
            platformLayout.AddSpace(5);

            GUIToggleGroup platformToggleGroup = new GUIToggleGroup();

            PlatformType[] availablePlatforms = BuildManager.AvailablePlatforms;
            platformButtons = new GUIToggle[availablePlatforms.Length];
            for (int i = 0; i < availablePlatforms.Length; i++)
            {
                PlatformType currentPlatform = availablePlatforms[i];
                bool isActive = currentPlatform == BuildManager.ActivePlatform;

                string platformName = Enum.GetName(typeof(PlatformType), currentPlatform);
                if (isActive)
                    platformName += " (Active)";

                GUIToggle platformToggle = new GUIToggle(new LocEdString(platformName), platformToggleGroup, EditorStyles.Button);
                platformToggle.OnToggled += x => OnSelectedPlatformChanged(currentPlatform, x);
                platformLayout.AddElement(platformToggle);

                platformButtons[i] = platformToggle;

                if (isActive)
                {
                    platformToggle.Value = true;
                    selectedPlatform = currentPlatform;
                }
            }

            platformLayout.AddFlexibleSpace();

            GUIButton changePlatformBtn = new GUIButton(new LocEdString("Set active"));
            platformLayout.AddElement(changePlatformBtn);
            changePlatformBtn.OnClick += ChangeActivePlatform;

            platformBackground.AddElement(background);

            optionsScrollArea = new GUIScrollArea();
            optionsLayout.AddElement(optionsScrollArea);

            GUIButton buildButton = new GUIButton(new LocEdString("Build"));
            optionsLayout.AddFlexibleSpace();
            optionsLayout.AddElement(buildButton);

            buildButton.OnClick += TryStartBuild;

            BuildPlatformOptionsGUI();
        }
Пример #25
0
        /// <summary>
        /// Updates a selection outline drag operation by expanding the outline to the new location. Elements in the outline
        /// are selected.
        /// </summary>
        /// <param name="windowPos">Coordinates of the pointer relative to the window.</param>
        /// <returns>True if the selection outline drag is valid and was updated, false otherwise.</returns>
        private bool UpdateDragSelection(Vector2I windowPos)
        {
            if (!isDraggingSelection)
                return false;

            if (dragSelection == null)
            {
                dragSelection = new GUITexture(null, true, EditorStyles.SelectionArea);
                content.Overlay.AddElement(dragSelection);
            }

            dragSelectionEnd = WindowToScrollAreaCoords(windowPos);

            Rect2I selectionArea = CalculateSelectionArea();
            SelectInArea(selectionArea);
            dragSelection.Bounds = selectionArea;

            return true;
        }
Пример #26
0
        /// <summary>
        /// Updates a selection outline drag operation by expanding the outline to the new location. Elements in the outline
        /// are selected.
        /// </summary>
        /// <param name="scenePos">Coordinates of the pointer relative to the scene.</param>
        /// <returns>True if the selection outline drag is valid and was updated, false otherwise.</returns>
        private bool UpdateDragSelection(Vector2I scenePos)
        {
            if (!isDraggingSelection)
                return false;

            if (dragSelection == null)
            {
                dragSelection = new GUITexture(null, true, EditorStylesInternal.SelectionArea);
                selectionPanel.AddElement(dragSelection);
            }

            dragSelectionEnd = scenePos;

            Rect2I selectionArea = new Rect2I();

            Vector2I min = new Vector2I(Math.Min(dragSelectionStart.x, dragSelectionEnd.x), Math.Min(dragSelectionStart.y, dragSelectionEnd.y));
            Vector2I max = new Vector2I(Math.Max(dragSelectionStart.x, dragSelectionEnd.x), Math.Max(dragSelectionStart.y, dragSelectionEnd.y));
            selectionArea.x = min.x;
            selectionArea.y = min.y;
            selectionArea.width = Math.Max(max.x - min.x, 1);
            selectionArea.height = Math.Max(max.y - min.y, 1);

            dragSelection.Bounds = selectionArea;

            return true;
        }
Пример #27
0
        /// <summary>
        /// Creates a new curve editor GUI elements.
        /// </summary>
        /// <param name="window">Parent window of the GUI element.</param>
        /// <param name="gui">GUI layout into which to place the GUI element.</param>
        /// <param name="width">Width in pixels.</param>
        /// <param name="height">Height in pixels.</param>
        public GUICurveEditor(AnimationWindow window, GUILayout gui, int width, int height)
        {
            this.window = window;
            this.gui = gui;

            this.width = width;
            this.height = height;

            blankContextMenu = new ContextMenu();
            blankContextMenu.AddItem("Add keyframe", AddKeyframeAtPosition);

            blankEventContextMenu = new ContextMenu();
            blankEventContextMenu.AddItem("Add event", AddEventAtPosition);

            keyframeContextMenu = new ContextMenu();
            keyframeContextMenu.AddItem("Delete", DeleteSelectedKeyframes);
            keyframeContextMenu.AddItem("Edit", EditSelectedKeyframe);
            keyframeContextMenu.AddItem("Tangents/Auto", () => { ChangeSelectionTangentMode(TangentMode.Auto); });
            keyframeContextMenu.AddItem("Tangents/Free", () => { ChangeSelectionTangentMode(TangentMode.Free); });
            keyframeContextMenu.AddItem("Tangents/In/Auto", () => { ChangeSelectionTangentMode(TangentMode.InAuto); });
            keyframeContextMenu.AddItem("Tangents/In/Free", () => { ChangeSelectionTangentMode(TangentMode.InFree); });
            keyframeContextMenu.AddItem("Tangents/In/Linear", () => { ChangeSelectionTangentMode(TangentMode.InLinear); });
            keyframeContextMenu.AddItem("Tangents/In/Step", () => { ChangeSelectionTangentMode(TangentMode.InStep); });
            keyframeContextMenu.AddItem("Tangents/Out/Auto", () => { ChangeSelectionTangentMode(TangentMode.OutAuto); });
            keyframeContextMenu.AddItem("Tangents/Out/Free", () => { ChangeSelectionTangentMode(TangentMode.OutFree); });
            keyframeContextMenu.AddItem("Tangents/Out/Linear", () => { ChangeSelectionTangentMode(TangentMode.OutLinear); });
            keyframeContextMenu.AddItem("Tangents/Out/Step", () => { ChangeSelectionTangentMode(TangentMode.OutStep); });

            eventContextMenu = new ContextMenu();
            eventContextMenu.AddItem("Delete", DeleteSelectedEvents);
            eventContextMenu.AddItem("Edit", EditSelectedEvent);

            GUIPanel timelinePanel = gui.AddPanel();
            guiTimeline = new GUIGraphTime(timelinePanel, width, TIMELINE_HEIGHT);

            GUIPanel timelineBgPanel = gui.AddPanel(1);

            GUITexture timelineBackground = new GUITexture(null, EditorStyles.Header);
            timelineBackground.Bounds = new Rect2I(0, 0, width, TIMELINE_HEIGHT + VERT_PADDING);
            timelineBgPanel.AddElement(timelineBackground);

            eventsPanel = gui.AddPanel();
            eventsPanel.SetPosition(0, TIMELINE_HEIGHT + VERT_PADDING);
            guiEvents = new GUIAnimEvents(eventsPanel, width, EVENTS_HEIGHT);

            GUIPanel eventsBgPanel = eventsPanel.AddPanel(1);

            GUITexture eventsBackground = new GUITexture(null, EditorStyles.Header);
            eventsBackground.Bounds = new Rect2I(0, 0, width, EVENTS_HEIGHT + VERT_PADDING);
            eventsBgPanel.AddElement(eventsBackground);

            drawingPanel = gui.AddPanel();
            drawingPanel.SetPosition(0, TIMELINE_HEIGHT + EVENTS_HEIGHT + VERT_PADDING);

            guiCurveDrawing = new GUICurveDrawing(drawingPanel, width, height - TIMELINE_HEIGHT - EVENTS_HEIGHT - VERT_PADDING * 2, curveInfos);
            guiCurveDrawing.SetRange(60.0f, 20.0f);

            GUIPanel sidebarPanel = gui.AddPanel(-10);
            sidebarPanel.SetPosition(0, TIMELINE_HEIGHT + EVENTS_HEIGHT + VERT_PADDING);

            guiSidebar = new GUIGraphValues(sidebarPanel, SIDEBAR_WIDTH, height - TIMELINE_HEIGHT - EVENTS_HEIGHT - VERT_PADDING * 2);
            guiSidebar.SetRange(-10.0f, 10.0f);
        }