/// <summary> /// Загружает пакет ресурсов в память /// </summary> /// <param name="parAssetPack">Пакет ресурсов</param> /// <param name="parCustomAssetBuilder">Определенный строитель-загрузчик</param> /// <param name="parAssetPackName">Имя пакета ресурсов</param> public void LoadAssetPack(AssetPack parAssetPack, AssetDataAbstractBuilder parCustomAssetBuilder = null, string parAssetPackName = null) { AssetDataAbstractBuilder actualAssetDataBuilder = parCustomAssetBuilder ?? StandardAssetBuilder; //проверим, если этот пакет уже загружен parAssetPackName = parAssetPackName ?? AvailableAssetPacks.FirstOrDefault(parX => parX.Value == parAssetPack).Key; if (LoadedAssetPacks.ContainsKey(parAssetPackName)) { //выгрузим его сначала UnloadAssetPack(LoadedAssetPacks[parAssetPackName]); Console.WriteLine("Unloading asset pack because it has been already loaded in memory"); } //а затем снова загрузим Dictionary <string, AssetDataParent> assetPackData = new Dictionary <string, AssetDataParent>(); foreach (var contentData in parAssetPack.Content) { assetPackData.Add(contentData.Key, actualAssetDataBuilder.LoadAssetData <AssetDataParent>(contentData.Value)); Console.WriteLine($"Loaded data {contentData.Key} in asset pack {parAssetPackName}"); } LoadedAssetPacks.Add(parAssetPackName, new AssetPackLoadedData(assetPackData)); }
//TODO combine/put all this data in separate data structure public void AppRun(AssetDataAbstractBuilder parInitialAssetBuilder, IAssetDatabaseUpdateStrategy parInitialAssetDatabaseUpdateStrategy, SoundManagerColleague parViewSoundManagerColleague, ViewProviderColleague parViewSideViewProviderColleague) { if (CurrentAppState.CurrentBaseAppState != EBaseAppStates.Created) { throw new Exception("Already launched application model cannot be launched again!"); } CurrentAppState = new AppState() { CurrentBaseAppState = EBaseAppStates.Running }; //initialize resources manager AppResourceManager = new ResourceManager(AppInfoConsts.ResourcesAssetsDirpath, parInitialAssetBuilder, parInitialAssetDatabaseUpdateStrategy); // AppResourceManager.LoadAssetPack("packTest"); // AppResourceManager.LoadAssetPack("gfx_smd"); // Console.WriteLine($"{AppResourceManager.GetAssetData<AssetDataText>("packTest", "/data.txt").TextData[0]}"); //initialize sound manager ActualSoundManager = new AppSoundManager(AppResourceManager, this); ActualSoundManager.AppSoundManagerMediator.ViewSoundManagerColleague = parViewSoundManagerColleague; parViewSoundManagerColleague.Mediator = ActualSoundManager.AppSoundManagerMediator; ActualSoundManager.UpdateLibrary(); AppViewProviderMediator.ViewProviderViewSide = parViewSideViewProviderColleague; InitializeHumanPlayers(); /* * var testObj = AppGamePool.GetObject<GameObject>(typeof(GameObject)); * testObj.Init(this); * Console.WriteLine($"{testObj.LinkedAppModel}"); * testObj.DisableAndSendToPool(); * Console.WriteLine($"{testObj.LinkedAppModel}"); * Console.WriteLine($"{testObj.Test}"); */ GameObject launchingObject = AppGamePool.GetObject <GameObject>(typeof(GameObject)); launchingObject.Init(this); launchingObject.AddComponent <AppStartComponent>(AppGamePool .GetObject <AppStartComponent>(typeof(AppStartComponent)).Init(launchingObject)); //var testComp = AppGamePool.GetObject<TestInputExitComponent>(typeof(TestInputExitComponent)); //testComp.Init(testObj); //RegisterFixedUpdatableObject(new InputTestUpdatableObject(this)); //new InputTestUpdatableObject(this); //TODO: Application startup logic //TODO: Settings loading //TODO: App state machine definitions //TODO: Multithreading for physics }
/// <summary> /// Загружает пакет ресурсов в память /// </summary> /// <param name="parAssetPackName">Имя пакета ресурсов</param> /// <param name="parCustomAssetBuilder">Определенный строитель-загрузчик</param> /// <exception cref="ArgumentException">Пакет ресурсов не был найден</exception> public void LoadAssetPack(string parAssetPackName, AssetDataAbstractBuilder parCustomAssetBuilder = null) { if (AvailableAssetPacks.TryGetValue(parAssetPackName, out AssetPack assetPack)) { LoadAssetPack(assetPack, parCustomAssetBuilder, parAssetPackName); } else { throw new ArgumentException("Asset pack with the specified name was not found in database"); } }
/// <summary> /// Стандартный конструктор /// </summary> /// <param name="parAssetDatabaseDir">Директория для составления начальной базы данных ассетов</param> /// <param name="parInitialAssetBuilder">"Строитель"-загрузчик ресурсов</param> /// <param name="parAssetDatabaseUpdateStrategy">Стратегия составления начальной базы данных ассетов</param> public ResourceManager(string parAssetDatabaseDir, AssetDataAbstractBuilder parInitialAssetBuilder = null, IAssetDatabaseUpdateStrategy parAssetDatabaseUpdateStrategy = null) { AssetDatabaseDir = parAssetDatabaseDir; AvailableAssetPacks = new Dictionary <string, AssetPack>(); LoadedAssetPacks = new Dictionary <string, AssetPackLoadedData>(); StandardAssetBuilder = parInitialAssetBuilder ?? new AssetDataStandardBuilder(); StandardAssetDatabaseUpdateStrategy = parAssetDatabaseUpdateStrategy ?? new AssetDatabaseUpdateDiffByExtensionStrategy( StandardExtensionToAssetType); UpdateAssetsAvailableDatabase(StandardAssetDatabaseUpdateStrategy); }