Browse Source

[unity] Fixed runtime import hanging on "Importing small assets" in Unity 2019.3 and creating multiple Assets/Editor1, Assets/Editor2, etc dirs. Closes #1384.

Harald Csaszar 6 năm trước cách đây
mục cha
commit
b792cc4b73

+ 12 - 3
spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpinePreferences.cs

@@ -41,11 +41,17 @@
 
 using UnityEngine;
 using UnityEditor;
+using System.Threading;
 
 namespace Spine.Unity.Editor {
 
 	public class SpinePreferences : ScriptableObject {
 
+		#if NEW_PREFERENCES_SETTINGS_PROVIDER
+		static int wasPreferencesDirCreated = 0;
+		static int wasPreferencesAssetCreated = 0;
+		#endif
+
 		public const string SPINE_SETTINGS_ASSET_PATH = "Assets/Editor/SpineSettings.asset";
 
 		#if SPINE_TK2D
@@ -99,10 +105,13 @@ namespace Spine.Unity.Editor {
 			{
 				settings = ScriptableObject.CreateInstance<SpinePreferences>();
 				SpineEditorUtilities.OldPreferences.CopyOldToNewPreferences(ref settings);
-				if (!AssetDatabase.IsValidFolder("Assets/Editor"))
+				// Multiple threads may be calling this method during import, creating the folder
+				// multiple times with ascending number suffix. Atomic wasPreferencesDirCreated int
+				// variable is used to prevent any redundant create operations.
+				if (!AssetDatabase.IsValidFolder("Assets/Editor") && Interlocked.Exchange(ref wasPreferencesDirCreated, 1) == 0)
 					AssetDatabase.CreateFolder("Assets", "Editor");
-				AssetDatabase.CreateAsset(settings, SPINE_SETTINGS_ASSET_PATH);
-				AssetDatabase.SaveAssets();
+				if (Interlocked.Exchange(ref wasPreferencesAssetCreated, 1) == 0)
+					AssetDatabase.CreateAsset(settings, SPINE_SETTINGS_ASSET_PATH);
 			}
 			return settings;
 		}