Skip to content

Instantly share code, notes, and snippets.

@iwashihead
Last active March 19, 2020 04:50
Show Gist options
  • Save iwashihead/5ecde3e1e209be696461d37c5ed499ec to your computer and use it in GitHub Desktop.
Save iwashihead/5ecde3e1e209be696461d37c5ed499ec to your computer and use it in GitHub Desktop.
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