83 lines
2.4 KiB
C#
83 lines
2.4 KiB
C#
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|