예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedBlueGames.MulliganRenamer.RenamePreview"/> class.
 /// </summary>
 /// <param name="objectToRename">Object to rename.</param>
 /// <param name="renameResultSequence">Rename result sequence.</param>
 public RenamePreview(UnityEngine.Object objectToRename, RenameResultSequence renameResultSequence)
 {
     this.ObjectToRename         = objectToRename;
     this.RenameResultSequence   = renameResultSequence;
     this.OriginalPathToObject   = AssetDatabase.GetAssetPath(this.ObjectToRename);
     this.OriginalPathToSubAsset = AssetDatabaseUtility.GetAssetPathWithSubAsset(this.ObjectToRename);
 }
예제 #2
0
        private void AddAssets(string assetRelativePath, List <UnityEngine.Object> assets)
        {
            foreach (var asset in assets)
            {
                if (asset == null)
                {
                    continue;
                }

                var path = AssetDatabaseUtility.GetAssetPathWithSubAsset(asset);
                if (!string.IsNullOrEmpty(path))
                {
                    cachedFilePaths.Add(path);
                }
            }

            this.cachedAssetsInDirectories[assetRelativePath] = assets;
        }
예제 #3
0
        private static List <RenamePreview> GetPreviewsWithDuplicateNames(BulkRenamePreview preview, ref AssetCache assetCache)
        {
            // First collect all assets in directories of preview objects into the assetCache.
            CacheAssetsInSameDirectories(preview, ref assetCache);

            var assetPreviews = new List <RenamePreview>();

            for (int i = 0; i < preview.NumObjects; ++i)
            {
                var previewForObject = preview.GetPreviewAtIndex(i);
                if (previewForObject.ObjectToRename.IsAsset())
                {
                    assetPreviews.Add(previewForObject);
                }
            }

            // Get all the cached file paths, but remove any that are in the preview
            // because those names could be different. We want to test that NEW names
            // don't collide with existing assets.
            HashSet <string> allFinalFilePaths = assetCache.GetAllPathsHashed();

            foreach (var assetPreview in assetPreviews)
            {
                var thisObject = assetPreview.ObjectToRename;
                var assetPath  = AssetDatabaseUtility.GetAssetPathWithSubAsset(thisObject);
                allFinalFilePaths.Remove(assetPath);
            }

            // Now hash the new names and check if they collide with the existing assets
            var problemPreviews        = new List <RenamePreview>();
            var unchangedAssetPreviews = new List <RenamePreview>();
            var changedAssetPreviews   = new List <RenamePreview>();

            // Separate unchangedAssets from changedAsests
            foreach (var assetPreview in assetPreviews)
            {
                var thisObject = assetPreview.ObjectToRename;
                var thisResult = assetPreview.RenameResultSequence;
                if (thisResult.NewName == thisResult.OriginalName)
                {
                    unchangedAssetPreviews.Add(assetPreview);
                }
                else
                {
                    changedAssetPreviews.Add(assetPreview);
                }
            }

            // First add all the unchanged results, so that we collide on the
            // first time adding new names. This fixes an issue where
            // you'd rename one object which now matches a second, but the second gets
            // the warning instead of the first.
            var previewsSorted = new List <RenamePreview>();

            previewsSorted.AddRange(unchangedAssetPreviews);
            previewsSorted.AddRange(changedAssetPreviews);
            foreach (var renamePreview in previewsSorted)
            {
                var resultingPath = renamePreview.GetResultingPath();
                if (allFinalFilePaths.Contains(resultingPath))
                {
                    problemPreviews.Add(renamePreview);
                }
                else
                {
                    allFinalFilePaths.Add(resultingPath);
                }
            }

            return(problemPreviews);
        }