private static void AddComponentSyncSettingFields(VisualElement parent, GUIContent content,
                                                          ComponentSyncSettings componentSyncSettings)
        {
            VisualTreeAsset template = UIElementsEditorUtility.LoadVisualTreeAsset(
                Constants.COMPONENT_SYNC_FIELDS_TEMPLATE_PATH);
            TemplateContainer templateInstance = template.CloneTree();
            VisualElement     fieldContainer   = templateInstance.Query <VisualElement>("FieldContainer").First();


            Label label = templateInstance.Query <Label>().First();

            label.text    = content.text;
            label.tooltip = content.tooltip;

            Toggle createToggle = templateInstance.Query <Toggle>("CreateToggle").First();

            Assert.IsNotNull(createToggle);

            createToggle.SetValueWithoutNotify(componentSyncSettings.CanCreate);
            createToggle.RegisterValueChangedCallback((ChangeEvent <bool> changeEvent) => {
                componentSyncSettings.CanCreate = changeEvent.newValue;
            });

            Toggle updateToggle = templateInstance.Query <Toggle>("UpdateToggle").First();

            Assert.IsNotNull(updateToggle);
            updateToggle.SetValueWithoutNotify(componentSyncSettings.CanUpdate);
            updateToggle.RegisterValueChangedCallback((ChangeEvent <bool> changeEvent) => {
                componentSyncSettings.CanUpdate = changeEvent.newValue;
            });

            parent.Add(fieldContainer);
        }
Ejemplo n.º 2
0
        internal static VisualElement Create(UIElementsSamples.SampleTreeItem item)
        {
            var panelContainer = new ScrollView();

            panelContainer.name = s_StylesExplorerName;
            panelContainer.AddToClassList(s_StylesExplorerClassName);

            var innerContainer = new VisualElement();

            panelContainer.Add(innerContainer);
            innerContainer.AddToClassList(s_ScrollViewContainerClassName);
            innerContainer.RegisterCallback <GeometryChangedEvent>(ContainerGeometryChange);
            ContainerSetColumnCount(innerContainer);

            var leftPanel  = CreatePanel();
            var rightPanel = CreatePanel();

            leftPanel.AddToClassList(s_StylePanelDarkClassName);
            rightPanel.AddToClassList(s_StylePanelLightClassName);

            leftPanel.styleSheets.Add(UIElementsEditorUtility.GetCommonDarkStyleSheet());
            rightPanel.styleSheets.Add(UIElementsEditorUtility.GetCommonLightStyleSheet());

            innerContainer.Add(leftPanel);
            innerContainer.Add(rightPanel);

            return(panelContainer);
        }
Ejemplo n.º 3
0
        protected void OnEnterPanel()
        {
            var p = panel as BaseVisualElementPanel;

            if (p != null)
            {
                if (graphViewShader == null)
                {
                    graphViewShader = EditorGUIUtility.LoadRequired("GraphView/GraphViewUIE.shader") as Shader;
                }
                p.standardShader = graphViewShader;
                HostView ownerView = p.ownerObject as HostView;
                if (ownerView != null && ownerView.actualView != null)
                {
                    ownerView.actualView.antiAliasing = 4;
                }

                // Changing the updaters is assumed not to be a normal use case, except maybe for Unity debugging
                // purposes. For that reason, we don't track updater changes.
                Panel.BeforeUpdaterChange += OnBeforeUpdaterChange;
                Panel.AfterUpdaterChange  += OnAfterUpdaterChange;
                UpdateDrawChainRegistration(true);
            }

            // Force DefaultCommonDark.uss since GraphView only has a dark style at the moment
            UIElementsEditorUtility.ForceDarkStyleSheet(this);
        }
//----------------------------------------------------------------------------------------------------------------------

        private MeshSyncUserSettingsProvider() : base(USER_SETTINGS_MENU_PATH, SettingsScope.User)
        {
            //activateHandler is called when the user clicks on the Settings item in the Settings window.

            activateHandler = (string searchContext, VisualElement root) => {
                m_dccToolsSettingsTab = new DCCToolsSettingsTab();


                //Main Tree
                VisualTreeAsset main = UIElementsEditorUtility.LoadVisualTreeAsset(MeshSyncEditorConstants.MAIN_USER_SETTINGS_PATH);
                Assert.IsNotNull(main);
                main.CloneTree(root);

                //Style
                UIElementsEditorUtility.LoadAndAddStyle(root.styleSheets, MeshSyncEditorConstants.USER_SETTINGS_STYLE_PATH);

                VisualElement content = root.Query <VisualElement>("Content");
                if (null == content)
                {
                    Debug.LogError("MeshSync: Can't create User Settings");
                    return;
                }
                m_dccToolsSettingsTab.Setup(content);
            };

            deactivateHandler = () => {
            };

            //keywords
            HashSet <string> meshSyncKeywords = new HashSet <string>(new[] { "MeshSync", });

            keywords = meshSyncKeywords;
        }
Ejemplo n.º 5
0
        public static void FlagStyleSheetChange()
        {
            // clear caches that depend on loaded style sheets
            UnityEngine.UIElements.StyleSheets.StyleSheetCache.ClearCaches();

            // for now we don't bother tracking which panel depends on which style sheet
            var iterator = UIElementsUtility.GetPanelsIterator();

            while (iterator.MoveNext())
            {
                var panel = iterator.Current.Value;

                // In-game doesn't support styling
                if (panel.contextType != ContextType.Editor)
                {
                    continue;
                }

                // Reload default style sheets to resolve variables if they changed
                UIElementsEditorUtility.ReloadDefaultEditorStyleSheets();
                panel.DirtyStyleSheets();

                var guiView = panel.ownerObject as GUIView;
                if (guiView != null)
                {
                    guiView.Repaint();
                }
            }
        }
//----------------------------------------------------------------------------------------------------------------------
        public void Setup(VisualElement root)
        {
            VisualTreeAsset   tab         = UIElementsEditorUtility.LoadVisualTreeAsset(Constants.SCENE_CACHE_PLAYER_SETTINGS_TAB_PATH);
            TemplateContainer tabInstance = tab.CloneTree();

            VisualElement content = tabInstance.Query <VisualElement>("Content").First();

            m_generatedSCResPathTextField = tabInstance.Query <TextField>("GeneratedSCResPathText").First();
            m_generatedSCResPathTextField.RegisterValueChangedCallback((ChangeEvent <string> changeEvent) => {
                MeshSyncRuntimeSettings settings = MeshSyncRuntimeSettings.GetOrCreateSettings();
                settings.SetSceneCacheOutputPath(changeEvent.newValue);
                settings.SaveSettings();
            });

            m_outputPathSelectButton          = tabInstance.Query <Button>("OutputPathSelectButton").First();
            m_outputPathSelectButton.clicked += OnOutputPathSelectButtonClicked;
            RefreshSettings();

            //MeshSyncPlayerConfig
            MeshSyncPlayerConfigSection section = new MeshSyncPlayerConfigSection(MeshSyncPlayerType.CACHE_PLAYER);

            section.Setup(content);

            root.Add(tabInstance);
        }
Ejemplo n.º 7
0
        private static StyleSheet LoadAndResolveStyleSheet(bool isDarkTheme)
        {
            var styleSheet = ScriptableObject.CreateInstance <StyleSheet>();

            styleSheet.hideFlags         = HideFlags.HideAndDontSave;
            styleSheet.isUnityStyleSheet = true;

            var packageManagerThemeVariablesSheetPath = isDarkTheme ? k_PackageManagerDarkVariablesSheetPath : k_PackageManagerLightVariablesSheetPath;
            var variablesThemeStyleSheetPath          = isDarkTheme ? UIElementsEditorUtility.s_DefaultCommonDarkStyleSheetPath : UIElementsEditorUtility.s_DefaultCommonLightStyleSheetPath;
            var extensionThemeStyleSheetPath          = isDarkTheme ? k_ExtensionDarkVariablesSheetPath : k_ExtensionLightVariablesSheetPath;

            var packageManagerCommon = EditorGUIUtility.Load(k_PackageManagerCommonStyleSheetPath) as StyleSheet;
            var packageManagerTheme  = EditorGUIUtility.Load(packageManagerThemeVariablesSheetPath) as StyleSheet;

            var packageManagerStyles = k_PackageManagerStyleSheetPaths.Select(p => EditorGUIUtility.Load(p) as StyleSheet).ToArray();

            var variableThemeSheet       = EditorGUIUtility.Load(UIElementsEditorUtility.GetStyleSheetPathForCurrentFont(variablesThemeStyleSheetPath)) as StyleSheet;
            var extensionThemeStyleSheet = EditorGUIUtility.Load(extensionThemeStyleSheetPath) as StyleSheet;

            var resolver = new StyleSheets.StyleSheetResolver();

            resolver.AddStyleSheets(variableThemeSheet, extensionThemeStyleSheet, packageManagerCommon, packageManagerTheme);
            resolver.AddStyleSheets(packageManagerStyles);
            resolver.ResolveTo(styleSheet);

            return(styleSheet);
        }
Ejemplo n.º 8
0
        public void CheckUserSettingUIElements()
        {
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.MAIN_USER_SETTINGS_PATH));
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.DCC_TOOLS_SETTINGS_CONTAINER_PATH));
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.DCC_TOOL_INFO_TEMPLATE_PATH));

            Assert.IsNotNull(LoadStyleSheet(Constants.USER_SETTINGS_STYLE_PATH));
        }
 public static bool IsUnityEditorStyleSheet(this StyleSheet styleSheet)
 {
     if ((UIElementsEditorUtility.IsCommonDarkStyleSheetLoaded() && styleSheet == UIElementsEditorUtility.GetCommonDarkStyleSheet()) ||
         (UIElementsEditorUtility.IsCommonLightStyleSheetLoaded() && styleSheet == UIElementsEditorUtility.GetCommonLightStyleSheet()))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 10
0
        void OnEnterPanel(AttachToPanelEvent e)
        {
            // Force DefaultCommonDark.uss since GraphView only has a dark style at the moment
            UIElementsEditorUtility.ForceDarkStyleSheet(this);

            if (isReframable)
            {
                panel.visualTree.RegisterCallback <KeyDownEvent>(OnKeyDownShortcut);
            }
        }
Ejemplo n.º 11
0
//----------------------------------------------------------------------------------------------------------------------

        MeshSyncSettingsProvider() : base(PROJECT_SETTINGS_MENU_PATH, SettingsScope.Project)
        {
            m_tabs = new IMeshSyncSettingsTab[MeshSyncEditorConstants.MAX_SETTINGS_TAB];
            Button[] tabButtons = new Button[MeshSyncEditorConstants.MAX_SETTINGS_TAB];
            m_tabs[MeshSyncEditorConstants.GENERAL_SETTINGS_TAB]   = new GeneralSettingsTab();
            m_tabs[MeshSyncEditorConstants.DCC_TOOLS_SETTINGS_TAB] = new DCCToolsSettingsTab();

            //activateHandler is called when the user clicks on the Settings item in the Settings window.
            activateHandler = (string searchContext, VisualElement root) => {
                //Main Tree
                VisualTreeAsset main = UIElementsEditorUtility.LoadVisualTreeAsset(
                    Path.Combine(MeshSyncEditorConstants.PROJECT_SETTINGS_UIELEMENTS_PATH, "ProjectSettings_Main")
                    );
                main.CloneTree(root);


                //Tab Buttons
                VisualElement   tabsContainer     = root.Query <VisualElement>("TabsContainer");
                VisualTreeAsset tabButtonTemplate = UIElementsEditorUtility.LoadVisualTreeAsset(
                    Path.Combine(MeshSyncEditorConstants.PROJECT_SETTINGS_UIELEMENTS_PATH, "TabButtonTemplate")
                    );

                tabButtons[0] = CreateButton(tabButtonTemplate, Contents.GeneralSettings, OnGeneralSettingsTabClicked);
                tabButtons[1] = CreateButton(tabButtonTemplate, Contents.DCCTools, OnDCCToolsTabClicked);

                foreach (Button tabButton in tabButtons)
                {
                    tabsContainer.Add(tabButton);
                }

                //Style
                UIElementsEditorUtility.LoadAndAddStyle(
                    root.styleSheets,
                    Path.Combine(MeshSyncEditorConstants.PROJECT_SETTINGS_UIELEMENTS_PATH, "ProjectSettings_Style")
                    );


                m_content = root.Query <VisualElement>("Content");
                UpdateSelectedTabButton(tabButtons[0]);
                SetupTab(MeshSyncEditorConstants.GENERAL_SETTINGS_TAB);
            };


            deactivateHandler = () => {
                SetupTab(MeshSyncEditorConstants.UNINITIALIZED_TAB);
            };

            //keywords
            HashSet <string> meshSyncKeywords = new HashSet <string>(new[] { "MeshSync", });

            meshSyncKeywords.UnionWith(GetSearchKeywordsFromGUIContentProperties <MeshSyncSettingsProvider.Contents>());
            meshSyncKeywords.UnionWith(GetSearchKeywordsFromGUIContentProperties <GeneralSettingsTab.Contents>());

            keywords = meshSyncKeywords;
        }
        public void VerifyUIElementsResources()
        {
            VisualTreeAsset main = UIElementsEditorUtility.LoadVisualTreeAsset(SISEditorConstants.MAIN_USER_SETTINGS_PATH);

            Assert.IsNotNull(main);

            //Style
            StyleSheet styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>(SISEditorConstants.USER_SETTINGS_STYLE_PATH + ".uss");

            Assert.IsNotNull(styleSheet);
        }
Ejemplo n.º 13
0
//----------------------------------------------------------------------------------------------------------------------

        //Support Toggle, FloatField, etc
        private F AddField <F, V>(VisualElement parent, GUIContent content,
                                  V initialValue, Action <V> onValueChanged) where F : VisualElement, INotifyValueChanged <V>, new()
        {
            F field = UIElementsEditorUtility.AddField <F, V>(parent, content, initialValue, (ChangeEvent <V> changeEvent) => {
                onValueChanged(changeEvent.newValue);
                MeshSyncProjectSettings.GetOrCreateInstance().SaveInEditor();
            });

            field.AddToClassList("project-settings-field");
            return(field);
        }
Ejemplo n.º 14
0
        public void CheckProjectSettingUIElements()
        {
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.MAIN_PROJECT_SETTINGS_PATH));
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.SERVER_SETTINGS_TAB_PATH));
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.SCENE_CACHE_PLAYER_SETTINGS_TAB_PATH));
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.TAB_BUTTON_TEMPLATE_PATH));
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.PROJECT_SETTINGS_FIELD_TEMPLATE_PATH));
            Assert.IsNotNull(UIElementsEditorUtility.LoadVisualTreeAsset(Constants.MESHSYNC_PLAYER_CONFIG_CONTAINER_PATH));

            Assert.IsNotNull(LoadStyleSheet(Constants.PROJECT_SETTINGS_STYLE_PATH));
        }
