@@ -9,8 +9,6 @@ namespace UnityEngine.InputSystem
9
9
/// Provides convenience functions for creating and managing assets for test purposes.
10
10
/// Note that all returned paths are converted to Unix paths when running on Windows
11
11
/// for consistency and to avoid mixed path names.
12
- ///
13
- /// This file should NOT be in this assembly, it should reside in the editor test assembly and be internal.
14
12
public static class AssetDatabaseUtils
15
13
{
16
14
private const string kAssetPath = "Assets" ;
@@ -35,8 +33,7 @@ public static void ExternalMoveFileOrDirectory(string source, string dest)
35
33
}
36
34
37
35
// Create an asset at the given path containing the given text content.
38
- private static T CreateAssetAtPath < T > ( string path , string content )
39
- where T : ScriptableObject
36
+ private static T CreateAssetAtPath < T > ( string path , string content ) where T : UnityEngine . Object
40
37
{
41
38
Debug . Assert ( ! File . Exists ( path ) ) ;
42
39
@@ -45,20 +42,9 @@ private static T CreateAssetAtPath<T>(string path, string content)
45
42
{
46
43
CreateDirectories ( Path . GetDirectoryName ( path ) ) ;
47
44
48
- if ( content != null )
49
- {
50
- // Create asset as a file with explicit content
51
- File . WriteAllText ( path , content ) ;
52
- AssetDatabase . ImportAsset ( path ) ;
53
- obj = AssetDatabase . LoadAssetAtPath < T > ( path ) ;
54
- }
55
- else
56
- {
57
- // Use default serialization (YAML) to create asset.
58
- obj = ScriptableObject . CreateInstance < T > ( ) ;
59
- AssetDatabase . CreateAsset ( obj , path ) ;
60
- }
61
-
45
+ File . WriteAllText ( path , content ) ;
46
+ AssetDatabase . ImportAsset ( path ) ;
47
+ obj = AssetDatabase . LoadAssetAtPath < T > ( path ) ;
62
48
if ( obj == null )
63
49
throw new Exception ( $ "Failed to create asset at \" { path } \" ") ;
64
50
}
@@ -113,8 +99,7 @@ public static string CreateDirectory()
113
99
114
100
// Creates an asset in the given directory path with an explicit or random file name containing the
115
101
// given content or the default content based on type.
116
- public static T CreateAsset < T > ( string directoryPath , string filename = null , string content = null )
117
- where T : ScriptableObject
102
+ public static T CreateAsset < T > ( string directoryPath , string filename = null , string content = null ) where T : UnityEngine . Object
118
103
{
119
104
Debug . Assert ( directoryPath == null || directoryPath . Contains ( RootPath ( ) ) ) ;
120
105
Debug . Assert ( filename == null || ! filename . Contains ( "/" ) ) ;
@@ -139,7 +124,7 @@ public static T CreateAsset<T>(string directoryPath, string filename = null, str
139
124
// Creates an asset at the given path containing the specified content.
140
125
// If path is null, a unique random file name is assigned, if content is null the default content based
141
126
// on type (extension) is used.
142
- public static T CreateAsset < T > ( string path = null , string content = null ) where T : UnityEngine . ScriptableObject
127
+ public static T CreateAsset < T > ( string path = null , string content = null ) where T : UnityEngine . Object
143
128
{
144
129
if ( path == null )
145
130
path = RandomAssetFilePath ( RootPath ( ) , AssetFileExtensionFromType ( typeof ( T ) ) ) ;
@@ -223,7 +208,7 @@ private static string DefaultContentFromType(Type type)
223
208
{
224
209
if ( type == typeof ( InputActionAsset ) )
225
210
return "{}" ;
226
- return null ;
211
+ return string . Empty ;
227
212
}
228
213
}
229
214
}
0 commit comments