You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

using System.IO;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Helper class that will create assets for serializable objects.
/// </summary>
public static class CustomAssetUtility {
public static void CreateAsset<T>() where T : ScriptableObject
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (path == "")
{
path = "Assets";
}
else if (Path.GetExtension(path) != "")
{
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
}
CreateAsset<T>(path);
}
public static void CreateAsset<T>(string path) where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T>();
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset");
AssetDatabase.CreateAsset(asset, assetPathAndName);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
}