//---------------------------------------------------------------------------------------------------------------------- internal static SISUserSettings GetInstance() { if (null != m_instance) return m_instance; SISUserSettings settings = LoadUserSettings(); if (null != settings) { return settings; } m_instance = new SISUserSettings(); m_instance.SaveUserSettings(); return m_instance; }
//---------------------------------------------------------------------------------------------------------------------- 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); SISUserSettings userSettings = SISUserSettings.GetInstance(); int maxImagesMemoryMB = userSettings.GetMaxImagesMemoryMB(); //Prepare objects for binding m_maxMemoryForImagesScriptableObject = ScriptableObject.CreateInstance <IntScriptableObject>(); m_maxMemoryForImagesScriptableObject.Value = userSettings.GetMaxImagesMemoryMB(); SerializedObject maxMemoryForImagesSerializedObject = new SerializedObject(m_maxMemoryForImagesScriptableObject); //Slider VisualElement fieldContainer = UIElementsUtility.AddElement <VisualElement>(content, "field-container"); m_maxMemoryForImagesSliderInt = UIElementsUtility.AddField <SliderInt, int>(fieldContainer, Contents.MAX_MEMORY_FOR_IMAGES_MB, maxImagesMemoryMB); m_maxMemoryForImagesSliderInt.lowValue = 4096; m_maxMemoryForImagesSliderInt.highValue = 131072; m_maxMemoryForImagesSliderInt.bindingPath = nameof(IntScriptableObject.Value); m_maxMemoryForImagesSliderInt.Bind(maxMemoryForImagesSerializedObject); m_maxMemoryForImagesIntField = UIElementsUtility.AddField <IntegerField, int>(fieldContainer, null, maxImagesMemoryMB); m_maxMemoryForImagesIntField.bindingPath = nameof(IntScriptableObject.Value); m_maxMemoryForImagesIntField.Bind(maxMemoryForImagesSerializedObject); Label sliderIntValuePostLabel = UIElementsUtility.AddElement <Label>(fieldContainer); sliderIntValuePostLabel.text = "MB "; m_curMaxMemoryForImagesLabel = UIElementsUtility.AddElement <Label>(fieldContainer); m_curMaxMemoryForImagesLabel.text = $"({maxImagesMemoryMB} MB)"; //Buttons setup Button saveButton = root.Query <Button>("SaveButton"); saveButton.clicked += () => { userSettings.SetMaxImagesMemoryMB(m_maxMemoryForImagesSliderInt.value); m_curMaxMemoryForImagesLabel.text = $"({userSettings.GetMaxImagesMemoryMB()} MB)"; userSettings.SaveUserSettings(); }; 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; }