/// <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.º 2
0
        /// <inheritoc/>
        protected internal override void Initialize(int layoutIndex)
        {
            if (property.Type == SerializableProperty.FieldType.RRef)
            {
                System.Type type = property.InternalType;
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(RRef <>))
                {
                    type = type.GenericTypeArguments[0];
                }

                guiField            = new GUIResourceField(type, new GUIContent(title));
                guiField.OnChanged += OnFieldValueChanged;

                layout.AddElement(layoutIndex, guiField);
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            LoadResource();

            Material material = InspectedObject as Material;

            if (material == null)
            {
                return;
            }

            Shader        activeShader = material.Shader.Value;
            BuiltinShader builtinType  = ShaderToBuiltin(activeShader);

            builtinShaderField       = new GUIEnumField(typeof(BuiltinShader), new LocEdString("Shader"));
            builtinShaderField.Value = (ulong)builtinType;
            builtinShaderField.OnSelectionChanged += x =>
            {
                BuiltinShader newBuiltinType = (BuiltinShader)x;

                material.Shader = Builtin.GetShader(newBuiltinType);
                EditorApplication.SetDirty(material);
                RebuildParamGUI(material);

                bool newIsCustom = newBuiltinType == BuiltinShader.Custom;
                shaderField.Active = newIsCustom;
            };

            shaderField            = new GUIResourceField(typeof(Shader), new LocEdString("Shader file"));
            shaderField.ValueRef   = material.Shader;
            shaderField.OnChanged += (x) =>
            {
                Shader shader = Resources.Load <Shader>(x.UUID);

                material.Shader = shader;
                EditorApplication.SetDirty(material);
                RebuildParamGUI(material);
            };

            bool isCustom = builtinType == BuiltinShader.Custom;

            shaderField.Active = isCustom;

            RebuildParamGUI(material);
        }
Ejemplo n.º 4
0
 private static extern void Internal_CreateInstance(GUIResourceField instance, Type type, ref GUIContent title,
                                                    int titleWidth, string style, GUIOption[] options, bool withTitle);
Ejemplo n.º 5
0
        /// <summary>
        /// (Re)creates GUI with platform-specific options.
        /// </summary>
        private void BuildPlatformOptionsGUI()
        {
            optionsScrollArea.Layout.Clear();
            GUILayout layout = optionsScrollArea.Layout;

            PlatformInfo platformInfo = BuildManager.GetPlatformInfo(selectedPlatform);

            GUILabel options = new GUILabel(new LocEdString("Platform options"), EditorStyles.LabelCentered);

            GUIResourceField sceneField  = new GUIResourceField(typeof(Prefab), new LocEdString("Startup scene"));
            GUIToggleField   debugToggle = new GUIToggleField(new LocEdString("Debug"));

            GUIToggleField fullscreenField = new GUIToggleField(new LocEdString("Fullscreen"));
            GUIIntField    widthField      = new GUIIntField(new LocEdString("Window width"));
            GUIIntField    heightField     = new GUIIntField(new LocEdString("Window height"));

            GUITextField definesField = new GUITextField(new LocEdString("Defines"));

            layout.AddSpace(5);
            layout.AddElement(options);
            layout.AddSpace(5);
            layout.AddElement(sceneField);
            layout.AddElement(debugToggle);
            layout.AddElement(fullscreenField);
            layout.AddElement(widthField);
            layout.AddElement(heightField);
            layout.AddSpace(5);
            layout.AddElement(definesField);
            layout.AddSpace(5);

            sceneField.ValueRef   = platformInfo.MainScene;
            debugToggle.Value     = platformInfo.Debug;
            definesField.Value    = platformInfo.Defines;
            fullscreenField.Value = platformInfo.Fullscreen;
            widthField.Value      = platformInfo.WindowedWidth;
            heightField.Value     = platformInfo.WindowedHeight;

            if (platformInfo.Fullscreen)
            {
                widthField.Active  = false;
                heightField.Active = false;
            }

            sceneField.OnChanged      += x => platformInfo.MainScene = x.As <Prefab>();
            debugToggle.OnChanged     += x => platformInfo.Debug = x;
            definesField.OnChanged    += x => platformInfo.Defines = x;
            fullscreenField.OnChanged += x =>
            {
                widthField.Active  = !x;
                heightField.Active = !x;

                platformInfo.Fullscreen = x;
            };
            widthField.OnChanged  += x => platformInfo.WindowedWidth = x;
            heightField.OnChanged += x => platformInfo.WindowedHeight = x;

            switch (platformInfo.Type)
            {
            case PlatformType.Windows:
            {
                WinPlatformInfo winPlatformInfo = (WinPlatformInfo)platformInfo;

                GUITextField titleField = new GUITextField(new LocEdString("Title"));

                layout.AddElement(titleField);
                layout.AddSpace(5);

                GUITextureField iconField = new GUITextureField(new LocEdString("Icon"));
                layout.AddElement(iconField);

                titleField.Value     = winPlatformInfo.TitleText;
                iconField.TextureRef = winPlatformInfo.Icon;

                titleField.OnChanged += x => winPlatformInfo.TitleText = x;
                iconField.OnChanged  += x => winPlatformInfo.Icon = x.As <Texture>();
            }
            break;
            }
        }