Ejemplo n.º 15
0
        public PanelSplitter(VisualElement affectedElement)
        {
            m_AffectedElement = affectedElement;

            style.cursor   = UIElementsEditorUtility.CreateDefaultCursorStyle(MouseCursor.ResizeHorizontal);
            style.width    = k_SplitterWidth;
            style.minWidth = k_SplitterWidth;
            style.maxWidth = k_SplitterWidth;

            RegisterCallback <MouseDownEvent>(OnMouseDown, Capture.Capture);
            RegisterCallback <MouseMoveEvent>(OnMouseMove, Capture.Capture);
            RegisterCallback <MouseUpEvent>(OnMouseUp, Capture.Capture);
        }
Ejemplo n.º 16
0
        public void AddFields()
        {
            VisualElement parent = new VisualElement();

            GUIContent   content  = new GUIContent("My field");
            IntegerField intField = UIElementsEditorUtility.AddField <IntegerField, int>(parent, content, 100, null);

            Assert.IsNotNull(intField);
            PopupField <int> popupField = UIElementsEditorUtility.AddPopupField(parent, content, new List <int> {
                0, 1, 2, 3, 4
            }, 0, null);

            Assert.IsNotNull(popupField);
        }
Ejemplo n.º 17
0
//----------------------------------------------------------------------------------------------------------------------

        MeshSyncProjectSettingsProvider() : base(PROJECT_SETTINGS_MENU_PATH, SettingsScope.Project)
        {
            m_tabs = new IMeshSyncSettingsTab[MeshSyncEditorConstants.MAX_SETTINGS_TAB];
            Button[] tabButtons = new Button[MeshSyncEditorConstants.MAX_SETTINGS_TAB];
            m_tabs[MeshSyncEditorConstants.SERVER_SETTINGS_TAB]             = new ServerSettingsTab();
            m_tabs[MeshSyncEditorConstants.SCENE_CACHE_PLAYER_SETTINGS_TAB] = new SceneCachePlayerSettingsTab();

            //activateHandler is called when the user clicks on the Settings item in the Settings window.
            activateHandler = (string searchContext, VisualElement root) => {
                //Main Tree
                VisualTreeAsset main = UIElementsEditorUtility.LoadVisualTreeAsset(Constants.MAIN_PROJECT_SETTINGS_PATH);
                main.CloneTree(root);

                //Tab Buttons
                VisualElement   tabsContainer = root.Query <VisualElement>("TabsContainer");
                VisualTreeAsset btnTemplate   = UIElementsEditorUtility.LoadVisualTreeAsset(Constants.TAB_BUTTON_TEMPLATE_PATH);

                tabButtons[0] = CreateButton(btnTemplate, Contents.Server, OnServerSettingsTabClicked);
                tabButtons[1] = CreateButton(btnTemplate, Contents.SceneCachePlayer, OnSceneCachePlayerTabClicked);

                foreach (Button tabButton in tabButtons)
                {
                    tabsContainer.Add(tabButton);
                }

                //Style
                UIElementsEditorUtility.LoadAndAddStyle(root.styleSheets, Constants.PROJECT_SETTINGS_STYLE_PATH);


                m_content = root.Query <VisualElement>("Content");
                UpdateSelectedTabButton(tabButtons[0]);
                SetupTab(MeshSyncEditorConstants.SERVER_SETTINGS_TAB);
            };


            deactivateHandler = () => {
                SetupTab(MeshSyncEditorConstants.UNINITIALIZED_TAB);
            };

            //keywords
            HashSet <string> meshSyncKeywords = new HashSet <string>(new[] { "MeshSync", });

            meshSyncKeywords.UnionWith(GetSearchKeywordsFromGUIContentProperties <MeshSyncProjectSettingsProvider.Contents>());
            meshSyncKeywords.UnionWith(GetSearchKeywordsFromGUIContentProperties <ServerSettingsTab.Contents>());
            meshSyncKeywords.UnionWith(GetSearchKeywordsFromGUIContentProperties <SceneCachePlayerSettingsTab.Contents>());
            meshSyncKeywords.UnionWith(GetSearchKeywordsFromGUIContentProperties <MeshSyncPlayerConfigSection.Contents>());

            keywords = meshSyncKeywords;
        }
