Last active
March 19, 2020 04:50
-
-
Save iwashihead/5ecde3e1e209be696461d37c5ed499ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using UnityEngine; | |
using UnityEditor; | |
namespace SetupTools | |
{ | |
public class AbstractSettings<T> : ScriptableObject where T : ScriptableObject | |
{ | |
public static T Load(string assetPath) | |
{ | |
return AssetDatabase.LoadAssetAtPath<T>(assetPath); | |
} | |
static T CreateDefault(string assetPath) | |
{ | |
T setting = CreateInstance<T>(); | |
AssetDatabase.CreateAsset(setting, assetPath); | |
Debug.Log(string.Format("Created: {0}", assetPath)); | |
return setting; | |
} | |
public static T LoadOrCreate(string assetPath) | |
{ | |
if (File.Exists(assetPath)) { | |
return Load(assetPath); | |
} else { | |
return CreateDefault(assetPath); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment