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 static bool ImportCriAsset(string sourceFolderPath, string assetFolderPath, string[] assetExtensions)
        {
            if (string.IsNullOrEmpty(sourceFolderPath) || string.IsNullOrEmpty(assetFolderPath))
            {
                Debug.LogError("ImportCriAsset Error.");
                return(false);
            }

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

            if (!Directory.Exists(sourceFolderPath))
            {
                Debug.LogWarningFormat("Path Notfound. {0}", sourceFolderPath);
                return(false);
            }

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

            var copyTargets = files
                              .Where(x => assetExtensions.Contains(Path.GetExtension(x)))
                              .Select(x => Tuple.Create(x, PathUtility.Combine(assetFolderPath, x.Replace(sourceFolderPath, string.Empty))))
                              .ToArray();

            if (copyTargets.Any())
            {
                var copyCount = 0;

                var log = new StringBuilder();
                log.AppendLine("Copy MovieAssets:");

                for (var i = 0; i < copyTargets.Length; i++)
                {
                    if (FileCopy(copyTargets[i].Item1, copyTargets[i].Item2))
                    {
                        var assetPath = UnityPathUtility.ConvertFullPathToAssetPath(copyTargets[i].Item2);

                        AssetDatabase.ImportAsset(assetPath);

                        log.AppendLine(assetPath);
                        copyCount++;
                    }
                }

                if (0 < copyCount)
                {
                    Debug.Log(log.ToString());
                }
            }

            return(true);
        }
Esempio n. 3
0
        private static void ImportGeneratedCsFile(string csFilePath, string csFileHash)
        {
            var assetPath = UnityPathUtility.ConvertFullPathToAssetPath(csFilePath);

            var hash = GetCsFileHash(csFilePath);

            if (File.Exists(csFilePath))
            {
                if (csFileHash != hash)
                {
                    AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                }
            }
        }
Esempio n. 4
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();
        }
        private static void DeleteUnusedEnumFiles(string[] generatedScripts, GameTextConfig config)
        {
            var exportPath     = config.EnumScriptFolderPath;
            var exportFullPath = PathUtility.Combine(UnityPathUtility.GetProjectFolderPath(), exportPath);

            if (AssetDatabase.IsValidFolder(exportPath))
            {
                var files = Directory.GetFiles(exportFullPath, "*", SearchOption.TopDirectoryOnly);

                var deleteTargets = files
                                    .Where(x => Path.GetFileName(x) != SheetIdTableScriptFileName)
                                    .Where(x => Path.GetExtension(x) != ".meta" && !generatedScripts.Contains(Path.GetFileName(x)))
                                    .Select(x => UnityPathUtility.ConvertFullPathToAssetPath(x));

                foreach (var target in deleteTargets)
                {
                    if (Path.GetExtension(target) == ".cs")
                    {
                        AssetDatabase.DeleteAsset(target);
                        UnityConsole.Info("File Delete : {0}", target);
                    }
                }
            }
        }
Esempio n. 6
0
        void OnGUI()
        {
            EditorLayoutTools.Title("Generate KeyFile");

            if (string.IsNullOrEmpty(projectFolderPath))
            {
                projectFolderPath = UnityPathUtility.GetProjectFolderPath();
            }

            using (new LabelWidthScope(50f))
            {
                GUILayout.Space(2f);

                EditorGUI.BeginChangeCheck();

                var key = EditorGUILayout.TextField("Key", encryptKey);

                if (EditorGUI.EndChangeCheck())
                {
                    if (!key.IsNullOrEmpty())
                    {
                        if (key.Length == 32)
                        {
                            encryptKey = key;
                        }
                        else
                        {
                            Debug.LogError("Key must be 32 characters");
                        }
                    }
                }

                GUILayout.Space(2f);

                EditorGUI.BeginChangeCheck();

                var iv = EditorGUILayout.TextField("Iv", encryptIv);

                if (EditorGUI.EndChangeCheck())
                {
                    if (!iv.IsNullOrEmpty())
                    {
                        if (iv.Length == 16)
                        {
                            encryptIv = iv;
                        }
                        else
                        {
                            Debug.LogError("Iv must be 16 characters");
                        }
                    }
                }
            }

            GUILayout.Space(2f);

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();

                using (new DisableScope(encryptKey.IsNullOrEmpty() || encryptIv.IsNullOrEmpty()))
                {
                    if (GUILayout.Button("Generate", EditorStyles.miniButton, GUILayout.Width(250f)))
                    {
                        var fileDirectory = Prefs.FileDirectory;

                        if (!Directory.Exists(fileDirectory))
                        {
                            fileDirectory = projectFolderPath;
                        }

                        var filePath = EditorUtility.SaveFilePanel("Generate KeyFile", fileDirectory, "keyfile", string.Empty);

                        if (!filePath.IsNullOrEmpty())
                        {
                            keyFileManager.Create(filePath, encryptKey, encryptIv);

                            var keyFile = keyFileManager.Load(filePath);

                            if (keyFile != null)
                            {
                                using (new DisableStackTraceScope())
                                {
                                    Debug.LogFormat("Generate success.\n\nFilePath: {0}\n\nKey: {1}\nIv: {2}", filePath, keyFile.Key, keyFile.Iv);
                                }

                                var assetPath = UnityPathUtility.ConvertFullPathToAssetPath(filePath);

                                AssetDatabase.ImportAsset(assetPath);

                                Prefs.FileDirectory = Path.GetDirectoryName(filePath);
                            }
                        }
                    }
                }

                GUILayout.Space(5f);
            }

            GUILayout.Space(4f);

            EditorLayoutTools.Title("Check KeyFile");

            GUILayout.Space(2f);

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Load", EditorStyles.miniButton, GUILayout.Width(250f)))
                {
                    var fileDirectory = Prefs.FileDirectory;

                    if (!Directory.Exists(fileDirectory))
                    {
                        fileDirectory = projectFolderPath;
                    }

                    var filePath = EditorUtility.OpenFilePanel("Load KeyFile", fileDirectory, string.Empty);

                    if (!filePath.IsNullOrEmpty())
                    {
                        var keyFile = keyFileManager.Load(filePath);

                        using (new DisableStackTraceScope())
                        {
                            Debug.LogFormat("FilePath: {0}\nKey: {1}\nIv: {2}", filePath, keyFile.Key, keyFile.Iv);
                        }

                        Prefs.FileDirectory = Path.GetDirectoryName(filePath);
                    }
                }

                GUILayout.Space(5f);
            }
        }