DCS/ruiyiweiUX/Assets/GeneralTools/Scripts/Always/ScriptManager.cs

83 lines
2.4 KiB
C#
Raw Normal View History

2026-06-09 13:59:11 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
namespace GeneralTools
{
public class ScriptManager : MonoBehaviour
{
/// <summary>
/// 自动获取子物体上的脚本
/// </summary>
protected List<BaseAttribute> scriptList = new List<BaseAttribute>();
protected BaseAttribute gameManager;
protected LoadingManager loadManager;
private void Awake()
{
ConfigHelper.Init(DevicePath.StreamingAssetsPath + "/config.ini");
DontDestroyOnLoad(gameObject);
CollectScript();
ScriptAwake();
}
private void Start()
{
ScriptStart();
}
private void OnApplicationQuit()
{
ScriptApplicationQuit();
}
void ScriptAwake()
{
for (int i = 0; i < scriptList.Count; i++)
{
if (scriptList[i] != null)
{
scriptList[i].IAwake();
}
}
}
void ScriptStart()
{
for (int i = 0; i < scriptList.Count; i++)
{
if (scriptList[i] != null)
{
scriptList[i].IStart();
}
}
if (loadManager == null && gameManager!=null)
{
//有加载事件时不运行GameStart
gameManager.GameStart();
}
}
void ScriptApplicationQuit()
{
for (int i = 0; i < scriptList.Count; i++)
{
if (scriptList[i] != null)
{
scriptList[i].IOnApplicationQuit();
}
}
}
void CollectScript()
{
scriptList.Clear();
scriptList = UtilityTool.CollectComponent<BaseAttribute>(transform);
loadManager = UtilityTool.FindChild<LoadingManager>(transform, "LoadingManager");
gameManager = UtilityTool.FindChild<BaseAttribute>(transform, "GameManager");
if (gameManager == null)
{
//Debug.LogError("缺少GameManager");
}
if (loadManager != null)
{
loadManager.LoadingFinshedListeners += gameManager.GameStart;
}
}
}
}