Ejemplo n.º 18
0
        private VisualElement CreateRoot <TMode>() where TMode : EditorMode
        {
            var type        = typeof(TMode);
            var namePostfix = type == typeof(DefaultEditorMode) ? "" : "-" + type.Name;
            var name        = "rootVisualContainer" + namePostfix;
            var root        = new VisualElement()
            {
                name           = VisualElementUtils.GetUniqueName(name),
                pickingMode    = PickingMode.Ignore, // do not eat events so IMGUI gets them
                persistenceKey = name
            };

            UIElementsEditorUtility.AddDefaultEditorStyleSheets(root);
            return(root);
        }
Ejemplo n.º 19
0
        private static VisualElement CreateRoot()
        {
            var name = "rootVisualContainer";
            var root = new VisualElement()
            {
                name        = VisualElementUtils.GetUniqueName(name),
                pickingMode = PickingMode.Ignore, // do not eat events so IMGUI gets them
                viewDataKey = name,
                renderHints = RenderHints.ClipWithScissors
            };

            root.pseudoStates |= PseudoStates.Root;
            UIElementsEditorUtility.AddDefaultEditorStyleSheets(root);
            root.style.overflow = UnityEngine.UIElements.Overflow.Hidden;
            return(root);
        }
Ejemplo n.º 20
0
        void OnAddDCCToolButtonClicked(EventBase evt)
        {
            string path = null;

            if (Application.platform == RuntimePlatform.OSXEditor)
            {
                path = OpenFilePanel();
            }
            else
            {
                path = OpenFolderPanel();
            }

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            //Find the path to the actual app
            DCCToolType lastDCCToolType = DCCToolType.AUTODESK_MAYA;
            DCCToolInfo dccToolInfo     = null;

            for (int i = 0; i < (int)(DCCToolType.NUM_DCC_TOOL_TYPES) && null == dccToolInfo; ++i)
            {
                lastDCCToolType = (DCCToolType)(i);
                dccToolInfo     = DCCFinderUtility.FindDCCToolInDirectory(lastDCCToolType, null, path);
            }

            if (null == dccToolInfo)
            {
                EditorUtility.DisplayDialog("MeshSync Project Settings", "No DCC Tool is detected", "Ok");
                return;
            }

            MeshSyncEditorSettings settings = MeshSyncEditorSettings.GetOrCreateSettings();

            if (settings.AddDCCTool(dccToolInfo))
            {
                //Add to ScrollView
                VisualTreeAsset dccToolInfoTemplate = UIElementsEditorUtility.LoadVisualTreeAsset(
                    MeshSyncEditorConstants.DCC_TOOL_INFO_TEMPLATE_PATH
                    );
                ScrollView scrollView = GetEventButtonUserDataAs <ScrollView>(evt.target);
                Assert.IsNotNull(scrollView);
                AddDCCToolSettingsContainer(dccToolInfo, scrollView, dccToolInfoTemplate);
            }
        }
