Editor GUI element that displays a list box with user-specified elements and an optional label. List box can be a standard list-box that allows a single element to be selected, or a multi-select list box where any number of elements can be selected at the same time.
Inheritance: GUIElement
Ejemplo n.º 1
0
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            Layout.Clear();

            Bone bone = InspectedObject as Bone;

            if (bone == null)
            {
                return;
            }

            string[] boneNames = GetBoneNames(bone);
            if (boneNames == null)
            {
                boneNames = new string[0];
            }

            boneField = new GUIListBoxField(boneNames, false, new LocEdString("Bone"));

            Layout.AddElement(boneField);

            boneField.OnSelectionChanged += x =>
            {
                selectedBoneName = boneNames[x];

                StartUndo("bone");
                bone.Name = selectedBoneName;
                EndUndo();

                MarkAsModified();
                ConfirmModify();
            };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();

            Bone bone = InspectedObject as Bone;

            if (bone == null)
            {
                return;
            }

            string[] boneNames = GetBoneNames(bone);
            if (boneNames == null)
            {
                boneNames = new string[0];
            }

            boneField = new GUIListBoxField(boneNames, false, new LocEdString("Bone"));

            Layout.AddElement(boneField);

            boneField.OnSelectionChanged += x =>
            {
                selectedBoneName = boneNames[x];
                bone.Name        = selectedBoneName;

                MarkAsModified();
                ConfirmModify();
            };
        }
        /// <inheritdoc/>
        protected internal override void Initialize(int layoutIndex)
        {
            if (property != null)
            {
                guiLayerMaskField = new GUIListBoxField(Layers.Names, true, new GUIContent(title));

                guiLayerMaskField.OnSelectionChanged += x =>
                {
                    ulong  layers = 0;
                    bool[] states = guiLayerMaskField.States;
                    for (int i = 0; i < states.Length; i++)
                    {
                        layers |= states[i] ? Layers.Values[i] : 0;
                    }

                    layersValue = layers;

                    StartUndo();

                    property.SetValue(layers);
                    state |= InspectableState.ModifyInProgress | InspectableState.Modified;

                    EndUndo();
                };

                layout.AddElement(layoutIndex, guiLayerMaskField);
            }
        }
Ejemplo n.º 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>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();

            Renderable renderable = InspectedObject as Renderable;

            if (renderable == null)
            {
                return;
            }

            meshField   = new GUIResourceField(typeof(Mesh), new LocEdString("Mesh"));
            layersField = new GUIListBoxField(Layers.Names, false, new LocEdString("Layer"));

            Layout.AddElement(meshField);
            Layout.AddElement(layersField);

            layersValue    = 0;
            materials      = renderable.Materials;
            materialsField = GUIArrayField <RRef <Material>, MaterialArrayRow> .Create(new LocEdString("Materials"), materials, Layout);

            materialsField.OnChanged += x => { materials = x; };
            materialsField.IsExpanded = Persistent.GetBool("materialsField_Expanded");
            materialsField.OnExpand  += x => Persistent.SetBool("materialsField_Expanded", x);

            meshField.OnChanged += x =>
            {
                Mesh mesh = Resources.Load <Mesh>(x.UUID);
                renderable.Mesh = mesh;

                MarkAsModified();
                ConfirmModify();
            };

            layersField.OnSelectionChanged += x =>
            {
                ulong  layers = 0;
                bool[] states = layersField.States;
                for (int i = 0; i < states.Length; i++)
                {
                    layers |= states[i] ? Layers.Values[i] : 0;
                }

                layersValue       = layers;
                renderable.Layers = layers;

                MarkAsModified();
                ConfirmModify();
            };

            materialsLayout = Layout.AddLayoutY();
            BuildMaterialsGUI();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates necessary GUI elements for selecting a material variation.
        /// </summary>
        /// <param name="material">Material for which to provide variation selection.</param>
        /// <param name="layout">GUI layout to which to append GUI elements.</param>
        internal MaterialVariationGUI(Material material, GUILayout layout)
        {
            this.material = material;
            variation     = material.Variation;

            Shader shader = material.Shader.Value;

            if (shader == null)
            {
                return;
            }

            ShaderVariationParamInfo[] variationParams = shader.VariationParams;
            foreach (var param in variationParams)
            {
                if (param.isInternal)
                {
                    continue;
                }

                LocString[] names  = new LocString[param.values.Length];
                int[]       values = new int[names.Length];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i]  = new LocEdString(param.values[i].name);
                    values[i] = param.values[i].value;
                }

                GUIListBoxField listBox = new GUIListBoxField(names, new LocEdString(param.name));
                listBox.OnSelectionChanged += idx =>
                {
                    int value = values[idx];
                    variation.SetInt(param.identifier, value);

                    material.Variation = variation;
                };

                int curValue = variation.GetInt(param.identifier);
                for (int j = 0; j < values.Length; j++)
                {
                    if (curValue == values[j])
                    {
                        listBox.Index = j;
                        break;
                    }
                }

                layout.AddElement(listBox);
            }
        }
 private static extern void Internal_CreateInstance(GUIListBoxField instance, LocString[] entries, bool multiselect,
     ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle);
