8using Object = System.Object;
12 public sealed partial class Asset
17 internal static class ThrowIf
19 public static void ArgumentIsNull(Object obj, String argName)
22 throw new ArgumentNullException(argName);
25 public static void DoesNotExistInFileSystem(Path path)
27 if (path.ExistsInFileSystem ==
false)
28 throw new FileNotFoundException($
"path does not exist: '{path}'");
31 public static void AlreadyAnAsset(UnityEngine.Object obj)
33 if (Status.IsImported(obj))
34 throw new ArgumentException($
"object already is an asset file: {obj}");
37 public static void AssetPathNotInDatabase(Path path)
39 if (path.Exists ==
false)
40 throw new ArgumentException($
"path does not exist or not imported: {path}");
43 public static void NotInDatabase(UnityEngine.Object obj)
45 if (Status.IsImported(obj) ==
false)
46 throw new ArgumentException($
"object is not an asset: {obj}");
49 public static void NotAnAssetGuid(GUID guid)
51 if (Path.Get(guid) ==
null)
52 throw new ArgumentException($
"guid is not an asset: {guid}");
83 public static void AssetLoadReturnedNull(UnityEngine.Object obj, Path path)
89 throw new AssetLoadException(
"asset load returned null - this can occur if the AssetDatabase " +
90 "is currently initializing (eg static ctor) or when importing an asset " +
91 "async or while ADB is 'paused', or if the type does not math, or " +
92 $
"some other reason (please report); path: {path}");
96 public static void PathIsNotValid(String path)
98 if (Path.IsValid(path) ==
false)
99 throw new ArgumentException($
"invalid path: {GetLastErrorMessage()}");
102 public static void NotAProjectPath(String fullPath)
104 var rootPath = Path.FullProjectPath;
105 if (fullPath.StartsWith(rootPath) ==
false)
107 throw new ArgumentException(
108 $
"invalid relative or project path: '{fullPath}' - relative paths must start with 'Assets', full paths must include the project's root directory");
112 public static void NullOrWhitespace(String param, String paramName)
115 throw new ArgumentNullException($
"{paramName} is null");
116 if (String.IsNullOrWhiteSpace(param))
117 throw new ArgumentException($
"{paramName} is empty or whitespace");
120 public static void ContainsPathSeparators(String fileName, String paramName)
122 var normalized = fileName.ToForwardSlashes();
123 if (normalized.Contains(
'/'))
124 throw new ArgumentException($
"filename contains path separators: '{fileName}'", paramName);
127 public static void SubObjectIsGameObject(UnityEngine.Object subObject)
129 if (subObject is GameObject go)
130 throw new ArgumentException($
"sub assets must not be of type GameObject: {subObject}");
133 public static void ExtensionIsNotUnityPackage(Path path)
135 if (path.Extension.ToLower().Equals(
".unitypackage") ==
false)
136 throw new ArgumentException($
"file does not have .unitypackage extension: {path}");
139 public static void SourceAndDestPathAreEqual(Path sourcePath, Path destinationPath)
141 if (sourcePath.Equals(destinationPath))
142 throw new ArgumentException($
"source and destination path are equal: {sourcePath}");