80 lines
1.8 KiB
C#
80 lines
1.8 KiB
C#
|
|
using EasyInject.Attributes;
|
|
using EasyInject.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
[DefaultExecutionOrder(-1000000000)]
|
|
[GameObjectBean]
|
|
[AddComponentMenu("WXDC/Application/ApplicationBoot")]
|
|
public sealed class ApplicationBoot : MonoBehaviour
|
|
{
|
|
public static readonly IIoC Instance = new MyIoC();
|
|
|
|
|
|
[Autowired]
|
|
private ApplicationStateMachine applicationState;
|
|
|
|
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
|
static void OnBeforeSceneLoad()
|
|
{
|
|
Debug.Log("First scene loading: Before Awake is called.");
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
Debug.Log("IOC容器初始化");
|
|
Instance.Init();
|
|
}
|
|
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
|
|
private static void Run()
|
|
{
|
|
//Debug.Log("IOC容器初始化");
|
|
//Instance.Init();
|
|
}
|
|
private void Start()
|
|
{
|
|
applicationState.OnInit();
|
|
}
|
|
private void Update()
|
|
{
|
|
applicationState.OnUpdate();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
// Clear the Beans in the corresponding scene
|
|
Shutdown();
|
|
Instance.ClearBeans(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 应用关闭执行
|
|
/// </summary>
|
|
private void Shutdown()
|
|
{
|
|
List<IApplcationShutdown> shutdowns = Instance.GetBeans<IApplcationShutdown>();
|
|
shutdowns = shutdowns.Distinct().ToList();
|
|
foreach(var down in shutdowns)
|
|
{
|
|
if (down == null)
|
|
{
|
|
continue;
|
|
}
|
|
try
|
|
{
|
|
down?.Shutdown();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogError(ex);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|