Created
September 16, 2015 09:23
-
-
Save nobnak/e5fb4e3ea968f267bb94 to your computer and use it in GitHub Desktop.
Editor Script for ScriptableObject Creation for Unity
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 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