public ModelComposition GetComposition(StoreAsset storeAsset) { var(leftSaber, rightSaber) = GetSabers(storeAsset.Prefab.transform); if (rightSaber == null) { var newParent = new GameObject("RightSaber").transform; newParent.parent = storeAsset.Prefab.transform; rightSaber = Object.Instantiate(leftSaber, newParent, false); rightSaber.transform.position = Vector3.zero; rightSaber.transform.localScale = new Vector3(-1, 1, 1); rightSaber.name = "RightSaberMirror"; rightSaber = newParent.gameObject; rightSaber.SetActive(false); } var storeAssetLeft = new StoreAsset(storeAsset.RelativePath, leftSaber, storeAsset.AssetBundle); var storeAssetRight = new StoreAsset(storeAsset.RelativePath, rightSaber, storeAsset.AssetBundle); var modelLeft = _factory.Create(storeAssetLeft); var modelRight = _factory.Create(storeAssetRight); modelLeft.SaberDescriptor = modelRight.SaberDescriptor = storeAsset.Prefab.GetComponent <SaberDescriptor>(); modelLeft.SaberSlot = ESaberSlot.Left; modelRight.SaberSlot = ESaberSlot.Right; var composition = new ModelComposition(AssetTypeDefinition.CustomSaber, modelLeft, modelRight, storeAsset.Prefab); composition.SetFavorite(_config.IsFavorite(storeAsset.RelativePath)); return(composition); }
private async Task LoadAllMetaDataForLoader(AssetBundleLoader loader, bool createIfNotExisting = false) { var sw = Stopwatch.StartNew(); await Task.Run(async() => { foreach (var assetMetaPath in await _customSaberAssetLoader.CollectFiles()) { var relativePath = PathTools.ToRelativePath(assetMetaPath.MetaDataPath); if (_metaData.TryGetValue(relativePath, out _)) { continue; } if (!assetMetaPath.HasMetaData) { if (createIfNotExisting) { var comp = await await UnityMainThreadTaskScheduler.Factory.StartNew(() => this[PathTools.ToRelativePath(assetMetaPath.Path)]); if (comp == null) { continue; } var metaData = new PreloadMetaData(assetMetaPath, comp, comp.AssetTypeDefinition); await metaData.SaveToFile(); _metaData.Add(relativePath, metaData); } } else { var metaData = new PreloadMetaData(assetMetaPath); await metaData.LoadFromFile(); metaData.IsFavorite = _config.IsFavorite(PathTools.ToRelativePath(assetMetaPath.Path)); _metaData.Add(relativePath, metaData); } } }); sw.Stop(); _logger.Info($"Loaded Metadata in {sw.Elapsed.Seconds}.{sw.Elapsed.Milliseconds}s"); }
private async Task LoadAllMetaDataForLoader(AssetBundleLoader loader, bool createIfNotExisting = false) { var sw = DebugTimer.StartNew("Loading Metadata"); foreach (var assetMetaPath in loader.CollectFiles(_pluginDirs)) { if (_metaData.TryGetValue(assetMetaPath.RelativePath + ".meta", out _)) { continue; } if (!assetMetaPath.HasMetaData) { if (createIfNotExisting) { var comp = await this[PathTools.ToRelativePath(assetMetaPath.Path)]; if (comp == null) { continue; } var metaData = new PreloadMetaData(assetMetaPath, comp, comp.AssetTypeDefinition); metaData.SaveToFile(); _metaData.Add(assetMetaPath.RelativePath + ".meta", metaData); } } else { var metaData = new PreloadMetaData(assetMetaPath); metaData.LoadFromFile(); metaData.IsFavorite = _config.IsFavorite(PathTools.ToRelativePath(assetMetaPath.Path)); _metaData.Add(assetMetaPath.RelativePath + ".meta", metaData); } } sw.Print(_logger); }
public ModelComposition GetComposition(StoreAsset storeAsset) { var(leftSaber, rightSaber) = GetSabers(storeAsset.Prefab.transform); var storeAssetLeft = new StoreAsset(storeAsset.RelativePath, leftSaber, storeAsset.AssetBundle); var storeAssetRight = new StoreAsset(storeAsset.RelativePath, rightSaber, storeAsset.AssetBundle); var modelLeft = _factory.Create(storeAssetLeft); var modelRight = _factory.Create(storeAssetRight); modelLeft.SaberDescriptor = modelRight.SaberDescriptor = storeAsset.Prefab.GetComponent <SaberDescriptor>(); modelLeft.SaberSlot = ESaberSlot.Left; modelRight.SaberSlot = ESaberSlot.Right; var composition = new ModelComposition(AssetTypeDefinition.CustomSaber, modelLeft, modelRight, storeAsset.Prefab); composition.SetFavorite(_config.IsFavorite(storeAsset.RelativePath)); return(composition); }