using System.IO; using UnityEditor; using UnityEngine; /// /// Helper class that will create assets for serializable objects. /// public static class CustomAssetUtility { public static void CreateAsset() 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(path); } public static void CreateAsset(string path) where T : ScriptableObject { T asset = ScriptableObject.CreateInstance(); string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset"); AssetDatabase.CreateAsset(asset, assetPathAndName); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; } }