
1.新增单例模式单例类模板,可以广泛用在同时间只有一个存在在场景中的各种管理器
2.新增事件框架
3.新增状态模式的状态类和状态管理员类的类模板
4.新增进入式触发器
5.新增互动式触发器(涉及玩家类的更改,暂缓)
*.以上均为底层代码,目前无法测试,如果发现问题请联系开发者,如无必要,请勿修改
我是每天上班提醒小助手,今天你上班了吗?😺
41 lines
846 B
C#
41 lines
846 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 单例模式类模板
|
|
/// </summary>
|
|
public class UnitySingleton<T> : MonoBehaviour
|
|
where T : Component
|
|
{
|
|
private static T m_instance;
|
|
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
if (m_instance == null)
|
|
{
|
|
m_instance = FindObjectOfType<T>();
|
|
if (m_instance == null)
|
|
{
|
|
Debug.LogError("缺少 " + typeof(T) + " 这个单例,没法在场景中找到");
|
|
}
|
|
}
|
|
return m_instance;
|
|
}
|
|
}
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
if (m_instance == null)
|
|
{
|
|
m_instance = this as T;
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|