35 lines
896 B
C#
35 lines
896 B
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Threading;
|
|||
|
|
using System.Timers;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace GeneralTools
|
|||
|
|
{
|
|||
|
|
public class SingletonBaseAttribute<T> : BaseAttribute where T : BaseAttribute
|
|||
|
|
{
|
|||
|
|
private static T instance;
|
|||
|
|
public static T Instance
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (instance == null)
|
|||
|
|
{
|
|||
|
|
instance = FindObjectOfType<T>();
|
|||
|
|
if (instance == null)
|
|||
|
|
{
|
|||
|
|
instance = new GameObject().AddComponent<T>();
|
|||
|
|
}
|
|||
|
|
instance.IAwake();
|
|||
|
|
instance.IStart();
|
|||
|
|
}
|
|||
|
|
return instance;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public override void IAwake()
|
|||
|
|
{
|
|||
|
|
base.IAwake();
|
|||
|
|
instance = this as T;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|