Esempio n. 1
0
        private static void DeleteCriAsset(string sourceFolderPath, string assetFolderPath)
        {
            if (string.IsNullOrEmpty(sourceFolderPath) || string.IsNullOrEmpty(assetFolderPath))
            {
                Debug.LogError("DeleteCriAsset Error.");
                return;
            }

            sourceFolderPath += PathUtility.PathSeparator;
            assetFolderPath   = PathUtility.Combine(UnityPathUtility.GetProjectFolderPath(), assetFolderPath) + PathUtility.PathSeparator;

            if (!Directory.Exists(assetFolderPath))
            {
                return;
            }

            var files = Directory.GetFiles(assetFolderPath, "*", SearchOption.AllDirectories);

            var deleteTargets = files
                                .Where(x => Path.GetExtension(x) != ".meta")
                                .Select(x => Tuple.Create(x, x.Replace(assetFolderPath, sourceFolderPath)))
                                .Where(x => !File.Exists(x.Item2))
                                .ToArray();

            if (deleteTargets.Any())
            {
                var builder = new StringBuilder();

                deleteTargets.ForEach(x => builder.AppendLine(x.Item1.ToString()));

                if (!EditorUtility.DisplayDialog("Delete Confirmation", builder.ToString(), "実行", "中止"))
                {
                    return;
                }

                for (var i = 0; i < deleteTargets.Length; i++)
                {
                    var assetPath = UnityPathUtility.ConvertFullPathToAssetPath(deleteTargets[i].Item1);

                    AssetDatabase.DeleteAsset(assetPath);
                }

                Debug.LogFormat("Delete CriAssets:\n{0}", builder.ToString());
            }

            var deleteDirectorys = DirectoryUtility.DeleteEmpty(assetFolderPath);

            if (deleteDirectorys.Any())
            {
                var builder = new StringBuilder();
                deleteDirectorys.ForEach(x => builder.AppendLine(x));

                Debug.LogFormat("Delete Empty Directory:\n{0}", builder.ToString());
            }
        }
Esempio n. 2
0
        private void CloneAssets()
        {
            DeleteClonedAssets();

            var clonedAssets = new List <string>();

            AssetDatabase.StartAssetEditing();

            foreach (var cloneAsset in cloneAssets)
            {
                if (string.IsNullOrEmpty(cloneAsset.Source) || string.IsNullOrEmpty(cloneAsset.To))
                {
                    Debug.LogError("アセットコピーの設定が正しくありません.");
                    continue;
                }

                var projectFolder = UnityPathUtility.GetProjectFolderPath();

                var source = PathUtility.RelativePathToFullPath(projectFolder, cloneAsset.Source);
                var dest   = PathUtility.RelativePathToFullPath(projectFolder, cloneAsset.To);

                // 除外対象か判定.
                Func <string, bool> ignoreCheck = x =>
                {
                    return(Path.GetExtension(x) != ".meta" &&
                           !string.IsNullOrEmpty(Path.GetFileNameWithoutExtension(x)));
                };

                // メタファイルはコピーしない.
                var cloned = DirectoryUtility.Clone(source, dest, ignoreCheck)
                             .Select(x => UnityPathUtility.ConvertFullPathToAssetPath(x))
                             .ToArray();

                foreach (var item in cloned)
                {
                    AssetDatabase.ImportAsset(item);
                }

                clonedAssets.AddRange(cloned);
            }

            AssetDatabase.StopAssetEditing();

            Prefs.clonedAssets = clonedAssets.Select(x => AssetDatabase.AssetPathToGUID(x)).ToArray();
        }
Esempio n. 3
0
        private static void GenerateTextData(ContentType contentType, GenerateInfo generateInfo)
        {
            var progressTitle = "Generate TextData";

            var config = TextDataConfig.Instance;

            // 読み込み.

            EditorUtility.DisplayProgressBar(progressTitle, "Load contents.", 0f);

            var sheets = LoadSheetData(config.FileFormat, generateInfo.contentsFolderPath);

            if (sheets == null)
            {
                return;
            }

            var cryptoKey = new AesCryptoKey(config.CryptoKey, config.CryptoIv);

            var generateScript = !string.IsNullOrEmpty(generateInfo.scriptFolderPath);

            try
            {
                using (new AssetEditingScope())
                {
                    // Script.

                    if (generateScript)
                    {
                        EditorApplication.LockReloadAssemblies();

                        DirectoryUtility.Clean(generateInfo.scriptFolderPath);

                        AssetDatabase.ImportAsset(generateInfo.scriptFolderPath, ImportAssetOptions.ForceUpdate);

                        EditorUtility.DisplayProgressBar(progressTitle, "Generate script.", 0.25f);

                        CategoryScriptGenerator.Generate(sheets, generateInfo.scriptFolderPath);

                        TextDataScriptGenerator.Generate(sheets, generateInfo.scriptFolderPath);

                        ContentsScriptGenerator.Generate(sheets, generateInfo.scriptFolderPath, generateInfo.textIndex);
                    }

                    // Asset.

                    EditorUtility.DisplayProgressBar(progressTitle, "Generate asset.", 0.5f);

                    var textDataAsset = LoadAsset(generateInfo.assetPath);

                    TextDataAssetGenerator.Build(textDataAsset, contentType, sheets, generateInfo.textIndex, cryptoKey);

                    EditorUtility.DisplayProgressBar(progressTitle, "Complete.", 1f);
                }

                AssetDatabase.SaveAssets();
            }
            finally
            {
                if (generateScript)
                {
                    EditorApplication.UnlockReloadAssemblies();
                }

                AssetDatabase.Refresh();

                EditorUtility.ClearProgressBar();
            }

            EditorUtility.ClearProgressBar();
        }