예제 #1
0
파일: Settings.cs 프로젝트: godjammit/GDX
            /// <summary>
            ///     Draw the Automatic Updates section of settings.
            /// </summary>
            /// <param name="settings">Serialized <see cref="GDXConfig" /> object to be modified.</param>
            public static void AutomaticUpdates(SerializedObject settings)
            {
                const string sectionID = "GDX.Editor.UpdateProvider";

                GUI.enabled = true;

                bool packageSectionEnabled = Layout.CreateSettingsSection(
                    sectionID, true,
                    "Automatic Package Updates", null,
                    settings.FindProperty("updateProviderCheckForUpdates"),
                    Content.AutomaticUpdatesEnabled);

                if (!Layout.GetCachedEditorBoolean(sectionID))
                {
                    return;
                }

                EditorGUILayout.BeginHorizontal(Styles.InfoBoxStyle);
                if (UpdateProvider.LocalPackage.Definition != null)
                {
                    GUILayout.BeginVertical();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Local Version:", EditorStyles.boldLabel,
                                    Styles.FixedWidth130LayoutOptions);
                    GUILayout.Label(UpdateProvider.LocalPackage.Definition.version);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Installation Method:", EditorStyles.boldLabel,
                                    Styles.FixedWidth130LayoutOptions);
                    GUILayout.Label(PackageProvider.GetFriendlyName(UpdateProvider.LocalPackage.InstallationMethod));
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();

                    // Handle additional information
                    switch (UpdateProvider.LocalPackage.InstallationMethod)
                    {
                    case PackageProvider.InstallationType.UPMBranch:
                    case PackageProvider.InstallationType.GitHubBranch:
                    case PackageProvider.InstallationType.GitHub:
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Source Branch:", EditorStyles.boldLabel,
                                        Styles.FixedWidth130LayoutOptions);
                        GUILayout.Label(!string.IsNullOrEmpty(UpdateProvider.LocalPackage.SourceTag)
                                ? UpdateProvider.LocalPackage.SourceTag : "N/A");
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                        break;

                    case PackageProvider.InstallationType.UPMTag:
                    case PackageProvider.InstallationType.GitHubTag:
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Source Tag:", EditorStyles.boldLabel,
                                        Styles.FixedWidth130LayoutOptions);
                        GUILayout.Label(!string.IsNullOrEmpty(UpdateProvider.LocalPackage.SourceTag)
                                ? UpdateProvider.LocalPackage.SourceTag : "N/A");
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                        break;

                    case PackageProvider.InstallationType.UPMCommit:
                    case PackageProvider.InstallationType.GitHubCommit:
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Source Commit:", EditorStyles.boldLabel,
                                        Styles.FixedWidth130LayoutOptions);
                        GUILayout.Label(!string.IsNullOrEmpty(UpdateProvider.LocalPackage.SourceTag)
                                ? UpdateProvider.LocalPackage.SourceTag : "N/A");
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                        break;
                    }

                    // Show remote version if we have something to show
                    if (UpdateProvider.UpdatePackageDefinition != null)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Remote Version:", EditorStyles.boldLabel, Styles.FixedWidth130LayoutOptions);
                        GUILayout.Label(UpdateProvider.UpdatePackageDefinition.version);
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Last Checked:", EditorStyles.boldLabel, Styles.FixedWidth130LayoutOptions);
                    GUILayout.Label(UpdateProvider.GetLastChecked().ToString(Localization.LocalTimestampFormat));
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();

                    GUILayout.EndVertical();

                    // Force things to the right
                    GUILayout.FlexibleSpace();

                    EditorGUILayout.BeginVertical();
                    if (UpdateProvider.HasUpdate(UpdateProvider.UpdatePackageDefinition))
                    {
                        if (GUILayout.Button("Changelog", Styles.ButtonStyle))
                        {
                            Application.OpenURL("https://github.com/dotBunny/GDX/blob/main/CHANGELOG.md");
                        }

                        if (UpdateProvider.IsUpgradable())
                        {
                            if (GUILayout.Button("Update", Styles.ButtonStyle))
                            {
                                UpdateProvider.AttemptUpgrade();
                            }
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Manual Check", Styles.ButtonStyle))
                        {
                            UpdateProvider.CheckForUpdates();
                        }
                    }

                    EditorGUILayout.EndVertical();
                }
                else
                {
                    GUILayout.Label(
                        $"An error occured trying to find the package definition.\nPresumed Root: {UpdateProvider.LocalPackage.PackageAssetPath}\nPresumed Manifest:{UpdateProvider.LocalPackage.PackageManifestPath})",
                        EditorStyles.boldLabel);
                }

                EditorGUILayout.EndHorizontal();

                // Disable based on if we have this enabled
                GUI.enabled = packageSectionEnabled;

                UpdateDayCountSetting =
                    EditorGUILayout.IntSlider(Content.AutomaticUpdatesUpdateDayCount, UpdateDayCountSetting, 1,
                                              31);
            }