using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using FairyGUI; using NBC; using NBF; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.Video; namespace NBF { public class App : MonoBehaviour { public static App Inst { get; private set; } [SerializeField] private VideoPlayer videoPlayer; [SerializeField] private GameObject startCanvas; [SerializeField] private bool playVideo; private void CheckOver(VideoPlayer vp) { Destroy(startCanvas); StartGame(); } private void Awake() { Inst = this; DontDestroyOnLoad(gameObject); // new GameObject("GameManager").AddComponent(); } private void OnDestroy() { PermanentCommon.Dispose(); } void Start() { ES3.Init(); ES3.Save("NBF", 1); if (!playVideo) { videoPlayer.Stop(); } else { videoPlayer.loopPointReached += CheckOver; } QualitySettings.vSyncCount = 0; // Application.targetFrameRate = 120; // NBC.Asset.Const.Offline = true; // yield return NBC.Asset.Assets.Initialize(); Init(); if (!playVideo) { CheckOver(videoPlayer); } } private void Init() { InitUI(); } private void InitUI() { GRoot.inst.SetContentScaleFactor(UIDef.DefaultScreen.Width, UIDef.DefaultScreen.Height, UIContentScaler.ScreenMatchMode.MatchWidthOrHeight); Binder.BindAll(); UIObjectFactory.SetLoaderExtension(typeof(XGLoader)); UIConst.UIPackRootUrl = UIDef.UIRoot; UIConfig.defaultFont = "AlibabaPuHuiTi-3-55-Regular"; UI.Inst.SetUILanguage(); UIConfig.modalLayerColor = new Color(0, 0, 0, 0.9f); AddUIPackages(); } private void AddUIPackages() { UI.Inst.AddPackage("Common/Common"); } public void StartGame() { PermanentCommon.Init(); InputDef.LoadIcon(); UI.Inst.OpenUI(); LoadData(); // Fishing.Inst.Go(1); } private void LoadData() { ConfigAssets.Init(); // var cfgAssets = Resources.Load("config/CfgAssets"); // var playerCache = Resources.Load("config/PlayerCache"); // GameManager.Instance._playerData = playerCache.PlayerData; var inputManager = this.GetComponent(); if (inputManager == null) { inputManager = gameObject.AddComponent(); } GameModel.Inst.Init(); // var inventoryManager = GetComponent(); // if (inventoryManager == null) // { // inventoryManager = gameObject.AddComponent(); // } //InventoryManager } #region New public ControllerType controllerType = ControllerType.GamePad; public void SetMouseCursor(bool val) { if (val) { if (controllerType == ControllerType.KeyboardMouse) { Cursor.visible = true; } Cursor.lockState = CursorLockMode.None; } else if (controllerType == ControllerType.KeyboardMouse) { Cursor.visible = false; } Cursor.visible = val; if (!val) { Cursor.lockState = CursorLockMode.Confined; } } #endregion } }