diff --git a/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs b/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs index 5987c8b0a6..00f332c41d 100644 --- a/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs +++ b/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; using System.IO; +using BrewMonster; +using Cysharp.Threading.Tasks; using UnityEngine; +using UnityEngine.Networking; public class GShopLoader : MonoBehaviour { @@ -13,10 +16,60 @@ public class GShopLoader : MonoBehaviour public GShopData primaryShop = new GShopData(); public GShopData secondaryShop = new GShopData(); - void Start() + + + async void Start() { + #if UNITY_ANDROID && !UNITY_EDITOR + bool result = await MoveShopDataToPersistentPath(); + if (!result) + { + BMLogger.LogError($"ElementDataMan: Failed to move element file to persistent path"); + return; + } + #endif + LoadGShopData(); } + + public async UniTask MoveShopDataToPersistentPath() + { + var destinationPath = Path.Combine(UnityEngine.Application.persistentDataPath, gshopDataPath); + var sourcePath = Path.Combine(UnityEngine.Application.streamingAssetsPath, gshopDataPath); + + + if (!File.Exists(destinationPath)) + { + UnityWebRequest request = UnityWebRequest.Get(sourcePath); + await request.SendWebRequest(); + if (request.result != UnityWebRequest.Result.Success) + { + BMLogger.LogError($"ElementDataMan: Failed to move element file to persistent path: {request.error}"); + return false; + } + File.WriteAllBytes(destinationPath, request.downloadHandler.data); + } + + BMLogger.Log($"ElementDataMan: Successfully moved element file to persistent path: {destinationPath}"); + + destinationPath = Path.Combine(UnityEngine.Application.persistentDataPath, gshop1DataPath); + sourcePath = Path.Combine(UnityEngine.Application.streamingAssetsPath, gshop1DataPath); + + if (!File.Exists(destinationPath)) + { + var request = UnityWebRequest.Get(sourcePath); + await request.SendWebRequest(); + if (request.result != UnityWebRequest.Result.Success) + { + BMLogger.LogError($"ElementDataMan: Failed to move element file to persistent path: {request.error}"); + return false; + } + File.WriteAllBytes(destinationPath, request.downloadHandler.data); + } + + BMLogger.Log($"ElementDataMan: Successfully moved element file to persistent path: {destinationPath}"); + return true; + } public void LoadGShopData() { diff --git a/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs b/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs index 5852c77ded..cbfe003ec0 100644 --- a/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs +++ b/Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs @@ -9,6 +9,7 @@ using BrewMonster.UI; using CSNetwork; using Cysharp.Threading.Tasks; using UnityEngine; +using UnityEngine.Networking; namespace BrewMonster.Scripts.Task { @@ -450,13 +451,40 @@ namespace BrewMonster.Scripts.Task }, _cts.Token); } #else - string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data"); - await pTaskMan.LoadTasksFromPack(task_data_path, true); + bool result = await MoveShopDataToPersistentPath("data/tasks.data"); + if (!result) + { + BMLogger.LogError($"CECTaskInterface: Failed to move tasks data to persistent path"); + return false; + } + string task_data_path = Path.Combine(Application.persistentDataPath, "data/tasks.data"); + await pTaskMan.LoadTasksFromPack(task_data_path, true, (x) => {}, _cts.Token); #endif + +#if UNITY_ANDROID && !UNITY_EDITOR + result = await MoveShopDataToPersistentPath("data/tasks.data"); + if (!result) + { + BMLogger.LogError($"CECTaskInterface: Failed to move tasks data to persistent path"); + return false; + } + var task_npc_path = Path.Combine(Application.persistentDataPath, "data/task_npc.data"); +#else var task_npc_path = Path.Combine(Application.streamingAssetsPath, "data/task_npc.data"); +#endif await pTaskMan.LoadNPCInfoFromPack(task_npc_path); - + +#if UNITY_ANDROID && !UNITY_EDITOR + result = await MoveShopDataToPersistentPath("data/tasks.data"); + if (!result) + { + BMLogger.LogError($"CECTaskInterface: Failed to move tasks data to persistent path"); + return false; + } + var dyn_tasks_path = Path.Combine(Application.persistentDataPath, "data/dyn_tasks.data"); +#else var dyn_tasks_path = Path.Combine(Application.streamingAssetsPath, "data/dyn_tasks.data"); +#endif await pTaskMan.VerifyDynTasksPack(dyn_tasks_path); InitActiveTaskList(); @@ -467,6 +495,33 @@ namespace BrewMonster.Scripts.Task return true; } + + public async UniTask MoveShopDataToPersistentPath(string shopDataPath) + { + BMLogger.Log($"CECTaskInterface: Moving shop data to persistent path: {shopDataPath}"); + var destinationPath = Path.Combine(UnityEngine.Application.persistentDataPath, shopDataPath); + var sourcePath = Path.Combine(UnityEngine.Application.streamingAssetsPath, shopDataPath); + + + if (File.Exists(destinationPath)) + { + return true; + } + + var destinationDirectory = Path.GetDirectoryName(destinationPath); + Directory.CreateDirectory(destinationDirectory); + + UnityWebRequest request = UnityWebRequest.Get(sourcePath); + await request.SendWebRequest(); + if (request.result != UnityWebRequest.Result.Success) + { + BMLogger.LogError($"CECTaskInterface: Failed to move element file to persistent path: {request.error}"); + return false; + } + File.WriteAllBytes(destinationPath, request.downloadHandler.data); + BMLogger.Log($"CECTaskInterface: Successfully moved element file to persistent path: {destinationPath}"); + return true; + } public void CheckPQEnterWorldInit() { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 14a0cceaa0..8bb05ae98f 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -12,7 +12,7 @@ PlayerSettings: targetDevice: 2 useOnDemandResources: 0 accelerometerFrequency: 60 - companyName: DefaultCompany + companyName: BrewMonster productName: perfect-world-unity defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} @@ -70,6 +70,7 @@ PlayerSettings: androidStartInFullscreen: 1 androidRenderOutsideSafeArea: 1 androidUseSwappy: 1 + androidDisplayOptions: 1 androidBlitType: 0 androidResizeableActivity: 1 androidDefaultWindowWidth: 1920 @@ -164,14 +165,14 @@ PlayerSettings: androidMaxAspectRatio: 2.4 androidMinAspectRatio: 1 applicationIdentifier: - Android: com.DefaultCompany.perfectworldunity + Android: com.bm.pw iPhone: com.DefaultCompany.perfect-world-unity buildNumber: Standalone: 0 VisionOS: 0 iPhone: 0 tvOS: 0 - overrideDefaultApplicationIdentifier: 0 + overrideDefaultApplicationIdentifier: 1 AndroidBundleVersionCode: 1 AndroidMinSdkVersion: 23 AndroidTargetSdkVersion: 0