Skip to content

Instantly share code, notes, and snippets.

@nobnak
Created September 16, 2015 09:23
Show Gist options
  • Save nobnak/e5fb4e3ea968f267bb94 to your computer and use it in GitHub Desktop.
Save nobnak/e5fb4e3ea968f267bb94 to your computer and use it in GitHub Desktop.
Editor Script for ScriptableObject Creation for Unity
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
namespace LayerComposer {
public static class ScriptableObjectUtil {
public static void Create<T>(string path) where T : ScriptableObject {
var data = ScriptableObject.CreateInstance<T>();
AssetDatabase.CreateAsset(data, path);
AssetDatabase.SaveAssets();
Selection.activeObject = data;
}
public static void Create<T>() where T : ScriptableObject {
var path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (string.IsNullOrEmpty(path))
path = "Assets";
if (!Directory.Exists(path))
path = path.Substring(0, path.LastIndexOf("/"));
path = AssetDatabase.GenerateUniqueAssetPath(path + "/" + typeof(T) + ".asset");
Create<T>(path);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment