Exemple #1
0
        private bool ChangeNameMapFolder(string proposedFolder)
        {
            if (string.Equals(proposedFolder, _nameMapPath, StringComparison.OrdinalIgnoreCase) || !AssetPath.IsProjectPath(proposedFolder))
            {
                return(false);
            }

            proposedFolder = AssetPath.ProjectRelativePath(proposedFolder);
            AssetPath.EnsurePath(proposedFolder);

            //Move map from current location to new location.
            if (!string.IsNullOrEmpty(_nameMapPath))
            {
                var existingFile = AssetPath.Combine(AssetPath.GetFullPath(_nameMapPath), NameMapFileName);

                if (File.Exists(existingFile))
                {
                    var oldFilePath = AssetPath.Combine(_nameMapPath, NameMapFileName);
                    var newFilePath = AssetPath.Combine(proposedFolder, NameMapFileName);

                    var msg = AssetDatabase.MoveAsset(oldFilePath, newFilePath);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        EditorUtility.DisplayDialog("Error Moving Asset", msg, "Ok");
                        return(false);
                    }
                    else
                    {
                        AssetDatabase.Refresh();
                    }
                }
            }

            _nameMapPath = proposedFolder;

            return(true);
        }
Exemple #2
0
        private bool ChangeStorageFolder(string proposedFolder)
        {
            if (string.Equals(proposedFolder, _storagePath, StringComparison.OrdinalIgnoreCase) || !AssetPath.IsProjectPath(proposedFolder))
            {
                return(false);
            }

            proposedFolder = AssetPath.ProjectRelativePath(proposedFolder);
            bool apexified = proposedFolder.EndsWith("Resources/" + AIManager.StorageFolder);

            if (!proposedFolder.EndsWith("Resources") && !apexified)
            {
                EditorUtility.DisplayDialog("Invalid Storage Folder", "The storage folder selected must be a Resources folder. This can however be anywhere inside the Assets folder.", "Ok");
                return(false);
            }

            if (!apexified)
            {
                proposedFolder = AssetPath.Combine(proposedFolder, AIManager.StorageFolder);
            }

            AssetPath.EnsurePath(proposedFolder);

            //Move files from current storage location to new location.
            var fullStoragePath = AssetPath.GetFullPath(_storagePath);

            if (Directory.Exists(fullStoragePath))
            {
                foreach (var asset in Directory.GetFiles(fullStoragePath, "*.asset", SearchOption.TopDirectoryOnly))
                {
                    var fileName = Path.GetFileName(asset);
                    var msg      = AssetDatabase.MoveAsset(AssetPath.ProjectRelativePath(asset), AssetPath.Combine(proposedFolder, fileName));
                    if (!string.IsNullOrEmpty(msg))
                    {
                        EditorUtility.DisplayDialog("Error Moving Assets", msg, "Ok");
                        return(false);
                    }
                }

                AssetDatabase.DeleteAsset(_storagePath);
            }

            _storagePath = proposedFolder;

            return(true);
        }