Last active
August 29, 2015 13:56
-
-
Save TarasOsiris/9252536 to your computer and use it in GitHub Desktop.
Generic method to create .asset files. Taken from here http://www.jacobpennock.com/Blog/?page_id=715 and modified a bit.
This file contains hidden or 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.IO; | |
/// <summary> | |
/// Taken from here : http://www.jacobpennock.com/Blog/?page_id=715 and modified | |
/// </summary> | |
public static class CustomAssetUtility | |
{ | |
public static void CreateAsset<T>() where T : ScriptableObject | |
{ | |
T asset = ScriptableObject.CreateInstance<T>(); | |
string path = AssetDatabase.GetAssetPath(Selection.activeObject); | |
if (path == string.Empty) | |
{ | |
path = "Assets"; | |
} | |
else if (Path.GetExtension(path) != string.Empty) | |
{ | |
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), string.Empty); | |
} | |
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T) + ".asset"); | |
AssetDatabase.CreateAsset(asset, assetPathAndName); | |
AssetDatabase.SaveAssets(); | |
EditorUtility.FocusProjectWindow(); | |
Selection.activeObject = asset; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment