diff --git a/CHANGELOG.md b/CHANGELOG.md index de2dc93..1cacdf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -#### v1.9.0 - Jan 31, 2024 +#### v1.9.1 - Feb 01, 2024 - API Changes: These static methods have been MOVED from **Asset** to **Asset.File**: - GetMainType @@ -8,7 +8,10 @@ - GetGuid - GetFileId - GetGuidAndFileId -- Rationale: These methods hindered API discovery via auto-completion by cluttering the Asset namespace, and they truly belong to the File API since they query asset file attributes. + - Rationale: These methods hindered API discovery via auto-completion by cluttering the Asset namespace, and they truly belong to the File API since they query asset file attributes. +- Fixed: 2021.3 shows warning when copying (duplicate, save as new) an asset, complaining that filename must match asset object name. This is likely a bug in Unity. +- Fixed the same 2021.3 issue in workflow sample. Also required importing batched asset after copying them. +- Asset.File.Import takes IEnumerable as input (not just array) #### v1.8.6 - Jan 30, 2024 diff --git a/Docs~/html/_asset_8_file_8cs_source.html b/Docs~/html/_asset_8_file_8cs_source.html index 4412ba4..f222f5c 100644 --- a/Docs~/html/_asset_8_file_8cs_source.html +++ b/Docs~/html/_asset_8_file_8cs_source.html @@ -198,11 +198,11 @@
305 where T : Object => Load<T>(path);
306
320 public static void
-
321 Import([NotNull] Path[] paths, ImportAssetOptions options = ImportAssetOptions.Default) =>
-
322 Import(Path.ToStrings(paths), options);
+
321 Import([NotNull] IEnumerable<Path> paths, ImportAssetOptions options = ImportAssetOptions.Default) =>
+
322 Import(Path.ToStrings(paths.ToArray()), options);
323
337 public static void
-
338 Import([NotNull] String[] paths, ImportAssetOptions options = ImportAssetOptions.Default) => BatchEditing(
+
338 Import([NotNull] IEnumerable<string> paths, ImportAssetOptions options = ImportAssetOptions.Default) => BatchEditing(
339 () =>
340 {
341 foreach (var path in paths)
@@ -455,38 +455,47 @@
1048
1049 destinationPath.CreateFolders();
1050
-
1051 var success = AssetDatabase.CopyAsset(sourcePath, destinationPath);
-
1052 SetLastErrorMessage(success ? String.Empty : $"failed to copy {sourcePath} to {destinationPath}");
-
1053 return success;
-
1054 }
-
1055
-
1056 private static void SaveInternal([NotNull] Object asset, Boolean forceSave = false)
-
1057 {
-
1058 ThrowIf.ArgumentIsNull(asset, nameof(asset));
-
1059 ThrowIf.NotInDatabase(asset);
-
1060
-
1061 if (forceSave)
-
1062 EditorUtility.SetDirty(asset);
-
1063
-
1064 AssetDatabase.SaveAssetIfDirty(asset);
-
1065 }
-
1066
-
1067 private static void ImportIfNotImported([NotNull] Path path,
-
1068 ImportAssetOptions options = ImportAssetOptions.Default)
-
1069 {
-
1070 // Not in database but on disk? => Import path
-
1071 // Cannot determine if existing file has been updated though.
-
1072 if (path.Exists == false && path.ExistsInFileSystem)
-
1073 Import(path, options);
+
1051#if UNITY_2022_1_OR_NEWER
+
1052 var success = AssetDatabase.CopyAsset(sourcePath, destinationPath);
+
1053 SetLastErrorMessage(success ? String.Empty : $"failed to copy {sourcePath} to {destinationPath}");
+
1054 return success;
+
1055#else
+
1056 // in Unity 2021 we have to load, clone and create instead
+
1057 // because object and file name have to match (likely a bug in that version)
+
1058 var original = LoadMain<Object>(sourcePath);
+
1059 var copy = Object.Instantiate(original);
+
1060 copy = Create(copy, destinationPath);
+
1061 return copy != null;
+
1062#endif
+
1063 }
+
1064
+
1065 private static void SaveInternal([NotNull] Object asset, Boolean forceSave = false)
+
1066 {
+
1067 ThrowIf.ArgumentIsNull(asset, nameof(asset));
+
1068 ThrowIf.NotInDatabase(asset);
+
1069
+
1070 if (forceSave)
+
1071 EditorUtility.SetDirty(asset);
+
1072
+
1073 AssetDatabase.SaveAssetIfDirty(asset);
1074 }
1075
-
1076#if !UNITY_2022_2_OR_NEWER // dummy for LoadAsync in earlier versions
-
1077 public class AssetDatabaseLoadOperation {}
-
1078#endif
-
1079 }
+
1076 private static void ImportIfNotImported([NotNull] Path path,
+
1077 ImportAssetOptions options = ImportAssetOptions.Default)
+
1078 {
+
1079 // Not in database but on disk? => Import path
+
1080 // Cannot determine if existing file has been updated though.
+
1081 if (path.Exists == false && path.ExistsInFileSystem)
+
1082 Import(path, options);
+
1083 }
+
1084
+
1085#if !UNITY_2022_2_OR_NEWER // dummy for LoadAsync in earlier versions
+
1086 public class AssetDatabaseLoadOperation {}
+
1087#endif
+
1088 }
-
1080 }
-
1081}
+
1089 }
+
1090}
CodeSmileEditor.Asset.File.OpenExternal
static void OpenExternal(Int32 instanceId, Int32 lineNumber=-1, Int32 columnNumber=-1)
Opens the asset in the application associated with the file's extension.
CodeSmileEditor.Asset.File.PathsNotDeleted
static IList< String > PathsNotDeleted
The paths that failed to be deleted or trashed. Is an empty list if no failure occured on the last ca...
Definition Asset.File.cs:46
CodeSmileEditor.Asset.File.Save
static void Save([NotNull] Object asset)
Saves the object to disk if it is dirty.
diff --git a/Docs~/html/class_code_smile_editor_1_1_asset_1_1_database_a7c993d64861e62fbdcff3700690b2318.html b/Docs~/html/class_code_smile_editor_1_1_asset_1_1_database_a7c993d64861e62fbdcff3700690b2318.html index 9df0ff8..cab77b5 100644 --- a/Docs~/html/class_code_smile_editor_1_1_asset_1_1_database_a7c993d64861e62fbdcff3700690b2318.html +++ b/Docs~/html/class_code_smile_editor_1_1_asset_1_1_database_a7c993d64861e62fbdcff3700690b2318.html @@ -119,7 +119,7 @@

Scans for external file system modifications and updates the Database accordingly. Prefer to use CodeSmileEditor.Asset.File.Import within CodeSmileEditor.Asset.File.BatchEditing. CAUTION: ImportAll ('Refresh') unloads unused resources. This can degrade editor performance!

-

For best performance, prefer to use CodeSmileEditor.Asset.File.Import(String[],ImportAssetOptions) to import multiple assets in a batch operation.

+

For best performance, prefer to use CodeSmileEditor.Asset.File.Import(String[],ImportAssetOptions) to import multiple assets in a batch operation.

When to call ImportAll (same as AssetDatabase.Refresh):