Ejemplo n.º 1
0
        public VisualElement GetVisualElement()
        {
            VisualElement visualElement = new VisualElement();

            m_NameElement = new Foldout();
            m_NameElement.AddToClassList("sub-header-1");
            m_NameElement.Add(visualElement);

            m_NameElement.RegisterCallback <MouseEnterEvent>(_ => OnSelected());

            SetBaseVisualElement(visualElement);

            m_DeleteButton = new Button(() => m_DeleteAction(Blueprint, m_NameElement));
            m_DeleteButton.AddToClassList("delete");
            visualElement.Add(m_DeleteButton);

            UpdateName();
            UpdateDeleteButton();
            return(m_NameElement);
        }
        public NoiseEditorView(NoiseSettings _noiseUpdateTarget_ = null, NoiseSettings _sourceAsset_ = null)
        {
            // create temp noisesettings asset and the IMGUI view for this window
            m_noiseUpdateTarget = _noiseUpdateTarget_ == null?ScriptableObject.CreateInstance <NoiseSettings>() : _noiseUpdateTarget_;

            m_serializedNoiseProfile = new SerializedObject(m_noiseUpdateTarget);
            m_noiseGUI = new NoiseSettingsGUI();
            m_noiseGUI.Init(m_noiseUpdateTarget);

            m_noiseSourceAsset = _sourceAsset_;

            var stylesheet = EditorGUIUtility.isProSkin ?
                             AssetDatabase.LoadAssetAtPath <StyleSheet>("Packages/com.unity.terrain-tools/Editor/TerrainTools/NoiseLib/Styles/Noise_Dark.uss") :
                             AssetDatabase.LoadAssetAtPath <StyleSheet>("Packages/com.unity.terrain-tools/Editor/TerrainTools/NoiseLib/Styles/Noise_Light.uss");

            var settingsScrollView = new ScrollView()
            {
                name = Styles.settingsScrollViewName
            };

            ///////////////////////////////////////////////////////////////////////////////
            // settings buttons
            ///////////////////////////////////////////////////////////////////////////////

            var noiseGUIContainer = new IMGUIContainer()
            {
                name = Styles.noiseGUIContainerName
            };

            noiseGUIContainer.onGUIHandler = () =>
            {
                EditorGUI.BeginChangeCheck();
                {
                    m_noiseGUI.OnGUI(NoiseSettingsGUIFlags.All & (~NoiseSettingsGUIFlags.Preview));
                }
                bool changed = EditorGUI.EndChangeCheck();

                if (changed)
                {
                    INTERNAL_OnSettingsChanged();
                }
            };
            settingsScrollView.Add(noiseGUIContainer);

            ///////////////////////////////////////////////////////////////////////////////
            // settings buttons
            ///////////////////////////////////////////////////////////////////////////////

            filePanelContainer = new VisualElement()
            {
                name  = Styles.saveButtonsContainer,
                style =
                {
                    flexDirection = FlexDirection.Row
                }
            };
            filePanelContainer.AddToClassList(Styles.filePanelContainer);

            saveAsButton = new Button(SaveAsCallback)
            {
                name    = Styles.saveAsButtonName,
                text    = "Save As",
                tooltip = Styles.saveasTooltip
            };
            saveAsButton.AddToClassList(Styles.filePanelButton);

            revertButton = new Button(ResetRevertCallback)
            {
                name    = Styles.resetButtonName,
                text    = "Reset",
                tooltip = Styles.resetTooltip
            };
            revertButton.AddToClassList(Styles.filePanelButton);

            applyButton = new Button(() => { Undo.RecordObject(m_noiseSourceAsset, "NoiseWindow - Apply Settings"); m_noiseSourceAsset.CopySerialized(m_noiseUpdateTarget); })
            {
                name    = Styles.applyButtonName,
                text    = "Apply",
                tooltip = Styles.applyTooltip
            };
            applyButton.AddToClassList(Styles.filePanelButton);
            applyButton.AddToClassList(Styles.filePanelButton);

            ///////////////////////////////////////////////////////////////////////////////
            // noise settings object field
            ///////////////////////////////////////////////////////////////////////////////

            var objectFieldContainer = new VisualElement()
            {
                name = Styles.objectFieldContainer
            };

            objectFieldContainer.AddToClassList(Styles.objectFieldContainer);

            objectField = new ObjectField()
            {
                name = Styles.noiseAssetFieldName,
                allowSceneObjects = false,
                objectType        = typeof(NoiseSettings),
                label             = Styles.noiseAssetFieldLabel,
                tooltip           = Styles.noiseAssetFieldTooltip //,
                                                                  // viewDataKey = Styles.noiseAssetFieldName
            };
            objectField.AddToClassList(Styles.noiseAssetFieldName);
            objectField.RegisterCallback <ChangeEvent <UnityEngine.Object> >(OnSourceProfileChanged);

            objectFieldContainer.Add(objectField);

            ///////////////////////////////////////////////////////////////////////////////
            // export settings
            ///////////////////////////////////////////////////////////////////////////////

            var flexArea = new VisualElement()
            {
                name = Styles.flexArea
            };

            flexArea.AddToClassList(Styles.flexArea);

            var exportContainer = new VisualElement()
            {
                name = Styles.exportContainer
            };

            exportContainer.AddToClassList(Styles.exportContainer);

            var exportHeader = new Foldout()
            {
                name        = Styles.exportHeader,
                text        = "Export Noise to Texture",
                tooltip     = Styles.exportTooltip,
                viewDataKey = Styles.exportHeader
            };

            exportHeader.RegisterCallback <ChangeEvent <bool> >(
                (evt) =>
            {
                if (evt.newValue)
                {
                    m_exportContainer.Add(m_exportSettings);
                    m_exportContainer.Add(m_exportButton);
                }
                else
                {
                    m_exportContainer.Remove(m_exportSettings);
                    m_exportContainer.Remove(m_exportButton);
                }
            }
                );
            exportHeader.AddToClassList(Styles.foldoutContainer);

            var exportSettings = CreateExportSettingsView();

            var exportButton = new Button(
                () =>
            {
                if (m_exportType.value == ExportTextureType.Texture2D)
                {
                    Export2D();
                }
                else if (m_exportType.value == ExportTextureType.Texture3D)
                {
                    Export3D();
                }
            }
                )
            {
                name = Styles.exportButton,
                text = "Export"
            };

            exportButton.AddToClassList(Styles.exportButton);

            m_exportButton = exportButton;
            exportContainer.Add(exportHeader);
            // exportContainer.Add( exportSettings );
            // exportContainer.Add( exportButton );

            m_exportContainer  = exportContainer;
            exportHeader.value = false;

            // container for the settings panel
            var settingsContainer = new VisualElement()
            {
                name = Styles.settingsContainerName
            };

            settingsContainer.AddToClassList(Styles.settingsContainerName);
            settingsContainer.Add(objectFieldContainer);
            settingsContainer.Add(filePanelContainer);
            settingsContainer.Add(settingsScrollView);
            settingsContainer.Add(flexArea); // add this so the export stuff stays at the bottom of the settings container
            settingsContainer.Add(exportContainer);
            settingsContainer.Bind(m_serializedNoiseProfile);

            ///////////////////////////////////////////////////////////////////////////////
            // settings buttons
            ///////////////////////////////////////////////////////////////////////////////

            var previewContainer = new VisualElement()
            {
                name = Styles.noisePreviewContainerName
            };

            previewContainer.AddToClassList(Styles.noisePreviewContainerName);

            var previewLabel = new Label()
            {
                name    = Styles.noisePreviewLabelName,
                text    = Styles.previewLabel,
                tooltip = Styles.previewLabelTooltip
            };

            previewLabel.AddToClassList(Styles.noisePreviewLabelName);
            previewContainer.Add(previewLabel);

            m_noiseFieldView = new NoiseFieldView(m_serializedNoiseProfile)
            {
                name = Styles.noisePreviewTextureName
            };
            m_noiseFieldView.onGUIHandler += () =>
            {
                INTERNAL_OnSettingsChanged();
            };
            m_noiseFieldView.AddToClassList(Styles.noisePreviewTextureName);
            previewContainer.Add(m_noiseFieldView);

            ///////////////////////////////////////////////////////////////////////////////
            // wrap it all up
            ///////////////////////////////////////////////////////////////////////////////

            styleSheets.Add(stylesheet);
            AddToClassList(Styles.noiseWindowName);
            Add(settingsContainer);
            Add(previewContainer);

            this.Bind(m_serializedNoiseProfile);

            m_settingsContainer = settingsContainer;

            INTERNAL_OnSourceProfileChanged(_sourceAsset_);

            this.viewDataKey = Styles.noiseWindowName;
        }
