Exemple #1
0
        private static void ProcessResourceAsset(string assetGuid, string path, Object asset, ProjectResources projectResources)
        {
            if (projectResources.ResourcePaths.Contains(path))                     // Handle assets stored in `Resources`.
            {
                var otherAsset = Resources.Load(path, typeof(UnityEngine.Object)); // Check if a different asset is available under the same resources path.
                if (ObjectUtils.IsValid(otherAsset) && otherAsset != asset)
                {
                    var otherPath = AssetDatabase.GetAssetPath(otherAsset);
                    PostprocessBuild();
                    EditorUtility.ClearProgressBar();
                    throw new System.Exception($"Resource conflict detected: asset stored at `{otherPath}` conflicts with `{path}` Naninovel resource; rename or move the conflicting asset and rebuild the player.");
                }
                return;
            }

            if (useAddressables)
            {
                if (!AddressableHelper.CheckAssetConflict(assetGuid, path, out var conflictAddress))
                {
                    AddressableHelper.CreateOrUpdateAddressableEntry(assetGuid, path);
                    return;
                }
                Debug.Log($"Asset assigned as a Naninovel `{path}` resource is already registered in the Addressable Asset System as `{conflictAddress}`. It will be copied to prevent conflicts.");
            }

            var objPath      = AssetDatabase.GetAssetPath(asset);
            var resourcePath = PathUtils.Combine(tempResourcesPath, path);

            if (objPath.Contains("."))
            {
                resourcePath += $".{objPath.GetAfter(".")}";
            }

            EditorUtils.CreateFolderAsset(resourcePath.GetBeforeLast("/"));
            AssetDatabase.CopyAsset(objPath, resourcePath);
        }
Exemple #2
0
        private static void ProcessResourceAsset(string assetGuid, string resourcePath, string assetPath, IReadOnlyDictionary <string, Type> projectResources)
        {
            if (projectResources.Keys.Contains(resourcePath)) // Handle assets stored in `Resources`.
            {
                var otherAsset = Resources.Load(resourcePath, typeof(UnityEngine.Object));
                AssetDatabase.TryGetGUIDAndLocalFileIdentifier(otherAsset, out var otherGuid, out long _);
                if (otherAsset && otherGuid != assetGuid) // Check if a different asset is available under the same resources path.
                {
                    var otherPath = AssetDatabase.GetAssetPath(otherAsset);
                    PostprocessBuild();
                    EditorUtility.ClearProgressBar();
                    throw new Exception($"Resource conflict detected: asset stored at `{otherPath}` conflicts with `{resourcePath}` Naninovel resource; rename or move the conflicting asset and rebuild the player.");
                }
                return;
            }

            if (useAddressables)
            {
                if (!AddressableHelper.CheckAssetConflict(assetGuid, resourcePath, out var conflictAddress))
                {
                    AddressableHelper.CreateOrUpdateAddressableEntry(assetGuid, resourcePath, config.GroupByCategory);
                    return;
                }
                Debug.Log($"Asset assigned as a Naninovel `{resourcePath}` resource is already registered in the Addressable Asset System as `{conflictAddress}`. It will be copied to prevent conflicts.");
            }

            var tempPath = string.IsNullOrWhiteSpace(config.ProjectRootPath) ? PathUtils.Combine(TempResourcesPath, resourcePath) : PathUtils.Combine(TempResourcesPath, config.ProjectRootPath, resourcePath);

            if (assetPath.Contains("."))
            {
                tempPath += $".{assetPath.GetAfter(".")}";
            }

            EditorUtils.CreateFolderAsset(tempPath.GetBeforeLast("/"));
            AssetDatabase.CopyAsset(assetPath, tempPath);
        }