/// <summary>
 /// Changes the visual representation of the element as being cut.
 /// </summary>
 /// <param name="enable">True if mark as cut, false to reset to normal.</param>
 public void MarkAsCut(bool enable)
 {
     if (enable)
     {
         icon.SetTint(CUT_COLOR);
     }
     else
     {
         icon.SetTint(Color.White);
     }
 }
 public void SetSelection(bool selected)
 {
     if (selected)
     {
         backgroundTexture.SetTint(Color.DarkCyan);
     }
     else
     {
         backgroundTexture.SetTint(Color.Transparent);
     }
 }
        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 = selectionBtn.Bounds.height;

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

            layouts.background.AddElement(backgroundTexture);
        }
Example #4
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);

            currentCamera = Scene.Camera;
            bool hasMainCamera = currentCamera != null;

            renderTextureGUI.Active = hasMainCamera;
            noCameraLabel.Active    = !hasMainCamera;

            ToggleOnDemandDrawing(EditorApplication.IsOnDemandDrawingEnabled());
            NotifyNeedsRedraw();
        }
        /// <summary>
        /// Changes the visual representation of the element as being selected.
        /// </summary>
        /// <param name="enable">True if mark as selected, false to reset to normal.</param>
        public void MarkAsSelected(bool enable)
        {
            if ((int)underlayState > (int)UnderlayState.Selected)
            {
                return;
            }

            if (enable)
            {
                CreateUnderlay();
                underlay.SetTint(SELECTION_COLOR);
                underlayState = UnderlayState.Selected;
            }
            else
            {
                ClearUnderlay();
                underlayState = UnderlayState.None;
            }
        }
        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(50);

            overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
            layouts.overlay.AddElement(overlaySpacing);
        }
Example #7
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 #8
0
        private void OnInitialize()
        {
            GUILayoutY layout      = GUI.AddLayoutY();
            GUILayoutX titleLayout = layout.AddLayoutX();

            GUIContentImages infoImages = new GUIContentImages(
                EditorBuiltin.GetLogMessageIcon(LogMessageIcon.Info, 16, false),
                EditorBuiltin.GetLogMessageIcon(LogMessageIcon.Info, 16, true));

            GUIContentImages warningImages = new GUIContentImages(
                EditorBuiltin.GetLogMessageIcon(LogMessageIcon.Warning, 16, false),
                EditorBuiltin.GetLogMessageIcon(LogMessageIcon.Warning, 16, true));

            GUIContentImages errorImages = new GUIContentImages(
                EditorBuiltin.GetLogMessageIcon(LogMessageIcon.Error, 16, false),
                EditorBuiltin.GetLogMessageIcon(LogMessageIcon.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;
        }
Example #9
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.GetLogMessageIcon(LogMessageIcon.Info, 32, false));
                    break;

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

                case DebugMessageType.Error:
                case DebugMessageType.CompilerError:
                    icon.SetTexture(EditorBuiltin.GetLogMessageIcon(LogMessageIcon.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 #10
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();
        }
        /// <summary>
        /// Creates a new GUI layout of the specified type, with a texture background.
        /// </summary>
        /// <typeparam name="T">Type of layout to create.</typeparam>
        /// <param name="layout">Parent layout to add the layout to.</param>
        /// <param name="background">Texture to display on the background.</param>
        /// <param name="backgroundColor">Color to apply to the background texture.</param>
        /// <param name="padding">Optional padding to apply between element borders and content.</param>
        /// <returns>New GUI layout with background object.</returns>
        public static GUILayoutWithBackground Create <T>(GUILayout layout, SpriteTexture background, Color backgroundColor,
                                                         RectOffset padding = new RectOffset()) where T : GUILayout, new()
        {
            GUIPanel   mainPanel  = layout.AddPanel();
            GUILayoutX mainLayout = mainPanel.AddLayoutX();

            GUILayout contentLayout;

            if (padding.top > 0 || padding.bottom > 0)
            {
                GUILayoutY paddingVertLayout = mainLayout.AddLayoutY();

                if (padding.top > 0)
                {
                    paddingVertLayout.AddSpace(padding.top);
                }

                if (padding.left > 0 || padding.right > 0)
                {
                    GUILayoutX paddingHorzLayout = paddingVertLayout.AddLayoutX();

                    if (padding.left > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.left);
                    }

                    contentLayout = new T();
                    paddingHorzLayout.AddElement(contentLayout);

                    if (padding.right > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.right);
                    }
                }
                else
                {
                    contentLayout = new T();
                    paddingVertLayout.AddElement(contentLayout);
                }

                if (padding.bottom > 0)
                {
                    paddingVertLayout.AddSpace(padding.bottom);
                }
            }
            else
            {
                if (padding.left > 0 || padding.right > 0)
                {
                    GUILayoutX paddingHorzLayout = mainLayout.AddLayoutX();

                    if (padding.left > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.left);
                    }

                    contentLayout = new T();
                    paddingHorzLayout.AddElement(contentLayout);

                    if (padding.right > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.right);
                    }
                }
                else
                {
                    contentLayout = new T();
                    mainLayout.AddElement(contentLayout);
                }
            }

            GUIPanel   bgPanel   = mainPanel.AddPanel(1);
            GUITexture bgTexture = new GUITexture(Builtin.WhiteTexture);

            bgTexture.SetTint(backgroundColor);
            bgPanel.AddElement(bgTexture);

            return(new GUILayoutWithBackground(mainPanel, contentLayout));
        }