예제 #1
0
        private IEnumerable <string> ProcessMoveTasks()
        {
            foreach (Task task in tasks.Where(t => t.type == Task.Type.Move && t.status == Task.Status.Pending))
            {
                EditorUtils.EnsureFolderExists(EditorUtils.GetParentFolder(task.destination));

                currentTask = task.step;

                yield return(string.Format("Moving {0} to {1}", task.source, task.destination));

                string result = AssetDatabase.MoveAsset(task.source, task.destination);

                if (string.IsNullOrEmpty(result))
                {
                    task.SetSucceeded(string.Format("{0} was moved to\n{1}", task.source, task.destination));
                }
                else
                {
                    task.SetFailed(string.Format("{0} could not be moved to\n{1}: '{2}'",
                                                 task.source, task.destination, result));
                }

                yield return(task.statusText);
            }
        }
예제 #2
0
            private void GenerateFolderMergeTasks(string sourceFolder, string destinationFolder)
            {
                IEnumerable <string> assetPaths = AssetDatabase.FindAssets(string.Empty, new string[] { sourceFolder })
                                                  .Select(g => AssetDatabase.GUIDToAssetPath(g))
                                                  .Where(p => !AssetDatabase.IsValidFolder(p) || IsFolderEmpty(p));

                foreach (string sourcePath in assetPaths)
                {
                    int prefixLength = sourceFolder.Length;

                    if (!sourceFolder.EndsWith("/"))
                    {
                        ++prefixLength;
                    }

                    string relativePath    = sourcePath.Substring(prefixLength);
                    string destinationPath = string.Format("{0}/{1}", destinationFolder, relativePath);

                    if (!AssetExists(destinationPath))
                    {
                        AddMoveTask(sourcePath, destinationPath);
                        AddFolderTasks(EditorUtils.GetParentFolder(sourcePath));
                    }
                    else if (AssetDatabase.IsValidFolder(sourcePath))
                    {
                        AddFolderTasks(sourcePath);
                    }
                }
            }
예제 #3
0
 private static IEnumerable <string> FindFileAssets(string folder)
 {
     if (AssetDatabase.IsValidFolder(folder))
     {
         return(AssetDatabase.FindAssets(string.Empty, new string[] { folder })
                .Select(g => AssetDatabase.GUIDToAssetPath(g))
                .Where(p => (EditorUtils.GetParentFolder(p) == folder) && !AssetDatabase.IsValidFolder(p)));
     }
     else
     {
         return(Enumerable.Empty <string>());
     }
 }
예제 #4
0
        private static void SelectAssetOrParentFolder(string path)
        {
            while (!AssetExists(path))
            {
                path = EditorUtils.GetParentFolder(path);

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
            }

            Selection.activeObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path);
        }
예제 #5
0
            private void AddFolderTasks(string path)
            {
                string baseFolder = BaseFolders.First(f => path.StartsWith(f));

                string currentFolder = path;

                // Find the last folder in the path that exists, without leaving the base folder
                while (currentFolder.StartsWith(baseFolder) && !AssetDatabase.IsValidFolder(currentFolder))
                {
                    currentFolder = EditorUtils.GetParentFolder(currentFolder);
                }

                while (currentFolder.StartsWith(baseFolder) && currentFolder != baseFolder)
                {
                    AddFolderTask(currentFolder);
                    currentFolder = EditorUtils.GetParentFolder(currentFolder);
                }
            }
예제 #6
0
            private void GenerateTasksForLooseAssets()
            {
                foreach (MoveRecord asset in looseAssets)
                {
                    string filename        = Path.GetFileName(asset.source);
                    string destinationPath = $"Assets/{RuntimeUtils.PluginBasePath}/{asset.destination}/{filename}";

                    if (AssetExists(asset.source) && !AssetExists(destinationPath))
                    {
                        AddMoveTask(asset.source, destinationPath);
                        AddFolderTasks(EditorUtils.GetParentFolder(asset.source));
                    }
                    else if (AssetDatabase.IsValidFolder(asset.source) && AssetDatabase.IsValidFolder(destinationPath))
                    {
                        GenerateFolderMergeTasks(asset.source, destinationPath);
                        AddFolderTasks(asset.source);
                    }
                }
            }
예제 #7
0
            private void GenerateTasksForPlatform(Platform platform)
            {
                IEnumerable <Platform.FileInfo> files = platform.GetSourceFileInfo().Cast <Platform.FileInfo>();

                foreach (BuildTarget buildTarget in platform.GetBuildTargets())
                {
                    files = files.Concat(platform.GetBinaryFileInfo(buildTarget, Platform.BinaryType.All).Cast <Platform.FileInfo>());
                }

                foreach (Platform.FileInfo info in files)
                {
                    string newPath = string.Format("{0}/{1}", AssetsFolder, info.LatestLocation());

                    if (!AssetExists(newPath))
                    {
                        bool   foundPath = false;
                        string oldPath   = null;

                        foreach (string path in info.OldLocations())
                        {
                            oldPath = string.Format("{0}/{1}", AssetsFolder, path);

                            if (tasks.Any(t => t.source == oldPath))
                            {
                                foundPath = true;
                                break;
                            }

                            if (AssetExists(oldPath))
                            {
                                tasks.Add(Task.Move(oldPath, newPath, platform));

                                foundPath = true;
                                break;
                            }
                        }

                        if (oldPath != null)
                        {
                            string oldFolder = EditorUtils.GetParentFolder(oldPath);
                            string newFolder = EditorUtils.GetParentFolder(newPath);

                            if (newFolder != oldFolder)
                            {
                                AddFolderTasks(oldFolder);
                            }
                        }

                        if (!foundPath && ((info.type & Platform.BinaryType.Optional) == 0) &&
                            !tasks.Any(t => t.source == newPath))
                        {
                            tasks.Add(Task.Missing(newPath, platform));
                        }
                    }
                }

                foreach (string path in platform.GetObsoleteAssetPaths())
                {
                    if (AssetExists(path) && !tasks.Any(t => t.source == path))
                    {
                        tasks.Add(Task.RemoveAsset(path, platform));
                    }
                }
            }