using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
namespace GeneralTools
{
public class ScriptManager : MonoBehaviour
{
///
/// 自动获取子物体上的脚本
///
protected List scriptList = new List();
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(transform);
loadManager = UtilityTool.FindChild(transform, "LoadingManager");
gameManager = UtilityTool.FindChild(transform, "GameManager");
if (gameManager == null)
{
//Debug.LogError("缺少GameManager");
}
if (loadManager != null)
{
loadManager.LoadingFinshedListeners += gameManager.GameStart;
}
}
}
}