File tree 2 files changed +38
-0
lines changed
Assets/Animation/Script/Editor
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ using UnityEngine ;
2
+ using UnityEditor ;
3
+ using System ;
4
+ public class CreateAssets
5
+ {
6
+ [ MenuItem ( "Assets/Create assets" ) ]
7
+ public static void CreateAsset ( )
8
+ {
9
+ ScriptableObjectUtility . CreateAsset < AnimatorParameter > ( ) ;
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ using UnityEngine ;
2
+ using UnityEditor ;
3
+ using System . IO ;
4
+
5
+ public static class ScriptableObjectUtility
6
+ {
7
+ public static void CreateAsset < T > ( ) where T : ScriptableObject
8
+ {
9
+ T asset = ScriptableObject . CreateInstance < T > ( ) ;
10
+ string path = AssetDatabase . GetAssetPath ( Selection . activeObject ) ;
11
+ if ( string . IsNullOrEmpty ( path ) )
12
+ {
13
+ Debug . LogError ( "Not select files, select files first! " ) ;
14
+ return ;
15
+ }
16
+ else if ( ! string . IsNullOrEmpty ( Path . GetExtension ( path ) ) )
17
+ {
18
+ path = path . Replace ( Path . GetFileName ( AssetDatabase . GetAssetPath ( Selection . activeObject ) ) , "" ) ;
19
+ }
20
+ string assetPathAndName = AssetDatabase . GenerateUniqueAssetPath ( path + "/New" + typeof ( T ) . ToString ( ) + ".asset" ) ;
21
+ AssetDatabase . CreateAsset ( asset , assetPathAndName ) ;
22
+ AssetDatabase . SaveAssets ( ) ;
23
+ AssetDatabase . Refresh ( ) ;
24
+ EditorUtility . FocusProjectWindow ( ) ;
25
+ Selection . activeObject = asset ;
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments