예제 #1
0
        private static void HandleEditorUpdate(Action openWindow, string getUpdatesUrl, AdditionalOnWindowOpened additionalOnWindowOpen = null)
        {
            if (!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                var defaultShowAtStartupPreferenceDefinition = ProductPreferenceBase.CreateDefaultShowOptionPreferenceDefinition();
                ProductPreferenceBase.StartupShowMode showWindowOnStartupMode = ProductPreferenceBase.StartupShowMode.Never;
                if (!EditorPrefs.HasKey(defaultShowAtStartupPreferenceDefinition.PreferenceKey)) //first run / import
                {
                    showWindowOnStartupMode = (ProductPreferenceBase.StartupShowMode)defaultShowAtStartupPreferenceDefinition.DefaultValue;
                    defaultShowAtStartupPreferenceDefinition.SetEditorPersistedValue(showWindowOnStartupMode);
                    OpenWindow(openWindow, additionalOnWindowOpen, true);

                    if (showWindowOnStartupMode != ProductPreferenceBase.StartupShowMode.Never)
                    {
                        GetUpdates(openWindow, getUpdatesUrl);
                    }
                }
                else
                {
                    if (Time.realtimeSinceStartup < 10) //static ctor will also be executed on script changes / domain reload, make sure editor is just turned on
                    {
                        showWindowOnStartupMode = (ProductPreferenceBase.StartupShowMode)defaultShowAtStartupPreferenceDefinition.GetEditorPersistedValueOrDefault();
                        if (showWindowOnStartupMode == ProductPreferenceBase.StartupShowMode.Always)
                        {
                            OpenWindow(openWindow, additionalOnWindowOpen, false);
                        }

                        if (showWindowOnStartupMode != ProductPreferenceBase.StartupShowMode.Never)
                        {
                            GetUpdates(openWindow, getUpdatesUrl);
                        }
                    }
                }
            }
        }
        private void EnsureInitialized()
        {
            if (_isInitialized)
            {
                return;
            }

            EnsureStylesInitialized();
            _startupStartupShowMode = (ProductPreferenceBase.StartupShowMode)EditorPrefs.GetInt(ShowAtStartupPreferenceKey, (int)ProductPreferenceBase.StartupShowMode.Always);
            LastUpdateText          = ProductPreferenceBase.CreateDefaultLastUpdateText().GetEditorPersistedValueOrDefault() as string;

            _isInitialized = true;
        }
        protected void RenderGUI(List <GuiSection> leftSections, GuiSection topSection, GuiSection bottomSection, ScrollViewGuiSection mainScrollViewGuiSection)
        {
            EnsureInitialized();

            if (_renderMainScrollView == null)
            {
                _renderMainScrollView = mainScrollViewGuiSection.RenderMainScrollViewSection;
            }

            EditorGUILayout.BeginHorizontal(GUIStyle.none, GUILayout.ExpandWidth(true));
            {
                if (leftSections != null && leftSections.Any())
                {
                    EditorGUILayout.BeginVertical(GUILayout.Width(leftSections.First().WidthPx));
                    foreach (var leftSection in leftSections)
                    {
                        {
                            RenderSectionStart(leftSection);

                            foreach (var element in leftSection.ClickableElements)
                            {
                                var lastUpdateButton = element as LastUpdateButton;
                                if (lastUpdateButton != null)
                                {
                                    if (!string.IsNullOrWhiteSpace(LastUpdateText))
                                    {
                                        if (!IsUpdateTextViewAlreadyPreselected)
                                        {
                                            ChangeMainScrollViewRenderFn(lastUpdateButton.RenderMainScrollViewFunction);
                                            IsUpdateTextViewAlreadyPreselected = true;
                                        }
                                        RenderClickableElement(element);
                                    }
                                }
                                else
                                {
                                    RenderClickableElement(element);
                                }
                            }

                            GUILayout.Space(10);
                        }
                    }

                    EditorGUILayout.EndVertical();
                }


                EditorGUILayout.BeginVertical(GUILayout.Width(topSection.WidthPx), GUILayout.ExpandHeight(true));
                {
                    if (topSection != null)
                    {
                        RenderSectionStart(topSection);

                        if (topSection.ClickableElements.Count > 0)
                        {
                            EditorGUILayout.BeginHorizontal(GUILayout.Width(topSection.WidthPx));
                            {
                                foreach (var element in topSection.ClickableElements)
                                {
                                    RenderClickableElement(element);
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }


                    if (mainScrollViewGuiSection != null)
                    {
                        RenderSectionStart(mainScrollViewGuiSection);
                        _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, "ProgressBarBack", GUILayout.ExpandHeight(true), GUILayout.Width(mainScrollViewGuiSection.WidthPx));

                        _renderMainScrollView(this);

                        GUILayout.EndScrollView();
                    }


                    if (bottomSection != null)
                    {
                        EditorGUILayout.BeginHorizontal(GUILayout.Width(bottomSection.WidthPx));
                        {
                            EditorGUILayout.BeginVertical();
                            {
                                RenderSectionStart(bottomSection);

                                EditorGUILayout.BeginHorizontal();
                                {
                                    for (var i = 0; i < bottomSection.ClickableElements.Count; i++)
                                    {
                                        var bottomLink = bottomSection.ClickableElements[i];
                                        if (GUILayout.Button(bottomLink.Text, LinkStyle))
                                        {
                                            bottomLink.OnClick(this);
                                        }

                                        if (i < bottomSection.ClickableElements.Count - 1)
                                        {
                                            GUILayout.Label("-");
                                        }
                                    }
                                }
                                EditorGUILayout.EndHorizontal();
                                GUILayout.Space(7);
                            }
                            EditorGUILayout.EndVertical();

                            GUILayout.FlexibleSpace();
                            EditorGUILayout.BeginVertical();
                            GUILayout.Space(7);
                            if (_productIcon != null)
                            {
                                GUILayout.Label(_productIcon);
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal("ProjectBrowserBottomBarBg", GUILayout.ExpandWidth(true), GUILayout.Height(22));
            {
                GUILayout.FlexibleSpace();
                EditorGUI.BeginChangeCheck();
                var cache = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 100;
                _startupStartupShowMode     = (ProductPreferenceBase.StartupShowMode)EditorGUILayout.EnumPopup("Show At Startup", _startupStartupShowMode, GUILayout.Width(220));
                EditorGUIUtility.labelWidth = cache;
                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetInt(ShowAtStartupPreferenceKey, (int)_startupStartupShowMode);
                }
            }
            EditorGUILayout.EndHorizontal();
        }