Exemple #1
0
 private static (GameObject, long Hash) ImportLayout(IAkyuiImportSettings settings, IAkyuiLoader akyuiLoader, PathGetter pathGetter, AkyuiLogger logger)
 {
     using (logger.SetCategory("Layout"))
     {
         logger.Log($"Import Start");
         var layoutInfo = akyuiLoader.LayoutInfo;
         var triggers   = settings.Triggers.Select(x => (IAkyuiGenerateTrigger)x).ToArray();
         var(gameObject, hash) = AkyuiGenerator.GenerateGameObject(new EditorAssetLoader(pathGetter, logger, settings.Triggers), layoutInfo, triggers);
         foreach (var trigger in settings.Triggers)
         {
             trigger.OnPostprocessPrefab(akyuiLoader, ref gameObject);
         }
         logger.Log($"Import Finish");
         return(gameObject, hash);
     }
 }
Exemple #2
0
        private static (GameObject, long Hash) ImportLayout(IAkyuiImportSettings settings, IAkyuiLoader akyuiLoader, PathGetter pathGetter, AkyuiLogger logger)
        {
            var stopWatch = Stopwatch.StartNew();

            using (logger.SetCategory("Layout"))
            {
                var layoutInfo = akyuiLoader.LayoutInfo;
                var triggers   = settings.Triggers.Select(x => (IAkyuiGenerateTrigger)x).ToArray();
                var(gameObject, hash) = AkyuiGenerator.GenerateGameObject(new EditorAssetLoader(pathGetter, logger, settings.Triggers), layoutInfo, triggers);
                foreach (var trigger in settings.Triggers)
                {
                    trigger.OnPostprocessPrefab(akyuiLoader, ref gameObject);
                }
                logger.Log($"Import Finish", ("time", $"{stopWatch.Elapsed.TotalSeconds:0.00}s"));
                return(gameObject, hash);
            }
        }
Exemple #3
0
        public static void Import(IAkyuiImportSettings settings, IAkyuiLoader[] loaders)
        {
            var logger = new AkyuiLogger("Akyui");

            using (var progressBar = new AkyuiProgressBar("Akyui"))
            {
                progressBar.SetTotal(loaders.Length);
                foreach (var loader in loaders)
                {
                    using (logger.SetCategory(loader.LayoutInfo.Name))
                        using (var progress = progressBar.TaskStart($"Importing {loader.LayoutInfo.Name}"))
                        {
                            Import(settings, loader, logger, progress);
                        }
                }

                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
Exemple #4
0
        private static Object[] ImportAssets(IAkyuiImportSettings settings, IAkyuiLoader akyuiLoader, PathGetter pathGetter, AkyuiLogger logger, IAkyuiProgress progress)
        {
            var stopWatch = Stopwatch.StartNew();

            using (logger.SetCategory("Assets"))
            {
                var assets = new List <Object>();
                var unityAssetsParentPath = Path.GetDirectoryName(Application.dataPath) ?? "";

                var assetOutputDirectoryFullPath = Path.Combine(unityAssetsParentPath, pathGetter.AssetOutputDirectoryPath);
                if (!Directory.Exists(assetOutputDirectoryFullPath))
                {
                    Directory.CreateDirectory(assetOutputDirectoryFullPath);
                }

                var importAssetNames = new List <string>();
                var skipAssetNames   = new List <string>();

                var allAssets = akyuiLoader.AssetsInfo.Assets.ToList();
                foreach (var trigger in settings.Triggers)
                {
                    trigger.OnPreprocessAllAssets(akyuiLoader, ref allAssets);
                }

                progress.SetTotal(allAssets.Count);
                foreach (var tmp in allAssets)
                {
                    var asset = tmp;
                    using (progress.TaskStart(asset.FileName))
                    {
                        var savePath     = Path.Combine(pathGetter.AssetOutputDirectoryPath, asset.FileName);
                        var saveFullPath = Path.Combine(unityAssetsParentPath, savePath);

                        if (!settings.ReimportAsset && File.Exists(saveFullPath))
                        {
                            var import       = AssetImporter.GetAtPath(savePath);
                            var prevUserData = JsonSerializer.Deserialize <Dictionary <string, object> >(import.userData);
                            if (prevUserData["hash"].JsonLong() == asset.Hash)
                            {
                                skipAssetNames.Add(asset.FileName);
                                assets.Add(AssetDatabase.LoadAssetAtPath <Object>(import.assetPath));
                                continue;
                            }
                        }

                        var bytes    = akyuiLoader.LoadAsset(asset.FileName); // Hashチェック後に初めて呼ぶ
                        var userData = new Dictionary <string, object>();
                        userData["hash"] = asset.Hash;

                        if (asset is SpriteAsset)
                        {
                            var texture = new Texture2D(2, 2);
                            texture.LoadImage(bytes);

                            userData["source_width"]  = texture.width;
                            userData["source_height"] = texture.height;
                        }

                        foreach (var trigger in settings.Triggers)
                        {
                            trigger.OnPreprocessAsset(akyuiLoader, ref bytes, ref asset, ref userData);
                        }
                        ImportAsset(asset, savePath, saveFullPath, bytes, userData, settings, logger);
                        assets.Add(AssetDatabase.LoadAssetAtPath <Object>(savePath));
                        importAssetNames.Add(asset.FileName);
                    }
                }

                var importAssets = assets.ToArray();
                foreach (var trigger in settings.Triggers)
                {
                    trigger.OnPostprocessAllAssets(akyuiLoader, importAssets);
                }

                logger.Log($"Import Finish", ("import", importAssetNames.Count), ("skip", skipAssetNames.Count), ("time", $"{stopWatch.Elapsed.TotalSeconds:0.00}s"));

                return(importAssets);
            }
        }