mycj_demo/mycj/Assets/Game/Scripts/Application/FBGame.cs
2024-12-02 09:37:47 +08:00

110 lines
2.9 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Felix-BangFBGame
//   へ     /|
//  /7    ∠_/
//  / │    
//  Z _,    /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │
//  / へ   / ノ<|
//  ヽ_ノ  (_  │//
//  7       |
//  ―r ̄ ̄`ー―_
// Describe启动游戏 初始化全局数据
// Createtime2018/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;
}
}
}