// // /*=============================================================================== // // Copyright (C) 2024 PhantomsXR Ltd. All Rights Reserved. // // // // This file is part of the Phantom.XRMOD.PackageTools.Editor. // // // // The SharedData cannot be copied, distributed, or made available to // // third-parties for commercial purposes without written permission of PhantomsXR Ltd. // // // // Contact info@phantomsxr.com for licensing requests. // // ===============================================================================*/ using System; using UnityEngine; using UnityEngine.Assertions; using Object = UnityEngine.Object; using Phantom.XRMOD.XRMODAPI.Runtime; using Phantom.XRMOD.Localization.Runtime; using Phantom.XRMOD.XRMODUtilites.Runtime; namespace #NAMESPACE#.Runtime { public class SharedData : IDisposable { private static SharedData _SHARED_DATA; public static SharedData GetInstance => _SHARED_DATA ??= new SharedData(); // Add your fields below. // e.g. public string HelloText = "Hello Text"; // e.g. public BindableProperty HelloTextBindable = new BindableProperty(); /// /// XRMOD Engine API. /// internal API XRMODAPI; /// /// Localization system /// internal LocalizationManagerV2 localizationManager = LocalizationManagerV2.Instance; private SharedData() { XRMODAPI = new API(nameof(#NAMESPACE#)); PrepareAssets(); } private async void PrepareAssets() { try { var tmp_LocalizationDatabase = await XRMODAPI.LoadAssetAsync(nameof(LocalizationDatabase)) as LocalizationDatabase; Assert.IsNotNull(tmp_LocalizationDatabase, "Localization table asset can not empty."); localizationManager.Initialize(_project: nameof(#NAMESPACE#), _database: tmp_LocalizationDatabase,_scope: LocalizationScope.InExperiences); LoadAssets(); } catch (Exception tmp_Exception) { Debug.LogError($"Load assets failed.\n{tmp_Exception}"); } } internal async void LoadAssets() { // Load your assets in here } /// /// Exit current experience(or quit app) /// /// True to quit app internal void Exit(bool _quitApplication = false) { if (!_quitApplication) XRMODAPI.ReleaseProject(nameof(#NAMESPACE#)); else Application.Quit(); } public void Dispose() { localizationManager.Release(nameof(#NAMESPACE#),LocalizationScope.InExperiences); localizationManager = null; } } }