1
- /*
2
- The MIT License (MIT)
3
-
4
- Copyright (c) 2013 Banbury
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.
23
- */
24
- using UnityEngine ;
25
- #if UNITY_EDITOR
26
- using UnityEditor ;
27
- #endif
28
- using System . IO ;
29
-
30
- public static class ScriptableObjectUtility {
31
- /// <summary>
32
- // This makes it easy to create, name and place unique new ScriptableObject asset files.
33
- /// </summary>
34
- #if UNITY_EDITOR
35
- public static void CreateAsset ( Object asset )
36
- {
37
- string path = AssetDatabase . GetAssetPath ( Selection . activeObject ) ;
38
- if ( path == "" ) {
39
- path = "Assets" ;
40
- } else if ( Path . GetExtension ( path ) != "" ) {
41
- path = path . Replace ( Path . GetFileName ( AssetDatabase . GetAssetPath ( Selection . activeObject ) ) , "" ) ;
42
- }
43
-
44
- string assetPathAndName = AssetDatabase . GenerateUniqueAssetPath ( path + "/New " + asset . GetType ( ) . ToString ( ) + ".asset" ) ;
45
-
46
- AssetDatabase . CreateAsset ( asset , assetPathAndName ) ;
47
-
48
-
49
- AssetDatabase . SaveAssets ( ) ;
50
-
51
- Selection . activeObject = asset ;
52
- }
53
-
54
- public static void CreateAsset ( Object asset , string filename )
55
- {
56
- string path = AssetDatabase . GetAssetPath ( Selection . activeObject ) ;
57
- if ( path == "" ) {
58
- path = "Assets" ;
59
- } else if ( Path . GetExtension ( path ) != "" ) {
60
- path = path . Replace ( Path . GetFileName ( AssetDatabase . GetAssetPath ( Selection . activeObject ) ) , "" ) ;
61
- }
62
-
63
- string assetPathAndName = AssetDatabase . GenerateUniqueAssetPath ( path + "/" + filename + ".asset" ) ;
64
-
65
- AssetDatabase . CreateAsset ( asset , assetPathAndName ) ;
66
-
67
-
68
- AssetDatabase . SaveAssets ( ) ;
69
-
70
- Selection . activeObject = asset ;
71
- }
72
- #endif
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2013 Banbury
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
+ */
24
+ using UnityEngine ;
25
+ #if UNITY_EDITOR
26
+ using UnityEditor ;
27
+ #endif
28
+ using System . IO ;
29
+
30
+ public static class ScriptableObjectUtility {
31
+ /// <summary>
32
+ // This makes it easy to create, name and place unique new ScriptableObject asset files.
33
+ /// </summary>
34
+ #if UNITY_EDITOR
35
+ public static void CreateAsset ( Object asset )
36
+ {
37
+ CreateAsset ( asset , "/New " + asset . GetType ( ) . ToString ( ) ) ;
38
+ }
39
+
40
+ public static void CreateAsset ( Object asset , string filename )
41
+ {
42
+ string path = AssetDatabase . GetAssetPath ( Selection . activeObject ) ;
43
+ if ( path == "" ) {
44
+ path = "Assets" ;
45
+ } else if ( Path . GetExtension ( path ) != "" ) {
46
+ path = path . Replace ( Path . GetFileName ( AssetDatabase . GetAssetPath ( Selection . activeObject ) ) , "" ) ;
47
+ }
48
+
49
+ string assetPathAndName = AssetDatabase . GenerateUniqueAssetPath ( path + "/" + filename + ".asset" ) ;
50
+
51
+ AssetDatabase . CreateAsset ( asset , assetPathAndName ) ;
52
+
53
+
54
+ AssetDatabase . SaveAssets ( ) ;
55
+
56
+ Selection . activeObject = asset ;
57
+ }
58
+ #endif
73
59
}
0 commit comments