WelcomePage.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using TheraBytes.BetterUi;
  6. using UnityEditor;
  7. using UnityEngine;
  8. namespace TheraBytes.BetterUi.Editor
  9. {
  10. public class WelcomePage : WizardPage
  11. {
  12. public override string NameId { get { return "WelcomePage"; } }
  13. protected override string NextButtonText { get { return "Start Setup Wizard"; } }
  14. public WelcomePage(IWizard wizard)
  15. : base(wizard)
  16. {
  17. }
  18. protected override void OnInitialize()
  19. {
  20. var data = wizard.PersistentData;
  21. Add(new InfoWizardPageElement(new GUIContent(Resources.Load<Texture2D>("wizard_banner"))));
  22. Add(new InfoWizardPageElement("Welcome", InfoType.Header));
  23. Add(new InfoWizardPageElement("Welcome to the setup wizard of Better UI!\n" +
  24. "It will guide you configuring Better UI properly for your project."));
  25. bool skippingIsRecommended = false;
  26. if (data.FileExists() && data.SavedDataCount > 1)
  27. {
  28. Add(new InfoWizardPageElement("It seems like you did the setup wizard for this project already.\n" +
  29. "You can do it again but if you change certain settings, it may lead to broken parts of your UIs.\n" +
  30. "So, make sure you made a backup of the 'TheraBytes' folder before starting the wizard.",
  31. InfoType.WarningBox));
  32. skippingIsRecommended = true;
  33. }
  34. else if (ResolutionMonitor.ScriptableObjectFileExists)
  35. {
  36. Add(new InfoWizardPageElement("It seems like you already have Better UI prepared for your project.\n" +
  37. "Probably you upgraded from an older version of Better UI." +
  38. "In this case it is recommended to skip the setup wizard to prevent breaking your existing UIs.\n\n" +
  39. "If you decide to do the Wizard anyway, make sure you have a backup of the 'TheraBytes' folder.",
  40. InfoType.WarningBox));
  41. skippingIsRecommended = true;
  42. }
  43. if (!skippingIsRecommended)
  44. {
  45. Add(new InfoWizardPageElement("It is recommended to follow this wizard before using any features of Better UI.\n" +
  46. "If you decide to skip the wizard for now, you will not be prompted to do it again.\n\n" +
  47. "However, you can start it manually:\n" +
  48. "Tools -> Better UI -> Settings -> Setup Wizard",
  49. InfoType.InfoBox));
  50. }
  51. if (skippingIsRecommended)
  52. {
  53. Add(new UnserializedButtonPageElement("Jump to Third-Party-Support Page",
  54. () => wizard.JumpToPage<ThirdPartySupportPage>()));
  55. #if UNITY_2017_3_OR_NEWER
  56. Add(new UnserializedButtonPageElement("Jump to Assembly-Definitions Page",
  57. () => wizard.JumpToPage<AssemblyDefinitionsPage>()));
  58. #endif
  59. Add(new UnserializedButtonPageElement("Jump to Example-Scenes Page",
  60. () => wizard.JumpToPage<ExampleScenesPage>()));
  61. Add(new UnserializedButtonPageElement("Jump to Tools Page",
  62. () => wizard.JumpToPage<ToolsPage>()));
  63. Add(new UnserializedButtonPageElement("Jump to Final Page",
  64. () => wizard.JumpToPage<FinalPage>()));
  65. Add(new SeparatorWizardPageElement());
  66. }
  67. Add(new ValueWizardPageElement<bool>("SkipWizard",
  68. (o, v) =>
  69. {
  70. if (GUILayout.Button("Skip Wizard"))
  71. {
  72. if (skippingIsRecommended
  73. || EditorUtility.DisplayDialog("Skip Wizard", "Do you really want to skip the wizard?", "Yes", "No"))
  74. {
  75. EditorUtility.DisplayDialog("Wizard Skipped",
  76. "You can start the wizard later by hand:\nTools -> Better UI -> Settings -> Setup Wizard.",
  77. "Ok");
  78. v = true;
  79. }
  80. }
  81. return v;
  82. },
  83. valueChangedCallback: (o) =>
  84. {
  85. if (o.Value)
  86. {
  87. wizard.PersistentData.RegisterValue(o.SerializationKey, o.GetValueAsString());
  88. wizard.PersistentData.Save();
  89. wizard.Close();
  90. }
  91. })
  92. .MarkComplete());
  93. }
  94. }
  95. }