192 lines
4.9 KiB
C#
192 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Assets.Scripts.Entity;
|
|
using Assets.Scripts.Hotfix;
|
|
using FairyGUI;
|
|
using NBC;
|
|
using NBC.Network;
|
|
using UnityEngine;
|
|
using UnityEngine.Video;
|
|
|
|
namespace NBF
|
|
{
|
|
public class Init : MonoBehaviour
|
|
{
|
|
[SerializeField] private VideoPlayer videoPlayer;
|
|
[SerializeField] private GameObject startCanvas;
|
|
[SerializeField] private bool playVideo;
|
|
|
|
private void CheckOver(VideoPlayer vp)
|
|
{
|
|
Destroy(startCanvas);
|
|
StartGame();
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
DontDestroyOnLoad(gameObject);
|
|
App.Init(InitCallback);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
PermanentCommon.Dispose();
|
|
}
|
|
|
|
void InitCallback()
|
|
{
|
|
ES3.Init();
|
|
ES3.Save("NBF", 1);
|
|
if (!playVideo)
|
|
{
|
|
videoPlayer.Stop();
|
|
}
|
|
else
|
|
{
|
|
videoPlayer.loopPointReached += CheckOver;
|
|
}
|
|
|
|
QualitySettings.vSyncCount = 0;
|
|
InitLanguage();
|
|
InitService();
|
|
InitUI();
|
|
if (!playVideo)
|
|
{
|
|
CheckOver(videoPlayer);
|
|
}
|
|
}
|
|
|
|
|
|
#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";
|
|
App.UI.SetUILanguage<UILangeageConfig>();
|
|
UIConfig.modalLayerColor = new Color(0, 0, 0, 0.9f);
|
|
AddUIPackages();
|
|
}
|
|
|
|
private void AddUIPackages()
|
|
{
|
|
App.UI.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();
|
|
CommonTopPanel.Show();
|
|
// FishingPanel.Show();
|
|
PreviewPanel.Show();
|
|
Fishing.Inst.Go(1);
|
|
|
|
// HomePanel.Show();
|
|
// ChatTestPanel.Show();
|
|
// SettingPanel.Show();
|
|
// //测试登录
|
|
// OnLoginButtonClick().Coroutine();
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
}
|
|
} |