Ejemplo n.º 21
0
//----------------------------------------------------------------------------------------------------------------------
        private void SetupInternal(VisualElement root)
        {
            m_dccStatusLabels.Clear();
            m_dccContainers.Clear();

            m_root = root;
            m_root.Clear();
            m_installPluginButtons.Clear();

            VisualTreeAsset container = UIElementsEditorUtility.LoadVisualTreeAsset(
                MeshSyncEditorConstants.DCC_TOOLS_SETTINGS_CONTAINER_PATH
                );

            VisualTreeAsset dccToolInfoTemplate = UIElementsEditorUtility.LoadVisualTreeAsset(
                MeshSyncEditorConstants.DCC_TOOL_INFO_TEMPLATE_PATH
                );

            TemplateContainer containerInstance = container.CloneTree();
            ScrollView        scrollView        = containerInstance.Query <ScrollView>().First();


            //Buttons
            Button autoDetectDCCButton = containerInstance.Query <Button>("AutoDetectDCCButton").First();

            autoDetectDCCButton.clickable.clicked        += OnAutoDetectDCCButtonClicked;
            m_checkPluginUpdatesButton                    = containerInstance.Query <Button>("ChecksPluginUpdatesButton").First();
            m_checkPluginUpdatesButton.clickable.clicked += OnCheckPluginUpdatesButtonClicked;
            Button addDCCToolButton = containerInstance.Query <Button>("AddDCCToolButton").First();

            addDCCToolButton.userData = scrollView;
            addDCCToolButton.clickable.clickedWithEventInfo += OnAddDCCToolButtonClicked;

            //Label
            m_footerStatusLabel = containerInstance.Query <Label>("FooterStatusLabel").First();

            //Add detected DCCTools to ScrollView
            MeshSyncEditorSettings settings = MeshSyncEditorSettings.GetOrCreateSettings();

            foreach (KeyValuePair <string, DCCToolInfo> dccToolInfo in settings.GetDCCToolInfos())
            {
                AddDCCToolSettingsContainer(dccToolInfo.Value, scrollView, dccToolInfoTemplate);
            }

            //Add the container of this tab to root
            root.Add(containerInstance);
        }
//----------------------------------------------------------------------------------------------------------------------

        private SISUserSettingsProvider() : base(USER_SETTINGS_MENU_PATH, SettingsScope.User)
        {
            //activateHandler is called when the user clicks on the Settings item in the Settings window.

            activateHandler = (string searchContext, VisualElement root) => {
                //Main Tree
                VisualTreeAsset main = UIElementsEditorUtility.LoadVisualTreeAsset(SISEditorConstants.MAIN_USER_SETTINGS_PATH);
                Assert.IsNotNull(main);
                main.CloneTree(root);

                //Style
                UIElementsEditorUtility.LoadAndAddStyle(root.styleSheets, SISEditorConstants.USER_SETTINGS_STYLE_PATH);
                VisualElement content = root.Query <VisualElement>("Content");
                Assert.IsNotNull(content);

                //Fields
                InitMaxMemoryForImagesField(content);
                InitDefaultSISPlayableAssetFPSField(content);

                m_activated = true;
            };

            deactivateHandler = () => {
                if (m_activated)
                {
                    m_maxMemoryForImagesSliderInt.Unbind();
                    m_maxMemoryForImagesIntField.Unbind();

                    Object.DestroyImmediate(m_maxMemoryForImagesScriptableObject);
                    m_maxMemoryForImagesScriptableObject = null;
                    m_activated = false;
                }
            };

            //keywords
            HashSet <string> sisKeywords = new HashSet <string>(new[] { "StreamingImageSequence", });

            sisKeywords.UnionWith(GetSearchKeywordsFromGUIContentProperties <SISUserSettingsProvider.Contents>());

            keywords = sisKeywords;
        }
//----------------------------------------------------------------------------------------------------------------------

        private static TemplateContainer InstantiateContainer(MeshSyncPlayerType playerType)
        {
            VisualTreeAsset container = null;

            switch (playerType)
            {
            case MeshSyncPlayerType.SERVER:
                container = UIElementsEditorUtility.LoadVisualTreeAsset(Constants.SERVER_CONFIG_CONTAINER_PATH);
                break;

            case MeshSyncPlayerType.CACHE_PLAYER:
                container = UIElementsEditorUtility.LoadVisualTreeAsset(Constants.SCENE_CACHE_PLAYER_CONFIG_CONTAINER_PATH);
                break;

            default:
                Assert.Fail();
                break;
            }

            return(container.CloneTree());
        }
