Created
August 26, 2015 02:56
-
-
Save FVSHaLuan/2a91fae29274b836e815 to your computer and use it in GitHub Desktop.
** Function: This makes it easy to create, name and place unique new ScriptableObject asset files.
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
#if UNITY_EDITOR | |
using UnityEngine; | |
using UnityEditor; | |
using System.IO; | |
/* Found on the Internet */ | |
public static class ScriptableObjectUtility | |
{ | |
/// <summary> | |
// This makes it easy to create, name and place unique new ScriptableObject asset files. | |
/// </summary> | |
public static void CreateAsset<T>() where T : ScriptableObject | |
{ | |
T asset = ScriptableObject.CreateInstance<T>(); | |
string path = AssetDatabase.GetAssetPath(Selection.activeObject); | |
if (path == "") | |
{ | |
path = "Assets"; | |
} | |
else if (Path.GetExtension(path) != "") | |
{ | |
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); | |
} | |
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset"); | |
AssetDatabase.CreateAsset(asset, assetPathAndName); | |
AssetDatabase.SaveAssets(); | |
AssetDatabase.Refresh(); | |
EditorUtility.FocusProjectWindow(); | |
Selection.activeObject = asset; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment