diff --git a/Editor/NFTPortSettings.cs b/Editor/NFTPortSettings.cs index 2f0facf..999d6ef 100644 --- a/Editor/NFTPortSettings.cs +++ b/Editor/NFTPortSettings.cs @@ -16,6 +16,7 @@ public class NFTPortSettings : EditorWindow private static bool windowopen = false; private bool ranLatestrel = false; PkgJson releasedPkgJson = null; + static private bool NFTPortStarted; [MenuItem("NFTPort/Home")] public static void ShowWindow() { @@ -38,6 +39,25 @@ static void RegisteredPackagesEventHandler(PackageRegistrationEventArgs packageR ReadFromUserPrefs(); } + [InitializeOnLoad] + public class Startup + { + static Startup() + { + EditorApplication.update += AfterLoad; + } + + static void AfterLoad() + { + NFTPortStarted = SessionState.GetBool("NFTPortStarted", false); + if(!NFTPortStarted) + { + ReadFromUserPrefs(); + SessionState.SetBool("NFTPortStarted", true); + } + } + } + void OnGUI() { Texture banner = Resources.Load("banner"); @@ -116,12 +136,27 @@ void OnGUI() } + private bool firstload = true; + void OnEnable() { - if(!windowopen) - ReadFromUserPrefs(); + if (!windowopen) + { + if (!firstload) + { + firstload = false; + return; + + } + else + { + ReadFromUserPrefs(); + } + + } windowopen = true; ranLatestrel = false; + } private void OnDisable() @@ -137,7 +172,7 @@ public override void SaveChanges() static void ShowHomeWindow() { - if(myAPIString != PortConstants.DefaultAPIKey || windowopen) + if(windowopen) return; NFTPortSettings win = GetWindow(WindowType, false, PortConstants.HomeWindowName, true) as NFTPortSettings; @@ -201,12 +236,21 @@ static void UserStats() userModel = null; User_Settings .Initialize(true) + .OnError(usermodel=> StatsErrore()) .OnComplete(usermodel=> userModel = usermodel) .Run(); } + + static void StatsErrore() + { + if (!windowopen && !APIkeyOk()) + { + ShowHomeWindow(); + } + } - bool APIkeyOk() + static bool APIkeyOk() { if (userModel == null) { diff --git a/Runtime/Internal/User_Settings.cs b/Runtime/Internal/User_Settings.cs index e5b7552..7cff349 100644 --- a/Runtime/Internal/User_Settings.cs +++ b/Runtime/Internal/User_Settings.cs @@ -65,7 +65,13 @@ private void OnEnable() /// Optional bool parameter can set to false to avoid Spawned GameObject being destroyed after the Api process is complete. public static User_Settings Initialize(bool destroyAtEnd = true) { - var _this = new GameObject("Port Initialize | Delete:" + destroyAtEnd).AddComponent(); + string name = "Port Initialize | Delete:"; + var existing = (GameObject.Find(name + destroyAtEnd)); + if (existing != null) + { + return existing.GetComponent(); + } + var _this = new GameObject(name + destroyAtEnd).AddComponent(); _this.destroyAtEnd = destroyAtEnd; _this.onEnable = false; _this.debugErrorLog = false;