Files
Fishing2/Assets/Scripts/Startup/App.cs
2025-06-26 19:20:42 +08:00

193 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using FairyGUI;
using NBC;
using UnityEngine;
using UnityEngine.Audio;
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()
{
Log.Open = true;
Inst = this;
DontDestroyOnLoad(gameObject);
// new GameObject("GameManager").AddComponent<GameManager>();
}
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()
{
InitLanguage();
InitService();
InitUI();
}
#region
private void InitLanguage()
{
// var map = LanguageConst.languageMap;
Lan.Inst.AddLanguageModule((int)LanguageModuleType.Text, new LanguageText());
Lan.Inst.AddLanguageModule((int)LanguageModuleType.Image, new LanguageImage());
Lan.Inst.AddLanguageModule((int)LanguageModuleType.Font, new LanguageFont());
foreach (var key in LanguageConst.languageMap.Keys)
{
Lan.Inst.AddLanguage(key);
}
UI.Inst.SetUILanguage<UILangeageConfig>();
// Lan.Inst.AutoUseLanguage();
}
#endregion
#region UI
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-Medium";
UI.Inst.SetUILanguage<UILangeageConfig>();
UIConfig.modalLayerColor = new Color(0, 0, 0, 0.9f);
AddUIPackages();
}
private void AddUIPackages()
{
UI.Inst.AddPackage("Common/Common");
}
#endregion
#region Service
// private static readonly List<MonoService> Services = new List<MonoService>();
private static readonly Dictionary<Type, MonoService> Services = new Dictionary<Type, MonoService>();
private void AddService<T>() where T : MonoService, new()
{
var service = this.GetComponent<T>();
if (!service)
{
service = gameObject.AddComponent<T>();
}
Services[typeof(T)] = service;
}
private void InitService()
{
AddService<InputManager>();
AddService<Settings>();
}
#endregion
public void StartGame()
{
PermanentCommon.Init();
InputDef.LoadIcon();
// UI.Inst.OpenUI<FishingShopPanel>();
LoadData();
UI.Inst.OpenUI<CommonTopPanel>();
// UI.Inst.OpenUI<FishingPanel>();
UI.Inst.OpenUI<PreviewPanel>();
// Fishing.Inst.Go(1);
// UI.Inst.OpenUI<SettingPanel>();
// UI.Inst.OpenUI<HomePanel>();
}
private void LoadData()
{
ConfigAssets.Init();
GameModel.Inst.Init();
// var inventoryManager = GetComponent<InventoryManager>();
// if (inventoryManager == null)
// {
// inventoryManager = gameObject.AddComponent<InventoryManager>();
// }
//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
}
}