1
This commit is contained in:
38
unity/Assets/Script/Tools/Utils/MonoSingleton.cs
Normal file
38
unity/Assets/Script/Tools/Utils/MonoSingleton.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
public bool global=true;
|
||||
private static T instance;
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
instance = FindObjectOfType<T>();
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
void Awake()
|
||||
{
|
||||
if (global)
|
||||
{
|
||||
if (instance != null && instance != this.gameObject.GetComponent<T>())
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(this.gameObject);
|
||||
instance = this.gameObject.GetComponent<T>();
|
||||
|
||||
}
|
||||
this.OnStart();
|
||||
}
|
||||
|
||||
protected virtual void OnStart()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
unity/Assets/Script/Tools/Utils/MonoSingleton.cs.meta
Normal file
11
unity/Assets/Script/Tools/Utils/MonoSingleton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29d9d55349331304fb3da0aa1c10e559
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
unity/Assets/Script/Tools/Utils/Resloader.cs
Normal file
15
unity/Assets/Script/Tools/Utils/Resloader.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
class Resloader
|
||||
{
|
||||
public static T Load<T>(string path) where T : UnityEngine.Object
|
||||
{
|
||||
return Resources.Load<T>(path);
|
||||
}
|
||||
}
|
||||
|
||||
11
unity/Assets/Script/Tools/Utils/Resloader.cs.meta
Normal file
11
unity/Assets/Script/Tools/Utils/Resloader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e7452ecf3eb2b94c8af2b8b2f16c9ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
unity/Assets/Script/Tools/Utils/Singleton.cs
Normal file
17
unity/Assets/Script/Tools/Utils/Singleton.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Singleton<T> where T : new()
|
||||
{
|
||||
static T instance;
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
return instance = new T();
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
unity/Assets/Script/Tools/Utils/Singleton.cs.meta
Normal file
11
unity/Assets/Script/Tools/Utils/Singleton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07784bad47cfbe64faab332768e5f00a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user