424 lines
17 KiB
C#
424 lines
17 KiB
C#
|
|
using asap.core;
|
|
using asap.core.common;
|
|
using game;
|
|
using Game;
|
|
using GameCore;
|
|
using System;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using AppsFlyerSDK;
|
|
using DataCenter;
|
|
using Script.RuntimeScript;
|
|
using ThinkingData.Analytics;
|
|
using tysdk;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.Rendering.Universal;
|
|
using UnityEngine.AddressableAssets;
|
|
using Newtonsoft.Json.Linq;
|
|
using MoreMountains.NiceVibrations;
|
|
|
|
public class SubBoostrap
|
|
{
|
|
|
|
public static async System.Threading.Tasks.Task RegisterServices(GameObject rootCtxGo)
|
|
{
|
|
var container = GContext.container;
|
|
VibrationController vibrationController = new VibrationController();
|
|
vibrationController.Init();
|
|
container.RegisterInstance(vibrationController);
|
|
container.Register<IObjectPoolService, ObjectPoolService>().AsSingleton();
|
|
|
|
|
|
#if AGG && !UNITY_EDITOR //AIHelp init
|
|
//string appKey = "TUYOOGAME_app_a6e73dd23da84d5ab72a5f68e4a58271";
|
|
string domain = "tuyoogame.aihelp.net";
|
|
#if UNITY_ANDROID
|
|
string appId = "tuyoogame_platform_7a6a236be774b7a82c23d3e59f7d1476";
|
|
#elif UNITY_IOS
|
|
string appId = "tuyoogame_platform_782757bd1f7ba24498cd9df0d0b9f214";
|
|
#endif
|
|
|
|
AIHelp.AIHelpSupport.enableLogging(false);
|
|
AIHelp.AIHelpSupport.AdditionalSupportFor(AIHelp.PublishCountryOrRegion.IN);
|
|
|
|
AIHelp.AIHelpSupport.RegisterAsyncEventListener(AIHelp.EventType.Initialization, (jsonEventData, ack)
|
|
=>Debug.Log($"[HotUpateBoostrap] AIHelpInitialized {JObject.Parse(jsonEventData).ToString()}"));
|
|
|
|
AIHelp.AIHelpSupport.Initialize(domain, appId);
|
|
|
|
#endif //AIHelp init end
|
|
|
|
#if AGG
|
|
var heartBeat = new HeartBeat();
|
|
#endif
|
|
using (container.InjectionScope())
|
|
{
|
|
#if AGG
|
|
container.RegisterInstance(heartBeat);
|
|
#endif
|
|
container.Register<ISoundService, SoundService>().AsSingleton();
|
|
container.Register<ILoadResourceService, LoadResourceService>().AsSingleton();
|
|
container.Register<SoundMgr>().AsSingleton();
|
|
container.Register<TileNewsManager>().AsSingleton();
|
|
}
|
|
|
|
#if AGG
|
|
heartBeat.Init();
|
|
#endif
|
|
|
|
var rtsManager = new GameObject("RTSManager").AddComponent<RTServiceBgFgManager>();
|
|
GameObject.DontDestroyOnLoad(rtsManager);
|
|
|
|
|
|
/*
|
|
* _____ ___ ____ ___
|
|
*|_ _/ _ \| _ \ / _ \
|
|
* | || | | | | | | | | |
|
|
* | || |_| | |_| | |_| |
|
|
* |_| \___/|____/ \___/
|
|
*/
|
|
// TODO Refactor all managers
|
|
#if UNITY_EDITOR
|
|
UnityEngine.Application.runInBackground = true;
|
|
GameCore.GameEventMgr.Init(true);
|
|
#else
|
|
GameCore.GameEventMgr.Init();
|
|
#endif
|
|
rootCtxGo.AddComponent<PlayFabMgr>();
|
|
// TODO Replace DataCenter with seprated data class
|
|
// Create();
|
|
// -----------------------------------------
|
|
await Awaiters.NextFrame;
|
|
GameCore.Timer.Create();
|
|
//-----------------------TODO--------------------------
|
|
Debug.Log("[HotUpateBoostrap] RegisterServices Done");
|
|
await Awaiters.NextFrame;
|
|
}
|
|
|
|
public static async System.Threading.Tasks.Task AfterAssetUpdate(IConfig config, Action<float> progressAction)
|
|
{
|
|
#if UNITY_EDITOR
|
|
var tables = await cfg.Tables.InitEditor(progress => progressAction(0.16f + progress * 0.02f));
|
|
#else
|
|
var tables = await cfg.Tables.Init(progress => progressAction(0.16f + progress * 0.02f));
|
|
#endif
|
|
var container = GContext.container;
|
|
GContext.container.RegisterInstance(tables);
|
|
GContext.container.Register<IFaceUIService, FaceUIService>().AsSingleton();
|
|
GContext.container.Register<IUIService, UIService>().AsSingleton();
|
|
GContext.container.Register<IChatService, ChatService>().AsSingleton();
|
|
GContext.container.Register<IReportService, ReportService>().AsSingleton();
|
|
GContext.container.Register<ILocalNotificationService, LocalNotificationService>().AsSingleton();
|
|
GContext.container.Register<ICustomServerMgr, CustomServerMgr>().AsSingleton();
|
|
GContext.container.Register<IInGameMailService, InGameMailService>().AsSingleton();
|
|
GContext.container.Register<IRTService, SignalRService>().AsSingleton();
|
|
GContext.container.RegisterInstance(new AvatarService());
|
|
|
|
var settings = new DefaultSettingService();
|
|
settings.Init(tables);
|
|
GContext.container.RegisterInstance<ISettingService>(settings);
|
|
GameCore.LocalizationMgr.Init();
|
|
QualityManager.AutoSetQualityLevel();
|
|
RootCtx.showFPS = !string.IsNullOrEmpty(config.Get(GConstant.K_FPS, string.Empty));
|
|
DebugFunc.Init();
|
|
|
|
zzwater.URPHelper.RendererFeatureSetActive(false, "FSBlur");
|
|
zzwater.URPHelper.RendererFeatureSetActive(false, "FSWave");
|
|
|
|
await InitVibration();
|
|
//#if UNITY_ANDROID
|
|
//RequestAndriodPermission();
|
|
//#endif
|
|
await Awaiters.NextFrame;
|
|
|
|
await GContext.container.Resolve<ILocalNotificationService>().Init();
|
|
|
|
IAdsService adsService;
|
|
|
|
if (Application.isEditor)
|
|
{
|
|
adsService = new DevAdsService();
|
|
}
|
|
else
|
|
{
|
|
adsService = new AggAdsService(settings);
|
|
}
|
|
adsService.Init();
|
|
GContext.container.RegisterInstance<IAdsService>(adsService);
|
|
|
|
Debug.Log("[HotUpateBoostrap] AfterAssetUpdate Done");
|
|
|
|
}
|
|
|
|
public static async System.Threading.Tasks.Task ShowLoadingScreen(IConfig config, GameObject rootCtxGo)
|
|
{
|
|
var fxClick = await Addressables.InstantiateAsync("TopUIFX").Task;
|
|
if (fxClick != null)
|
|
{
|
|
fxClick.name = "TopUIFX";
|
|
GameObject.DontDestroyOnLoad(fxClick);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("TopUIFX is null");
|
|
}
|
|
|
|
// TODO replace with new UI service
|
|
await GameCore.UIManager.Init(
|
|
UITypes.UIRoot, GameCore.ScreenType.PORTRAIT,
|
|
() => MessageDialog.ShowErrorDialog(-20, "Default Waiting Timeout")
|
|
);
|
|
|
|
var uiCam = rootCtxGo.FindChildGameObject("UICamera").GetComponent<Camera>();
|
|
var ui3DCam = rootCtxGo.FindChildGameObject("UI3DCamera").GetComponent<Camera>();
|
|
UIManager.SetUICamera(uiCam, ui3DCam);
|
|
|
|
//Camera.main.SetCamStack();
|
|
await LoadingScreen.Show(0.19f);
|
|
|
|
|
|
//LoadingScreen.SetVersionInfo($"Ver {Application.version}");
|
|
var reVer = VersionTool.FromString(config.Get(GConstant.K_Ver, string.Empty));
|
|
reVer.Save();
|
|
LoadingScreen.SetVersionInfo(reVer.ToVerString());
|
|
|
|
Debug.Log("[HotUpateBoostrap] ShowLoadingScreen Done");
|
|
}
|
|
|
|
private static async Task InitVibration()
|
|
{
|
|
var data = await Addressables.LoadAssetAsync<TextAsset>("vibrationdata").Task;
|
|
if (null != data)
|
|
{
|
|
var jsonData = JObject.Parse(data.text);
|
|
if (jsonData.ContainsKey("Soft"))
|
|
{
|
|
var soft = jsonData["Soft"];
|
|
MMVibrationManager.SoftDuration = soft["duration"].Value<long>();
|
|
MMVibrationManager.SoftAmplitude = soft["amplitude"].Value<int>();
|
|
}
|
|
if (jsonData.ContainsKey("Rigid"))
|
|
{
|
|
var rigid = jsonData["Rigid"];
|
|
MMVibrationManager.RigidDuration = rigid["duration"].Value<long>();
|
|
MMVibrationManager.RigidAmplitude = rigid["amplitude"].Value<int>();
|
|
}
|
|
if (jsonData.ContainsKey("Light"))
|
|
{
|
|
var light = jsonData["Light"];
|
|
MMVibrationManager.LightDuration = light["duration"].Value<long>();
|
|
MMVibrationManager.LightAmplitude = light["amplitude"].Value<int>();
|
|
}
|
|
if (jsonData.ContainsKey("Heavy"))
|
|
{
|
|
var heavy = jsonData["Heavy"];
|
|
MMVibrationManager.LightDuration = heavy["duration"].Value<long>();
|
|
MMVibrationManager.LightAmplitude = heavy["amplitude"].Value<int>();
|
|
}
|
|
if (jsonData.ContainsKey("Medium"))
|
|
{
|
|
var medium = jsonData["Medium"];
|
|
MMVibrationManager.LightDuration = medium["duration"].Value<long>();
|
|
MMVibrationManager.LightAmplitude = medium["amplitude"].Value<int>();
|
|
}
|
|
}
|
|
}
|
|
|
|
//#if UNITY_ANDROID
|
|
//private static void RequestAndriodPermission()
|
|
//{
|
|
//if(!UnityEngine.Android.Permission.HasUserAuthorizedPermission("android.permission.QUERY_ALL_PACKAGES"))
|
|
//{
|
|
//UnityEngine.Android.Permission.RequestUserPermission("android.permission.QUERY_ALL_PACKAGES");
|
|
//}
|
|
//}
|
|
//#endif
|
|
}
|
|
|
|
// public static class CameraExtension
|
|
// {
|
|
// public static void SetCamStack(this Camera cam)
|
|
// {
|
|
// if (cam != Camera.main) return;
|
|
// // For URP rendering, add UICamera into main scene camera's stack
|
|
// //
|
|
// Camera ui_cam = null;
|
|
//
|
|
// if (GameCore.UIManager.Instance != null)
|
|
// {
|
|
// ui_cam = GameCore.UIManager.Instance.UICamera;
|
|
// }
|
|
//
|
|
// if (ui_cam != null && cam != ui_cam)
|
|
// {
|
|
// var cam_stack = cam.GetUniversalAdditionalCameraData().cameraStack;
|
|
//
|
|
// if (!cam_stack.Contains(ui_cam))
|
|
// {
|
|
// cam_stack.Add(ui_cam);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
public class InternalEditorBoost
|
|
{
|
|
public static async Task Boost()
|
|
{
|
|
UnityEngine.Debug.Log("<color=orange>Editor Internal Boot</color>");
|
|
GContext.container.Register<IUIService, UIService>().AsSingleton();
|
|
|
|
await GameCore.UIManager.Init(
|
|
UITypes.UIRoot, GameCore.ScreenType.PORTRAIT,
|
|
() => MessageDialog.ShowErrorDialog(-20, "Default Waiting Timeout")
|
|
);
|
|
var ieb = new InternalEditorBoost();
|
|
await ieb.LoadConfig();
|
|
await ieb.Init();
|
|
}
|
|
|
|
private async Task LoadConfig()
|
|
{
|
|
var config = GContext.container.Resolve<IConfig>();
|
|
// Load Debug Config
|
|
var debugConfigPath = Path.Combine(Application.persistentDataPath, GConstant.V_Debug_Config_Path);
|
|
string remoteConfigUrl = null;
|
|
SimpleJSON.JSONNode debugConfig = null;
|
|
|
|
if (File.Exists(debugConfigPath))
|
|
{
|
|
#if UNITY_EDITOR
|
|
Debug.Log($"<color=yellow>Debug config [{debugConfigPath}] in use</color>");
|
|
#endif
|
|
debugConfig = SimpleJSON.JSON.Parse(File.ReadAllText(debugConfigPath));
|
|
if (debugConfig.HasKey(GConstant.K_Static_Res_URL))
|
|
{
|
|
remoteConfigUrl = debugConfig[GConstant.K_Static_Res_URL];
|
|
#if UNITY_EDITOR
|
|
Debug.Log($"<color=yellow>Debug Static Res URL => {remoteConfigUrl}</color>");
|
|
#endif
|
|
}
|
|
}
|
|
// load remote Config
|
|
remoteConfigUrl = remoteConfigUrl
|
|
?? string.Format(GConstant.V_Static_Res_URL, VersionTool.PackVer);
|
|
|
|
var request = UnityWebRequest.Get($"{remoteConfigUrl}/{GConstant.V_Remote_Config_Path}");
|
|
await request.SendWebRequest();
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
throw new Exception($"Load Config Error: {request.error}");
|
|
|
|
string remoteConfigStr = request.downloadHandler.text;
|
|
remoteConfigStr = Decrypt(remoteConfigStr);
|
|
var remoteConfig = SimpleJSON.JSON.Parse(remoteConfigStr);
|
|
// Merge Configs
|
|
foreach (var element in remoteConfig)
|
|
{
|
|
config.Set(element.Key, element.Value.Value);
|
|
}
|
|
|
|
if (null != debugConfig)
|
|
{
|
|
foreach (var element in debugConfig)
|
|
{
|
|
config.Set(element.Key, element.Value.Value);
|
|
}
|
|
}
|
|
|
|
// Change Addressable remote location, using custom assetbundle server
|
|
var customAddressableRemoteURL = config.Get(GConstant.K_Custom_Addressable, string.Empty);
|
|
var originAddressableRemoteURL = config.Get(GConstant.K_Origin_Addressable, string.Empty);
|
|
if (!string.IsNullOrEmpty(customAddressableRemoteURL)
|
|
&& !string.IsNullOrEmpty(originAddressableRemoteURL))
|
|
{
|
|
var ctx = (RootCtx)typeof(GContext).GetField("root", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null);
|
|
|
|
ctx.ChangeAddressableRemoteUrl(customAddressableRemoteURL, originAddressableRemoteURL);
|
|
}
|
|
|
|
}
|
|
string RTMKey = "tbambooz";
|
|
public string Decrypt(string text)
|
|
{
|
|
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
|
des.Key = Encoding.ASCII.GetBytes(RTMKey);
|
|
des.IV = Encoding.ASCII.GetBytes(RTMKey);
|
|
|
|
|
|
ICryptoTransform decryptor = des.CreateDecryptor(des.Key, des.IV);
|
|
byte[] inputBytes = Convert.FromBase64String(text);
|
|
byte[] outputBytes = decryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
|
|
|
|
return Encoding.UTF8.GetString(outputBytes);
|
|
}
|
|
private async Task Init()
|
|
{
|
|
var tables = await cfg.Tables.Init(x => { Debug.Log(x); });
|
|
GContext.container.RegisterInstance(tables);
|
|
GContext.container.Register<IFaceUIService, FaceUIService>().AsSingleton();
|
|
GContext.container.Register<IUIService, UIService>().AsSingleton();
|
|
GContext.container.Register<ICustomServerMgr, CustomServerMgr>().AsSingleton();
|
|
GContext.container.Register<IChatService, ChatService>().AsSingleton();
|
|
GContext.container.Register<ILocalNotificationService, LocalNotificationService>().AsSingleton();
|
|
GContext.container.Register<IReportService, ReportService>().AsSingleton();
|
|
GContext.container.Register<ModuleManager.ModuleManager>().AsSingleton();
|
|
GContext.container.Register<IInGameMailService, InGameMailService>().AsSingleton();
|
|
|
|
using (var scope = GContext.container.InjectionScope())
|
|
{
|
|
#if AGG
|
|
GContext.container.Register<IAdsService, AggAdsService>().AsSingleton();
|
|
#else
|
|
GContext.container.Register<IAdsService, DevAdsService>().AsSingleton();
|
|
#endif
|
|
GContext.container.Register<PlayerFishData>().AsSingleton();
|
|
GContext.container.Register<PlayerItemData>().AsSingleton();
|
|
GContext.container.Register<AlbumData>().AsSingleton();
|
|
GContext.container.Register<CampDataMM>().AsSingleton();
|
|
GContext.container.Register<FishingEventData>().AsSingleton();
|
|
GContext.container.Register<SigninData>().AsSingleton();
|
|
//GContext.container.Register<TaskData>().AsSingleton();
|
|
GContext.container.Register<ClubService>().AsSingleton();
|
|
GContext.container.Register<LeadboardData>().AsSingleton();
|
|
GContext.container.Register<PlayerShopData>().AsSingleton();
|
|
GContext.container.Register<TriggerPackData>().AsSingleton();
|
|
GContext.container.Register<GuideDataCenter>().AsSingleton();
|
|
GContext.container.Register<SmallGameData>().AsSingleton();
|
|
GContext.container.Register<PlayerData>().AsSingleton();
|
|
GContext.container.Register<SoundMgr>().AsSingleton();
|
|
GContext.container.Register<AvatarService>().AsSingleton();
|
|
GContext.container.Register<BuffDataCenter>().AsSingleton();
|
|
GContext.container.Register<FishingBoxData>().AsSingleton();
|
|
GContext.container.Register<FishingBoxDataProvier>().AsSingleton();
|
|
// GContext.container.Register<FishingChallengeCenter>().AsSingleton();
|
|
GContext.container.Register<FishingChallengeManager>().AsSingleton();
|
|
GContext.container.Register<OfferChainsChestManager>().AsSingleton();
|
|
GContext.container.Register<BattlePassDataProvider>().AsSingleton();
|
|
GContext.container.Register<MiniBattlePassDataProvider>().AsSingleton();
|
|
GContext.container.Register<BattlePassData>().AsSingleton();
|
|
GContext.container.Register<EventPackData>().AsSingleton();
|
|
GContext.container.Register<AchievementDataManager>().AsSingleton();
|
|
//GContext.container.Register<PokerScoreData>().AsSingleton();
|
|
//GContext.container.Register<RedeemCodeService>().AsSingleton();
|
|
GContext.container.Register<PiggyBankPackData>().AsSingleton();
|
|
GContext.container.Register<BargainPackData>().AsSingleton();
|
|
GContext.container.Register<RodSelectionPackData>().AsSingleton();
|
|
GContext.container.Register<SelectionPackData>().AsSingleton();
|
|
GContext.container.Register<DiggingGameManager>().AsSingleton();
|
|
GContext.container.Register<EventPartnerData>().AsSingleton();
|
|
}
|
|
var settings = new DefaultSettingService();
|
|
settings.Init(tables);
|
|
GContext.container.RegisterInstance<ISettingService>(settings);
|
|
GameCore.LocalizationMgr.Init();
|
|
await GContext.container.Resolve<ILocalNotificationService>().Init();
|
|
}
|
|
}
|
|
#endif
|