Ejemplo n.º 3
0
        protected sealed override void SetupUI()
        {
            var replicatorRowAsset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_ReplicatorRowPath);

            replicatorRowAsset.CloneTree(this);

            base.SetupUI();

            m_ContentContainer = this.Q <VisualElement>(k_ContentContainerName);

            m_Foldout = this.Q <Foldout>(k_RowFoldoutName);
            m_Foldout.RegisterValueChangedCallback(evt =>
            {
                var expanded = evt.newValue;
                m_ContentContainer.style.display = expanded ? DisplayStyle.Flex : DisplayStyle.None;
                if (expanded)
                {
                    RulesModule.CollapsedNodes.Remove(BackingObject);
                }
                else
                {
                    RulesModule.CollapsedNodes.Add(BackingObject);
                }

                RulesDrawer.BuildReplicatorsList();
            });

            m_Foldout.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject);

            if (IsGroup)
            {
                m_Foldout.visible = false;
            }
            else
            {
                var expanded = !RulesModule.CollapsedNodes.Contains(BackingObject);
                m_Foldout.value = expanded;
                m_ContentContainer.style.display = expanded ? DisplayStyle.Flex : DisplayStyle.None;
            }

            m_MatchCountEnum = this.Q <EnumField>(k_MatchCountEnum);
            m_MatchCountEnum.Init(RulesModule.ReplicatorCountOption.Every);
            m_MatchCountEnum.RegisterCallback <ChangeEvent <System.Enum> >(OnChangeMatchCountDropdown);

            m_MaxCountField = this.Q <IntegerField>(k_MaxInstancesName);
            m_MaxCountField.RegisterValueChangedCallback(OnMaxInstanceChanged);

            m_MaxCountField.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject);

            SetupProxyPresetUI(m_Entity);

            m_GroupDrillInButton          = this.Q <Button>(k_GroupDrillIn);
            m_GroupDrillInButton.clicked += () =>
            {
                var ruleSet = m_Entity.GetComponent <ProxyRuleSet>();
                RulesModule.RuleSetInstance = ruleSet;
                RulesDrawer.BuildReplicatorsList();
            };

            if (!IsGroup)
            {
                m_GroupDrillInButton.style.display = DisplayStyle.None;
            }

            m_SimMatchCount = this.Q <Label>(k_SimMatchCountName);

            SetupReplicatorRow();

            if (IsGroup)
            {
                m_AddButtonHoverElement.SetEnabled(false);
            }

            CreateAddContentButton();

            RegisterCallback <KeyDownEvent>(OnKeyDown);
        }