增加A2WToolBox工具集,增加Launch场景核LaunchPanel
This commit is contained in:
25
Assets/A2WToolBox/Runtime/Singleton/SceneSingleton.cs
Normal file
25
Assets/A2WToolBox/Runtime/Singleton/SceneSingleton.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace A2W
|
||||
{
|
||||
public class SceneSingleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
public static T instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = FindObjectOfType<T>();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
private static T _instance;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
Assets/A2WToolBox/Runtime/Singleton/SceneSingleton.cs.meta
Normal file
11
Assets/A2WToolBox/Runtime/Singleton/SceneSingleton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1917613a5d6fa964b80e64f209ba5b63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/A2WToolBox/Runtime/Singleton/Singleton.cs
Normal file
51
Assets/A2WToolBox/Runtime/Singleton/Singleton.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace A2W
|
||||
{
|
||||
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
private static T _instance;
|
||||
private static object _lock = new object();
|
||||
public static T instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (applicationIsQuitting)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
lock (_lock)
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = (T)FindObjectOfType(typeof(T));
|
||||
|
||||
if (FindObjectsOfType(typeof(T)).Length > 1)
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject singleton = new GameObject();
|
||||
_instance = singleton.AddComponent<T>();
|
||||
singleton.name = "(singleton)" + typeof(T).ToString();
|
||||
|
||||
DontDestroyOnLoad(singleton);
|
||||
}
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool applicationIsQuitting = false;
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
applicationIsQuitting = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/A2WToolBox/Runtime/Singleton/Singleton.cs.meta
Normal file
11
Assets/A2WToolBox/Runtime/Singleton/Singleton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8771fe51820c7994b96bae594e030d62
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user