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

This commit is contained in:
Harald Csaszar 2019-06-18 15:58:26 +02:00
parent e8866cc730
commit b792cc4b73

View File

@ -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;
}