示例#1
0
        private static void Import(IAkyuiImportSettings settings, IAkyuiLoader akyuiLoader, AkyuiLogger logger, IAkyuiProgress progress)
        {
            var stopWatch = Stopwatch.StartNew();

            CheckVersion(akyuiLoader);

            Settings = settings;
            using (Disposable.Create(() => Settings = null))
            {
                var pathGetter         = new PathGetter(settings, akyuiLoader.LayoutInfo.Name);
                var prevMetaGameObject = AssetDatabase.LoadAssetAtPath <GameObject>(pathGetter.MetaSavePath);
                var prevMeta           = prevMetaGameObject != null?prevMetaGameObject.GetComponent <AkyuiMeta>() : null;

                var prevAssets = prevMeta != null ? prevMeta.assets : new Object[] { };

                if (!settings.ReimportLayout && prevMeta != null && prevMeta.hash == akyuiLoader.LayoutInfo.Hash)
                {
                    logger.Log("Skip", ("hash", akyuiLoader.LayoutInfo.Hash));
                    return;
                }

                var assets = ImportAssets(settings, akyuiLoader, pathGetter, logger, progress);
                var(gameObject, hash) = ImportLayout(settings, akyuiLoader, pathGetter, logger);
                DeleteUnusedAssets(prevAssets, assets, logger);

                var metaGameObject = new GameObject(akyuiLoader.LayoutInfo.Name);
                gameObject.transform.SetParent(metaGameObject.transform);
                var akyuiMeta = metaGameObject.AddComponent <AkyuiMeta>();
                akyuiMeta.hash     = hash;
                akyuiMeta.root     = gameObject;
                akyuiMeta.assets   = assets;
                akyuiMeta.userData = akyuiLoader.LayoutInfo.UserData.Select(x => new AkyuiMetaUserData {
                    key = x.Key, value = x.Value
                }).ToArray();

                AkyuiEditorUtil.CreateDirectory(Path.GetDirectoryName(pathGetter.PrefabSavePath));
                AkyuiEditorUtil.CreateDirectory(Path.GetDirectoryName(pathGetter.MetaSavePath));

                PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, pathGetter.PrefabSavePath, InteractionMode.AutomatedAction);
                PrefabUtility.SaveAsPrefabAsset(metaGameObject, pathGetter.MetaSavePath);

                foreach (var trigger in settings.Triggers)
                {
                    trigger.OnPostprocessFile(akyuiLoader, pathGetter);
                }

                Object.DestroyImmediate(metaGameObject);
            }

            stopWatch.Stop();
            logger.Log($"Import Finish", ("time", $"{stopWatch.Elapsed.TotalSeconds:0.00}s"));
        }
示例#2
0
 public EditorAssetLoader(PathGetter pathGetter, AkyuiLogger logger, IAkyuiImportTrigger[] triggers)
 {
     _pathGetter = pathGetter;
     _logger     = logger;
     _triggers   = triggers;
 }
示例#3
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);
            }
        }
示例#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);
            }
        }
示例#5
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);
     }
 }
示例#6
0
        private static (GameObject, uint Hash, IDictionary <uint, GameObject> EidMap, ImportLayoutLog) ImportLayout(IAkyuiImportSettings settings, IAkyuiLoader akyuiLoader, PathGetter pathGetter, AkyuiLogger logger)
        {
            var stopWatch  = Stopwatch.StartNew();
            var layoutInfo = akyuiLoader.LayoutInfo;
            var triggers   = settings.Triggers.Select(x => (IAkyuiGenerateTrigger)x).ToArray();

            var(gameObject, hash, eidMap) = AkyuiGenerator.GenerateGameObject(new EditorAssetLoader(pathGetter, logger, settings.Triggers), layoutInfo, triggers);
            foreach (var trigger in settings.Triggers)
            {
                trigger.OnPostprocessPrefab(akyuiLoader, ref gameObject);
            }
            return(gameObject, hash, eidMap, new ImportLayoutLog {
                Time = stopWatch.Elapsed.TotalSeconds
            });
        }