private void LoadAssetFromStorage(AssetInfo assetInfo, PrefabObject o) { string assetName = assetInfo.AssetName; string assetBundleUri = ProjectData.ProjectStructure.IsMobile ? o.AndroidBundleResource : o.BundleResource; RequestFileRead requestAssetData = new RequestFileRead(assetBundleUri); requestAssetData.OnFinish += responseData => { ResponseFileRead responseFileRead = (ResponseFileRead)responseData; var bundleData = responseFileRead.ByteData; RequestLoadAssetFromMemory requestAsset = new RequestLoadAssetFromMemory(assetName, bundleData, new object[] { o, assetInfo }); requestAsset.OnFinish += response => { FeedBackText = LanguageManager.Instance.GetTextValue("LOADING") + " " + o.Config.i18n.GetCurrentLocale() + "..."; CreatePrefabEntity(response, o); }; }; }
private void LoadObject(PrefabObject o) { RequestFileRead request = new RequestFileRead(o.ConfigResource); request.OnFinish += response => { string json = ((ResponseFileRead)response).TextData; AssetInfo assetInfo = null; if (!LoadAssetInfo(json, ref assetInfo, o)) { return; } string mainAssembly = FindMainAssembly(assetInfo, o); foreach (string dllName in assetInfo.Assembly) { if (dllName != mainAssembly) { LoadDll(o, dllName); } } LoadDll(o, mainAssembly); LoadAssetFromStorage(assetInfo, o); }; request.OnError += s => { Helper.ShowErrorLoadObject(o, s); }; }
/// <summary> /// Sort objects if already loaded /// </summary> /// <param name="objects"></param> /// <returns></returns> public List <PrefabObject> GetRequiredObjects(List <PrefabObject> objects) { List <PrefabObject> result = new List <PrefabObject>(objects); List <PrefabObject> alreadyLoaded = GameStateData.GetPrefabsData(); List <PrefabObject> resultRemove = new List <PrefabObject>(); foreach (PrefabObject o in result) { PrefabObject found = alreadyLoaded.Find(prefabObject => prefabObject.Id == o.Id); if (found != null) { var loaded = result.Find(prefabObject => prefabObject.Id == o.Id); resultRemove.Add(loaded); Debug.Log(o.Config.i18n.en + " is already loaded"); } else { Debug.Log(o.Config.i18n.en + " is required"); } Debug.Log(o.Config.i18n.en + "was added to WorldStructure.SceneObjects"); } foreach (PrefabObject o in resultRemove) { result.Remove(o); } return(result); }
private void LoadDll(PrefabObject o, string dllName) { string dllCachePath = Path.Combine(Application.dataPath, "/cache/dll/" + o.Config.i18n.en + o.Guid); string dllPath = o.Resources + "/" + dllName; new RequestFileRead(dllPath).OnFinish += response1 => { var byteData = ((ResponseFileRead)response1).ByteData; bool error = !AddAssembly(dllCachePath, dllName, ref byteData); if (!error) { return; } string message = ErrorHelper.GetErrorDescByCode(Varwin.Errors.ErrorCode.LoadObjectError) + "\n" + o.Config.i18n.GetCurrentLocale(); Logger.Fatal(message); FeedBackText = message; RequestManager.Instance.StopRequestsWithError(message); }; }
private void LoadDll(PrefabObject o, string dllName) { string dllCachePath = FileSystemUtils.GetFilesPath(ProjectData.ProjectStructure.IsMobile, "cache/dll/") + o.Config.i18n.en + o.Guid; string dllPath = o.Resources + "/" + dllName; new RequestUri(dllPath).OnFinish += response1 => { byte[] byteData = ((ResponseUri)response1).ByteData; bool error = !AddAssembly(dllCachePath, dllName, ref byteData); if (!error) { return; } string message = ErrorHelper.GetErrorDescByCode(Varwin.Errors.ErrorCode.LoadObjectError) + "\n" + o.Config.i18n.GetCurrentLocale(); Logger.Fatal(message); FeedBackText = message; RequestManager.Instance.StopRequestsWithError(message); }; }
protected static string FindMainAssembly(AssetInfo assetInfo, PrefabObject o) { try { string result = assetInfo.Assembly.Find(x => Regex.Match(x, $"^{o.Config.type.Split('.')[0]}").Success); return(result); } catch { LogManager.GetCurrentClassLogger().Fatal("Can not find main assembly"); return(null); } }
protected bool LoadAssetInfo(string json, ref AssetInfo assetInfo, PrefabObject o) { LauncherErrorManager launcherErrorManager = LauncherErrorManager.Instance; VRErrorManager vrErrorManager = VRErrorManager.Instance; try { assetInfo = json.JsonDeserialize <AssetInfo>(); if (assetInfo.AssetName != null) { return(true); } string message = $"Asset name can not be null. {o.Config.i18n.en} Bundle.json is not actual version!"; LogManager.GetCurrentClassLogger().Fatal(message); RequestManager.Instance.StopRequestsWithError(message); if (launcherErrorManager != null) { launcherErrorManager.ShowFatal($"{o.Config.i18n.en} not actual!", "null asset"); } if (vrErrorManager != null) { vrErrorManager.ShowFatal($"{o.Config.i18n.en} not actual!", "null asset"); } return(false); } catch (Exception e) { string message = $"AssetInfo can not be loaded. {o.Config.i18n.en} Bundle.json is not actual version! Bundle.json = {json}"; LogManager.GetCurrentClassLogger().Fatal(message); RequestManager.Instance.StopRequestsWithError(message); if (launcherErrorManager != null) { launcherErrorManager.ShowFatal($"{o.Config.i18n.en} not actual!", e.StackTrace); } if (vrErrorManager != null) { vrErrorManager.ShowFatal($"{o.Config.i18n.en} not actual!", e.StackTrace); } return(false); } }
protected void CreatePrefabEntity(IResponse response, PrefabObject o, Sprite icon = null) { var alreadyLoaded = GameStateData.GetPrefabData(o.Id); if (alreadyLoaded != null) { LoadCounter.loadObjectsCounter.PrefabsLoaded++; LogManager.GetCurrentClassLogger().Info(o.Config.i18n.en + " was ignored, because it already loaded"); return; } ResponseAsset responseAsset = (ResponseAsset)response; Object unityObject = responseAsset.Asset; PrefabObject serverObject = (PrefabObject)responseAsset.UserData[0]; GameEntity entity = Contexts.sharedInstance.game.CreateEntity(); entity.AddServerObject(serverObject); GameStateData.AddPrefabGameObject(serverObject.Id, responseAsset.Asset, o); GameStateData.AddObjectIcon(serverObject.Id, icon); entity.AddIcon(icon); if (o.Embedded) { GameStateData.AddToEmbeddedList(serverObject.Id); } GameObject gameObject = unityObject as GameObject; if (gameObject != null) { entity.AddGameObject(gameObject); } else { string message = $"Game object is null in asset {o.Config.i18n.en}"; Logger.Fatal(message); RequestManager.Instance.StopRequestsWithError(message); return; } LoadCounter.loadObjectsCounter.PrefabsLoaded++; LogManager.GetCurrentClassLogger().Info(o.Config.i18n.en + " is loaded"); }
private void LoadCustomAssetApi(AssetInfo assetInfo, PrefabObject o) { string assetName = assetInfo.AssetName; string assetBundleUri = ProjectData.IsMobileVr() ? o.AndroidBundleResource : o.BundleResource; RequestAsset requestAsset = new RequestAsset(assetName, assetBundleUri, new object[] { o, assetInfo }); requestAsset.OnFinish += responseAsset => { FeedBackText = LanguageManager.Instance.GetTextValue("LOADING") + " " + o.Config.i18n.GetCurrentLocale() + "..."; CountLoadedObjects++; if (LoaderAdapter.OnDownLoadUpdate != null) { LoaderAdapter.OnDownLoadUpdate(CountLoadedObjects / (float)LoadCounter.loadObjectsCounter.PrefabsCount); } RequestTexture requestDownLoad = new RequestTexture(Settings.Instance().ApiHost + o.IconResource, 128, 128, ProjectData.IsMobileVr() ? TextureFormat.ASTC_RGB_6x6 : TextureFormat.DXT1); requestDownLoad.OnFinish += responseUri => { ResponseTexture responseTexture = (ResponseTexture)responseUri; Texture2D texture2D = responseTexture.Texture; Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, 128, 128), Vector2.zero); CreatePrefabEntity(responseAsset, o, sprite); }; requestDownLoad.OnError += s => { CreatePrefabEntity(responseAsset, o); }; }; }