110 lines
2.9 KiB
C#
110 lines
2.9 KiB
C#
|
// Felix-Bang:FBGame
|
|||
|
// へ /|
|
|||
|
// /\7 ∠_/
|
|||
|
// / │ / /
|
|||
|
// │ Z _,< / /`ヽ
|
|||
|
// │ ヽ / 〉
|
|||
|
// Y ` / /
|
|||
|
// イ● 、 ● ⊂⊃〈 /
|
|||
|
// () へ | \〈
|
|||
|
// >ー 、_ ィ │ //
|
|||
|
// / へ / ノ<| \\
|
|||
|
// ヽ_ノ (_/ │//
|
|||
|
// 7 |/
|
|||
|
// >―r ̄ ̄`ー―_
|
|||
|
// Describe:启动游戏 初始化全局数据
|
|||
|
// Createtime:2018/9/25
|
|||
|
|
|||
|
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.SceneManagement;
|
|||
|
using FBFramework;
|
|||
|
using System;
|
|||
|
|
|||
|
namespace FBApplication
|
|||
|
{
|
|||
|
[RequireComponent(typeof(FBObjectPool))]
|
|||
|
[RequireComponent(typeof(FBSound))]
|
|||
|
[RequireComponent(typeof(FBStaticData))]
|
|||
|
public class FBGame : FBApplicationBase<FBGame>
|
|||
|
{
|
|||
|
// 全局访问功能
|
|||
|
[HideInInspector]
|
|||
|
public FBObjectPool ObjectPool=null;
|
|||
|
[HideInInspector]
|
|||
|
public FBSound Sound = null;
|
|||
|
[HideInInspector]
|
|||
|
public FBStaticData StaticData = null;
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
SceneManager.sceneLoaded += OnSceneWasLoaded;
|
|||
|
}
|
|||
|
|
|||
|
// 游戏入口
|
|||
|
void Start ()
|
|||
|
{
|
|||
|
DontDestroyOnLoad(gameObject);
|
|||
|
|
|||
|
//赋值
|
|||
|
ObjectPool = FBObjectPool.Instance;
|
|||
|
Sound = FBSound.Instance;
|
|||
|
StaticData = FBStaticData.Instance;
|
|||
|
|
|||
|
//注册命令(Command)
|
|||
|
RegisterController(FBConsts.E_StartUp, typeof(FBStartUpController));
|
|||
|
|
|||
|
//启动游戏
|
|||
|
SendEvent(FBConsts.E_StartUp);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 加载场景
|
|||
|
/// </summary>
|
|||
|
/// <param name="index">场景索引</param>
|
|||
|
public void LoadScene(int index)
|
|||
|
{
|
|||
|
//退出旧场景
|
|||
|
//事件参数
|
|||
|
FBSceneArgs e = new FBSceneArgs
|
|||
|
{
|
|||
|
Index = SceneManager.GetActiveScene().buildIndex
|
|||
|
};
|
|||
|
//发布事件
|
|||
|
SendEvent(FBConsts.E_SceneExit,e);
|
|||
|
|
|||
|
//加载新场景
|
|||
|
SceneManager.LoadScene(index, LoadSceneMode.Single);
|
|||
|
}
|
|||
|
|
|||
|
// 当前场景加载后触发
|
|||
|
private void OnSceneWasLoaded(Scene arg0, LoadSceneMode arg1)
|
|||
|
{
|
|||
|
FBSceneArgs e = new FBSceneArgs
|
|||
|
{
|
|||
|
Index = arg0.buildIndex
|
|||
|
};
|
|||
|
|
|||
|
SendEvent(FBConsts.E_SceneEnter, e);
|
|||
|
}
|
|||
|
|
|||
|
// 当前场景加载后触发
|
|||
|
// OnLevelWasLoaded新版本的Unity即将放弃
|
|||
|
//private void OnLevelWasLoaded(int index)
|
|||
|
//{
|
|||
|
// FBSceneArgs e = new FBSceneArgs
|
|||
|
// {
|
|||
|
// Index = index
|
|||
|
// };
|
|||
|
|
|||
|
// SendEvent(FBConsts.E_EnterScene,e);
|
|||
|
//}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
SceneManager.sceneLoaded -= OnSceneWasLoaded;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|