Skip to content

Commit 5497481

Browse files
committed
Undo changes to AssetDatabaseUtils that were not needed in the end.
1 parent 58f9c28 commit 5497481

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

Packages/com.unity.inputsystem/Tests/TestFixture/AssetDatabaseUtils.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace UnityEngine.InputSystem
99
/// Provides convenience functions for creating and managing assets for test purposes.
1010
/// Note that all returned paths are converted to Unix paths when running on Windows
1111
/// 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.
1412
public static class AssetDatabaseUtils
1513
{
1614
private const string kAssetPath = "Assets";
@@ -35,8 +33,7 @@ public static void ExternalMoveFileOrDirectory(string source, string dest)
3533
}
3634

3735
// 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
4037
{
4138
Debug.Assert(!File.Exists(path));
4239

@@ -45,20 +42,9 @@ private static T CreateAssetAtPath<T>(string path, string content)
4542
{
4643
CreateDirectories(Path.GetDirectoryName(path));
4744

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);
6248
if (obj == null)
6349
throw new Exception($"Failed to create asset at \"{path}\"");
6450
}
@@ -113,8 +99,7 @@ public static string CreateDirectory()
11399

114100
// Creates an asset in the given directory path with an explicit or random file name containing the
115101
// 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
118103
{
119104
Debug.Assert(directoryPath == null || directoryPath.Contains(RootPath()));
120105
Debug.Assert(filename == null || !filename.Contains("/"));
@@ -139,7 +124,7 @@ public static T CreateAsset<T>(string directoryPath, string filename = null, str
139124
// Creates an asset at the given path containing the specified content.
140125
// If path is null, a unique random file name is assigned, if content is null the default content based
141126
// 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
143128
{
144129
if (path == null)
145130
path = RandomAssetFilePath(RootPath(), AssetFileExtensionFromType(typeof(T)));
@@ -223,7 +208,7 @@ private static string DefaultContentFromType(Type type)
223208
{
224209
if (type == typeof(InputActionAsset))
225210
return "{}";
226-
return null;
211+
return string.Empty;
227212
}
228213
}
229214
}

0 commit comments

Comments
 (0)