Ejemplo n.º 8
0
        private void OnInitialize()
        {
            GUIToggle projectFoldout = new GUIToggle(new LocEdString("Project"), EditorStyles.Foldout);
            GUIToggle editorFoldout  = new GUIToggle(new LocEdString("Editor"), EditorStyles.Foldout);

            projectFoldout.AcceptsKeyFocus = false;
            editorFoldout.AcceptsKeyFocus  = false;

            defaultHandleSizeField            = new GUIFloatField(new LocEdString("Handle size"), 200);
            defaultHandleSizeField.OnChanged += (x) => { EditorSettings.DefaultHandleSize = x; };

            autoLoadLastProjectField            = new GUIToggleField(new LocEdString("Automatically load last project"), 200);
            autoLoadLastProjectField.OnChanged += (x) => { EditorSettings.AutoLoadLastProject = x; };

            CodeEditorType[] availableEditors = CodeEditor.AvailableEditors;
            Array.Resize(ref availableEditors, availableEditors.Length + 1);
            availableEditors[availableEditors.Length - 1] = CodeEditorType.None;

            string[] availableEditorNames = new string[availableEditors.Length];
            for (int i = 0; i < availableEditors.Length; i++)
            {
                availableEditorNames[i] = Enum.GetName(typeof(CodeEditorType), availableEditors[i]);
            }

            codeEditorField = new GUIListBoxField(availableEditorNames, new LocEdString("Code editor"), 200);
            codeEditorField.OnSelectionChanged += x =>
            {
                EditorSettings.SetInt(ActiveCodeEditorKey, (int)availableEditors[x]);
                CodeEditor.ActiveEditor = availableEditors[x];
            };

            fpsLimitField              = new GUIIntField(new LocEdString("FPS limit"), 200);
            fpsLimitField.OnConfirmed += () => EditorSettings.FPSLimit = fpsLimitField.Value;
            fpsLimitField.OnFocusLost += () => EditorSettings.FPSLimit = fpsLimitField.Value;

            mouseSensitivityField            = new GUISliderField(0.2f, 2.0f, new LocEdString("Mouse sensitivity"));
            mouseSensitivityField.OnChanged += (x) => EditorSettings.MouseSensitivity = x;

            GUILayout mainLayout = GUI.AddLayoutY();

            mainLayout.AddElement(projectFoldout);
            GUILayout projectLayoutOuterY = mainLayout.AddLayoutY();

            projectLayoutOuterY.AddSpace(5);
            GUILayout projectLayoutOuterX = projectLayoutOuterY.AddLayoutX();

            projectLayoutOuterX.AddSpace(5);
            GUILayout projectLayout = projectLayoutOuterX.AddLayoutY();

            projectLayoutOuterX.AddSpace(5);
            projectLayoutOuterY.AddSpace(5);

            mainLayout.AddElement(editorFoldout);
            GUILayout editorLayoutOuterY = mainLayout.AddLayoutY();

            editorLayoutOuterY.AddSpace(5);
            GUILayout editorLayoutOuterX = editorLayoutOuterY.AddLayoutX();

            editorLayoutOuterX.AddSpace(5);
            GUILayout editorLayout = editorLayoutOuterX.AddLayoutY();

            editorLayoutOuterX.AddSpace(5);
            editorLayoutOuterY.AddSpace(5);

            mainLayout.AddFlexibleSpace();

            editorLayout.AddElement(defaultHandleSizeField);
            editorLayout.AddElement(autoLoadLastProjectField);
            editorLayout.AddElement(codeEditorField);
            editorLayout.AddElement(fpsLimitField);
            editorLayout.AddElement(mouseSensitivityField);

            projectFoldout.Value = true;
            editorFoldout.Value  = true;

            projectFoldout.OnToggled += (x) => projectLayout.Active = x;
            editorFoldout.OnToggled  += (x) => editorLayout.Active = x;
        }