UNPKG

com.phantomsxr.xrmodpackagetools

Version:

XR-MOD is a derivative based on Unity ARFoundation. Using the technical concept of MOD in the game allows XR creators to develop their own AR creative interactive experience. This tool is an extension of XR-MOD, used to generate XR-MOD identifiable resour

91 lines (77 loc) 3.08 kB
// // /*=============================================================================== // // 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<string> HelloTextBindable = new BindableProperty<string>(); /// <summary> /// XRMOD Engine API. /// </summary> internal API XRMODAPI; /// <summary> /// Localization system /// </summary> internal LocalizationManagerV2 localizationManager = LocalizationManagerV2.Instance; private SharedData() { XRMODAPI = new API(nameof(#NAMESPACE#)); PrepareAssets(); } private async void PrepareAssets() { try { var tmp_LocalizationDatabase = await XRMODAPI.LoadAssetAsync<ScriptableObject>(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 } /// <summary> /// Exit current experience(or quit app) /// </summary> /// <param name="_quitApplication">True to quit app</param> 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; } } }