private static DynamicUnitManager GetInstance() { if( s_Instance == null ) { #if UNITY_EDITOR // If there's no instance, load or create one DynamicUnitManager asset = null; string assetPathAndName = GeneratePath(); // Check the asset database for an existing instance of the asset asset = AssetDatabase.LoadAssetAtPath(assetPathAndName, typeof(ScriptableObject)) as DynamicUnitManager; // If the asset doesn't exist, create it if( asset == null ) { asset = ScriptableObject.CreateInstance<DynamicUnitManager>(); asset.Units = new List<UnitItem>(); AssetDatabase.CreateAsset( asset, assetPathAndName ); AssetDatabase.SaveAssets(); } s_Instance = asset; #else s_Instance = ScriptableObject.FindObjectOfType(typeof(DynamicUnitManager)) as DynamicUnitManager; #endif } return s_Instance; }
private static DynamicUnitManager GetInstance() { if (s_Instance == null) { #if UNITY_EDITOR // If there's no instance, load or create one DynamicUnitManager asset = null; string assetPathAndName = GeneratePath(); // Check the asset database for an existing instance of the asset asset = AssetDatabase.LoadAssetAtPath(assetPathAndName, typeof(ScriptableObject)) as DynamicUnitManager; // If the asset doesn't exist, create it if (asset == null) { asset = ScriptableObject.CreateInstance <DynamicUnitManager>(); asset.Units = new List <UnitItem>(); AssetDatabase.CreateAsset(asset, assetPathAndName); AssetDatabase.SaveAssets(); } s_Instance = asset; #else s_Instance = ScriptableObject.FindObjectOfType(typeof(DynamicUnitManager)) as DynamicUnitManager; #endif } return(s_Instance); }