Files
Fishing2/Assets/Scripts/Startup/App.cs
BobSong fcf41c3248 Merge branch 'master' of https://git.bobsong.cn/Game/Fishing2
# Conflicts:
#	Fishing2.sln.DotSettings.user
#	UserSettings/EditorUserSettings.asset
2025-05-30 20:39:20 +08:00

167 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using FairyGUI;
using NBC;
using UnityEngine;
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<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()
{
InitService();
InitUI();
}
#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-55-Regular";
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>();
// UI.Inst.OpenUI<SettingPanel>();
LoadData();
Fishing.Inst.Go(1);
}
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
}
}