예제 #1
0
        /// <summary>Is registered from HQ.</summary>
        /// <param name="guid"></param>
        /// <param name="selectionRect"></param>
        internal static void    OnProjectElementGUI(string guid, Rect selectionRect)
        {
            if (Event.current.type == EventType.Repaint)
            {
                if (ProjectCopyAssets.GUIDs.Contains(guid) == true)
                {
                    selectionRect.x      -= 1F;
                    selectionRect.width   = 1F;
                    selectionRect.y      += 1F;
                    selectionRect.height -= 2F;

                    if (ProjectCopyAssets.cut == true)
                    {
                        EditorGUI.DrawRect(selectionRect, ProjectCopyAssets.CutColor);
                    }
                    else
                    {
                        EditorGUI.DrawRect(selectionRect, ProjectCopyAssets.CopyColor);
                    }
                }
            }
            else if (Event.current.type == EventType.ValidateCommand)
            {
                if (ProjectCopyAssets.skipEvent == false)
                {
                    ProjectCopyAssets.skipEvent = true;

                    if (Event.current.commandName == "Copy")
                    {
                        if (ProjectCopyAssets.ValidateCopyCutAssets() == true)
                        {
                            ProjectCopyAssets.CopyAssets(null);
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.commandName == "Cut")
                    {
                        if (ProjectCopyAssets.ValidateCopyCutAssets() == true)
                        {
                            ProjectCopyAssets.CutAssets(null);
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.commandName == "Paste")
                    {
                        if (ProjectCopyAssets.ValidatePasteAssets() == true)
                        {
                            ProjectCopyAssets.PasteAssets(null);
                            Event.current.Use();
                        }
                    }
                }
            }
            else
            {
                ProjectCopyAssets.skipEvent = false;
            }
        }
예제 #2
0
        private static bool             ValidatePasteAssets()
        {
            for (int i = 0; i < ProjectCopyAssets.copyAssetPaths.Count; i++)
            {
                if (File.Exists(ProjectCopyAssets.copyAssetPaths[i]) == false &&
                    Directory.Exists(ProjectCopyAssets.copyAssetPaths[i]) == false)
                {
                    ProjectCopyAssets.copyAssetPaths.RemoveAt(i--);
                    ProjectCopyAssets.GUIDs.RemoveAt(i--);
                }
            }

            return(ProjectCopyAssets.copyAssetPaths.Count > 0 && ProjectCopyAssets.GetDestinationPath() != null);
        }
예제 #3
0
 private static void             CopyAssets(MenuCommand menuCommand)
 {
     ProjectCopyAssets.cut = false;
     ProjectCopyAssets.ExtractAssetsFromSelection();
 }
예제 #4
0
        private static void             PasteAssets(MenuCommand menuCommand)
        {
            string destination = ProjectCopyAssets.GetDestinationPath();

            if (File.Exists(destination) == true)
            {
                destination = Path.GetDirectoryName(destination);
            }

            if (Directory.Exists(destination) == true)
            {
                for (int i = 0; i < ProjectCopyAssets.copyAssetPaths.Count; i++)
                {
                    string fullPath        = Path.Combine(destination, Path.GetFileName(ProjectCopyAssets.copyAssetPaths[i]));
                    bool   incrementalCopy = false;

                    if (File.Exists(fullPath) == true)
                    {
                        incrementalCopy = true;
                    }

                    if (incrementalCopy == false)
                    {
                        if (ProjectCopyAssets.cut == false)
                        {
                            if (AssetDatabase.CopyAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath) == false)
                            {
                                InternalNGDebug.Log("Copy of \"" + ProjectCopyAssets.copyAssetPaths[i] + "\" into \"" + destination + "\" failed.");
                            }
                        }
                        else
                        {
                            string error = AssetDatabase.MoveAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath);

                            if (string.IsNullOrEmpty(error) == false)
                            {
                                InternalNGDebug.Log(error);
                            }
                            else
                            {
                                ProjectCopyAssets.copyAssetPaths[i] = fullPath;
                            }
                        }
                    }
                    else
                    {
                        string filename  = Path.GetFileNameWithoutExtension(ProjectCopyAssets.copyAssetPaths[i]);
                        string extension = Path.GetExtension(ProjectCopyAssets.copyAssetPaths[i]);
                        int    n         = 0;
                        int    j         = filename.Length - 1;

                        // Extract increment if it exists.
                        while (j >= 0 && '0' <= filename[j] && filename[j] <= '9')
                        {
                            n = n * 10 + filename[j] - '0';
                            --j;
                        }

                        if (n > 0)
                        {
                            filename = filename.Substring(0, j + 1);
                        }
                        else
                        {
                            n         = 1;
                            filename += ' ';
                        }

                        fullPath = Path.Combine(destination, filename + n + extension);

                        while (File.Exists(fullPath) == true)
                        {
                            ++n;
                            fullPath = Path.Combine(destination, filename + n + extension);
                        }

                        if (ProjectCopyAssets.cut == false)
                        {
                            if (AssetDatabase.CopyAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath) == false)
                            {
                                InternalNGDebug.Log("Copy of \"" + ProjectCopyAssets.copyAssetPaths[i] + "\" into \"" + destination + "\" failed.");
                            }
                        }
                        else
                        {
                            string error = AssetDatabase.MoveAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath);

                            if (string.IsNullOrEmpty(error) == false)
                            {
                                InternalNGDebug.Log(error);
                            }
                            ProjectCopyAssets.copyAssetPaths[i] = fullPath;
                        }
                    }

                    AssetDatabase.Refresh();
                }
            }
        }