| | 1 | | using System.IO; |
| | 2 | | using UnityEditor; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Helpers |
| | 6 | | { |
| | 7 | | //NOTE(Brian): This is taken from http://wiki.unity3d.com/index.php/CreateScriptableObjectAsset |
| | 8 | | public static class ScriptableObjectUtility |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | // This makes it easy to create, name and place unique new ScriptableObject asset files. |
| | 12 | | /// </summary> |
| | 13 | | public static void CreateAsset<T>() where T : ScriptableObject |
| | 14 | | { |
| 0 | 15 | | T asset = ScriptableObject.CreateInstance<T>(); |
| | 16 | |
|
| 0 | 17 | | string path = AssetDatabase.GetAssetPath(Selection.activeObject); |
| 0 | 18 | | if (path == "") |
| | 19 | | { |
| 0 | 20 | | path = "Assets"; |
| 0 | 21 | | } |
| 0 | 22 | | else if (Path.GetExtension(path) != "") |
| | 23 | | { |
| 0 | 24 | | path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); |
| | 25 | | } |
| | 26 | |
|
| 0 | 27 | | string assetPathAndName = |
| | 28 | | AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset"); |
| | 29 | |
|
| 0 | 30 | | AssetDatabase.CreateAsset(asset, assetPathAndName); |
| | 31 | |
|
| 0 | 32 | | AssetDatabase.SaveAssets(); |
| 0 | 33 | | AssetDatabase.Refresh(); |
| 0 | 34 | | EditorUtility.FocusProjectWindow(); |
| 0 | 35 | | Selection.activeObject = asset; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | [MenuItem("Assets/Create/Decentraland/DCLComponentFactory")] |
| 0 | 39 | | public static void CreateAsset() { ScriptableObjectUtility.CreateAsset<PoolableComponentFactory>(); } |
| | 40 | | } |
| | 41 | | } |