Esempio n. 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);
 }
Esempio n. 2
0
        private static void CacheAsestsInSameDirectoryAsAsset(UnityEngine.Object asset, ref AssetCache assetCache)
        {
            var path           = AssetDatabase.GetAssetPath(asset);
            var assetDirectory = AssetDatabaseUtility.GetDirectoryFromAssetPath(path);

            assetCache.LoadAssetsInAssetDirectory(assetDirectory);
        }
Esempio n. 3
0
        private static void CacheAssetsInSameDirectories(BulkRenamePreview preview, ref AssetCache assetCache)
        {
            for (int i = 0; i < preview.NumObjects; ++i)
            {
                var previewForObject = preview.GetPreviewAtIndex(i);
                var thisObject       = previewForObject.ObjectToRename;
                if (!thisObject.IsAsset())
                {
                    // Scene objects can be named the same thing, so skip these
                    continue;
                }

                var assetDirectory = AssetDatabaseUtility.GetAssetPathDirectory(thisObject);
                assetCache.LoadAssetsInAssetDirectory(assetDirectory);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads the assets in the specified asset relative directory. Caches them for quick repeat access.
        /// </summary>
        /// <returns>The assets in the directory.</returns>
        /// <param name="assetRelativePath">Asset relative path to the directory.</param>
        public List <Object> LoadAssetsInAssetDirectory(string assetRelativePath)
        {
            // Load the assets in the directory or get the previously loaded ones.
            List <Object> assetsInDirectory;

            if (this.cachedAssetsInDirectories.ContainsKey(assetRelativePath))
            {
                assetsInDirectory = this.cachedAssetsInDirectories[assetRelativePath];
            }
            else
            {
                assetsInDirectory = AssetDatabaseUtility.LoadAssetsAtDirectory(assetRelativePath);
                this.AddAssets(assetRelativePath, assetsInDirectory);
            }

            return(assetsInDirectory);
        }
Esempio n. 5
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;
        }
Esempio n. 6
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);
        }