Ejemplo n.º 24
0
//----------------------------------------------------------------------------------------------------------------------
        public void Setup(VisualElement root)
        {
            VisualTreeAsset   tab         = UIElementsEditorUtility.LoadVisualTreeAsset(Constants.SERVER_SETTINGS_TAB_PATH);
            TemplateContainer tabInstance = tab.CloneTree();

            VisualElement content = tabInstance.Query <VisualElement>("Content").First();


            //Templates
            VisualTreeAsset         fieldTemplate   = LoadVisualTreeAsset(Constants.PROJECT_SETTINGS_FIELD_TEMPLATE_PATH);
            MeshSyncRuntimeSettings runtimeSettings = MeshSyncRuntimeSettings.GetOrCreateSettings();

            //Add server port
            m_serverPortField = AddField <IntegerField, int>(fieldTemplate, content, Contents.ServerPort,
                                                             runtimeSettings.GetDefaultServerPort(),
                                                             (int newValue) => {
                MeshSyncRuntimeSettings settings = MeshSyncRuntimeSettings.GetOrCreateSettings();
                settings.SetDefaultServerPort((ushort)newValue);
            }
                                                             );

            m_allowPublicAccessToggle = AddField <Toggle, bool>(fieldTemplate, content, Contents.AllowPublicAccess,
                                                                runtimeSettings.GetServerPublicAccess(),
                                                                (bool newValue) => {
                MeshSyncRuntimeSettings settings = MeshSyncRuntimeSettings.GetOrCreateSettings();
                settings.SetServerPublicAccess(newValue);
            }
                                                                );


            //MeshSyncPlayerConfig section
            MeshSyncPlayerConfigSection section = new MeshSyncPlayerConfigSection(MeshSyncPlayerType.SERVER);

            section.Setup(content);



            root.Add(tabInstance);
        }
Ejemplo n.º 25
0
//----------------------------------------------------------------------------------------------------------------------
        public void Setup(VisualElement root)
        {
            Assert.IsNotNull(root);
            root.Clear();

            VisualTreeAsset   tab         = UIElementsEditorUtility.LoadVisualTreeAsset(Constants.SERVER_SETTINGS_TAB_PATH);
            TemplateContainer tabInstance = tab.CloneTree();

            VisualElement content = tabInstance.Query <VisualElement>("Content").First();

            MeshSyncProjectSettings projectSettings = MeshSyncProjectSettings.GetOrCreateInstance();

            //Add server port
            m_serverPortField = AddField <IntegerField, int>(content, Contents.ServerPort,
                                                             projectSettings.GetDefaultServerPort(),
                                                             (int newValue) => { projectSettings.SetDefaultServerPort((ushort)newValue); }
                                                             );

            m_allowPublicAccessToggle = AddField <Toggle, bool>(content, Contents.AllowPublicAccess,
                                                                projectSettings.GetServerPublicAccess(),
                                                                (bool newValue) => { projectSettings.SetServerPublicAccess(newValue); }
                                                                );

            //MeshSyncPlayerConfig section
            MeshSyncPlayerConfigSection section = new MeshSyncPlayerConfigSection(MeshSyncPlayerType.SERVER);

            section.Setup(content);

            Button resetButton = tabInstance.Query <Button>("ResetButton").First();

            resetButton.clicked += () => {
                projectSettings.ResetDefaultServerConfig();
                projectSettings.SaveInEditor();
                Setup(root);
            };


            root.Add(tabInstance);
        }
//----------------------------------------------------------------------------------------------------------------------

        //Support Toggle, FloatField, etc
        private F AddPlayerConfigField <F, V>(VisualElement parent, GUIContent content, V initialValue,
                                              Action <V> onValueChanged, string containerClass = null) where F : VisualElement, INotifyValueChanged <V>, new()
        {
            F field = UIElementsEditorUtility.AddField <F, V>(parent, content, initialValue, (ChangeEvent <V> changeEvent) => {
                F targetField = (changeEvent.target) as F;
                if (null == targetField)
                {
                    return;
                }

                onValueChanged(changeEvent.newValue);
                MeshSyncProjectSettings.GetOrCreateInstance().SaveInEditor();
            });

            field.AddToClassList("general-settings-field");
            if (!string.IsNullOrEmpty(containerClass))
            {
                field.parent.AddToClassList(containerClass);
            }

            return(field);
        }
