31 lines
959 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

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.

using EasyInject.Utils;
using UnityEngine;
namespace EasyInject.Controllers
{
/// <summary>
/// author: spyn
/// description: 全局初始化器
/// </summary>
/// <remarks>
/// 这里必须设置为最高优先级因为要在场景加载前初始化不然就会调用其他的Awake方法
/// </remarks>
[DefaultExecutionOrder(-1000000)]
public class GlobalInitializer : MonoBehaviour
{
// 实例化一个IoC容器存入静态变量中这样就可以导致整个游戏都只有一个IoC容器
public static readonly IIoC Instance = new MyIoC();
private void Awake()
{
// 每次进入场景都初始化IoC容器
Instance.Init();
}
private void OnDestroy()
{
// 清除该场景的所有Bean
Instance.ClearBeans(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
}
}
}