From 01649d78968efeaab772e6a0c07893a5d2b2c53d Mon Sep 17 00:00:00 2001 From: Priere <44214460+shiyouganai@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:03:14 -0400 Subject: [PATCH] Add quick fix for duplicate migration folder creation This commit adds a quick fix for an issue where duplicate asset folders were created if a user migrated to the package version of LTCGI when there was already an LTCGI Controller in their open scene. --- Editor/LTCGI_Controller.cs | 74 ++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/Editor/LTCGI_Controller.cs b/Editor/LTCGI_Controller.cs index 316dec1..d5b1d73 100644 --- a/Editor/LTCGI_Controller.cs +++ b/Editor/LTCGI_Controller.cs @@ -62,6 +62,8 @@ public partial class LTCGI_Controller : MonoBehaviour public bool HasDynamicScreens = false; public bool HasCylinders = false; + private static bool MigrationChecked = false; + public void OnEnable() { if (PrefabUtility.IsPartOfPrefabAsset(this.gameObject)) return; @@ -92,43 +94,47 @@ public void OnEnable() public static void MigratoryBirdsDontMigrateAsMuchAsWeDoButThisFunctionWillTakeCareOfItNonetheless() { var hasChanges = false; - if (!AssetDatabase.IsValidFolder("Assets\\_pi_")) - { - AssetDatabase.CreateFolder("Assets", "_pi_"); - hasChanges = true; - } - if (!AssetDatabase.IsValidFolder("Assets\\_pi_\\_LTCGI")) - { - AssetDatabase.CreateFolder("Assets\\_pi_", "_LTCGI"); - hasChanges = true; - } - if (!AssetDatabase.IsValidFolder("Assets\\_pi_\\_LTCGI\\Shaders")) - { - AssetDatabase.CreateFolder("Assets\\_pi_\\_LTCGI", "Shaders"); - hasChanges = true; - } - if (!File.Exists("Assets\\_pi_\\_LTCGI\\Shaders\\LTCGI.cginc")) + if (MigrationChecked == false) { - File.WriteAllText("Assets\\_pi_\\_LTCGI\\Shaders\\LTCGI.cginc", "#include \"Packages\\at.pimaker.ltcgi\\Shaders\\LTCGI.cginc\""); - hasChanges = true; - } + if (!AssetDatabase.IsValidFolder("Assets\\_pi_")) + { + AssetDatabase.CreateFolder("Assets", "_pi_"); + hasChanges = true; + } + if (!AssetDatabase.IsValidFolder("Assets\\_pi_\\_LTCGI")) + { + AssetDatabase.CreateFolder("Assets\\_pi_", "_LTCGI"); + hasChanges = true; + } + if (!AssetDatabase.IsValidFolder("Assets\\_pi_\\_LTCGI\\Shaders")) + { + AssetDatabase.CreateFolder("Assets\\_pi_\\_LTCGI", "Shaders"); + hasChanges = true; + } + if (!File.Exists("Assets\\_pi_\\_LTCGI\\Shaders\\LTCGI.cginc")) + { + File.WriteAllText("Assets\\_pi_\\_LTCGI\\Shaders\\LTCGI.cginc", "#include \"Packages\\at.pimaker.ltcgi\\Shaders\\LTCGI.cginc\""); + hasChanges = true; + } - // god I hate this part, Unity dumb dumb - if (!AssetDatabase.IsValidFolder("Assets\\Gizmos")) - { - AssetDatabase.CreateFolder("Assets", "Gizmos"); - hasChanges = true; - } - if (!File.Exists("Assets\\Gizmos\\LTCGI_Screen_Gizmo.png")) - { - File.Copy("Packages\\at.pimaker.ltcgi\\LTCGI_Screen_Gizmo.png", "Assets\\Gizmos\\LTCGI_Screen_Gizmo.png", true); - hasChanges = true; - } + // god I hate this part, Unity dumb dumb + if (!AssetDatabase.IsValidFolder("Assets\\Gizmos")) + { + AssetDatabase.CreateFolder("Assets", "Gizmos"); + hasChanges = true; + } + if (!File.Exists("Assets\\Gizmos\\LTCGI_Screen_Gizmo.png")) + { + File.Copy("Packages\\at.pimaker.ltcgi\\LTCGI_Screen_Gizmo.png", "Assets\\Gizmos\\LTCGI_Screen_Gizmo.png", true); + hasChanges = true; + } - if (hasChanges) - { - Debug.Log("LTCGI Migration took place, refreshing asset database"); - AssetDatabase.Refresh(); + if (hasChanges) + { + Debug.Log("LTCGI Migration took place"); + } + + MigrationChecked = true; } }