Ejemplo n.º 27
0
//----------------------------------------------------------------------------------------------------------------------
        public void Setup(VisualElement root)
        {
            m_dccStatusLabels.Clear();
            m_dccContainers.Clear();

            m_root = root;
            m_root.Clear();

            VisualTreeAsset container = UIElementsEditorUtility.LoadVisualTreeAsset(
                MeshSyncEditorConstants.DCC_TOOLS_SETTINGS_CONTAINER_PATH
                );

            VisualTreeAsset dccToolInfoTemplate = UIElementsEditorUtility.LoadVisualTreeAsset(
                MeshSyncEditorConstants.DCC_TOOL_INFO_TEMPLATE_PATH
                );

            TemplateContainer containerInstance = container.CloneTree();
            ScrollView        scrollView        = containerInstance.Query <ScrollView>().First();

            //[TODO-sin: 2020-4-24] Auto detect installed DCC tools + check MeshSync status
            MeshSyncEditorSettings settings = MeshSyncEditorSettings.GetOrCreateSettings();

            foreach (var dccToolInfo in settings.GetDCCToolInfos())
            {
                AddDCCToolSettingsContainer(dccToolInfo.Value, scrollView, dccToolInfoTemplate);
            }

            //Buttons
            Button autoDetectButton = containerInstance.Query <Button>("AutoDetectButton").First();

            autoDetectButton.clickable.clicked += OnAutoDetectButtonClicked;
            Button addDCCToolButton = containerInstance.Query <Button>("AddDCCToolButton").First();

            addDCCToolButton.clickable.clicked += OnAddDCCToolButtonClicked;


            //Add the container of this tab to root
            root.Add(containerInstance);
        }
        // VLadN: Use our own ForceDarkStyleSheet as UIToolkit version also affects parent elements
        // (UIElementsEditorUtility.ForceDarkStyleSheet)
        // This makes it that panels outside of graphview like node inspector and toolbar are also forced in dark incorrectly
        private static void ForceDarkStyleSheet(VisualElement ele)
        {
            if (EditorGUIUtility.isProSkin)
            {
                return;
            }
#if UNITY_2020_3_OR_NEWER
            StyleSheet commonLightStyleSheet = UIElementsEditorUtility.GetCommonLightStyleSheet();
            StyleSheet commonDarkStyleSheet  = UIElementsEditorUtility.GetCommonDarkStyleSheet();
#else
            StyleSheet commonLightStyleSheet = UIElementsEditorUtility.s_DefaultCommonLightStyleSheet;
            StyleSheet commonDarkStyleSheet  = UIElementsEditorUtility.s_DefaultCommonDarkStyleSheet;
#endif
            VisualElement visualElement = ele;
            {
                VisualElementStyleSheetSet styleSheets = visualElement.styleSheets;
                if (styleSheets.Contains(commonLightStyleSheet))
                {
                    styleSheets = visualElement.styleSheets;
                    styleSheets.Swap(commonLightStyleSheet, commonDarkStyleSheet);
                }
            }
        }
Ejemplo n.º 29
0
        void SetupLabel()
        {
            if (typeof(IValueField <U>).IsAssignableFrom(typeof(T)))
            {
                if (typeof(U) == typeof(float))
                {
                    var dragger = new VFXFieldMouseDragger <float>((IValueField <float>)m_Control, DragValueFinished);
                    dragger.SetDragZone(m_Label);
                    m_Label.style.cursor = UIElementsEditorUtility.CreateDefaultCursorStyle(MouseCursor.SlideArrow);
                }
                else if (typeof(U) == typeof(double))
                {
                    var dragger = new VFXFieldMouseDragger <double>((IValueField <double>)m_Control, DragValueFinished);
                    dragger.SetDragZone(m_Label);
                    m_Label.style.cursor = UIElementsEditorUtility.CreateDefaultCursorStyle(MouseCursor.SlideArrow);
                }
                else if (typeof(U) == typeof(long))
                {
                    var dragger = new VFXFieldMouseDragger <long>((IValueField <long>)m_Control, DragValueFinished);
                    dragger.SetDragZone(m_Label);
                    m_Label.style.cursor = UIElementsEditorUtility.CreateDefaultCursorStyle(MouseCursor.SlideArrow);
                }
                else if (typeof(U) == typeof(int))
                {
                    var dragger = new VFXFieldMouseDragger <int>((IValueField <int>)m_Control, DragValueFinished);
                    dragger.SetDragZone(m_Label);
                    m_Label.style.cursor = UIElementsEditorUtility.CreateDefaultCursorStyle(MouseCursor.SlideArrow);
                }
            }

            m_IndeterminateLabel = new Label()
            {
                name = "indeterminate",
                text = VFXControlConstants.indeterminateText
            };
            m_IndeterminateLabel.SetEnabled(false);
        }
//----------------------------------------------------------------------------------------------------------------------
        private PopupField <T> AddPlayerConfigPopupField <T>(VisualElement parent, GUIContent content,
                                                             List <T> options, T initialValue, Action <int> onValueChanged,
                                                             string containerClass = null)
        {
            PopupField <T> popupField = UIElementsEditorUtility.AddPopupField <T>(parent, content, options, initialValue,
                                                                                  (ChangeEvent <T> changeEvent) => {
                PopupField <T> targetField = (changeEvent.target) as PopupField <T>;
                if (null == targetField)
                {
                    return;
                }

                onValueChanged(targetField.index);
                MeshSyncProjectSettings.GetOrCreateInstance().SaveInEditor();
            }
                                                                                  );

            popupField.AddToClassList("general-settings-field");
            if (!string.IsNullOrEmpty(containerClass))
            {
                popupField.parent.AddToClassList(containerClass);
            }
            return(popupField);
        }