Compare commits
No commits in common. "26b316d4315f94de4d976937343da04d30bb773f" and "a07dbf23a59df5adfacd05a15f4b77806ddfff9f" have entirely different histories.
26b316d431
...
a07dbf23a5
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 369587a5e18126349b07b3a1e7c9abe5
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: a8734ea3ee422854a8491e4ea1703e8f
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,14 +0,0 @@
|
||||||
public class CommonEventBase
|
|
||||||
{
|
|
||||||
private int _errorCode;
|
|
||||||
public int ErrorCode
|
|
||||||
{
|
|
||||||
get { return _errorCode; }
|
|
||||||
set { _errorCode = value; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CustomEvent : CommonEventBase
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 20c6a74d993d2514185dafb53f2b6ee9
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,65 +0,0 @@
|
||||||
using FirstVillain.Singleton;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace FirstVillain.Event
|
|
||||||
{
|
|
||||||
public class EventManager : UnitySingleton<EventManager>
|
|
||||||
{
|
|
||||||
public delegate void EventDelegate<T>(T cEvent) where T : CommonEventBase;
|
|
||||||
private delegate void EventDelegate(CommonEventBase cEvent);
|
|
||||||
|
|
||||||
private Dictionary<Type, EventDelegate> _delegateDict = new();
|
|
||||||
private Dictionary<Delegate, EventDelegate> _delegateLookupDict = new();
|
|
||||||
|
|
||||||
private void AddListener<T>(EventDelegate<T> callback) where T : CommonEventBase
|
|
||||||
{
|
|
||||||
EventDelegate newDelegate = e => callback(e as T);
|
|
||||||
_delegateLookupDict[callback] = newDelegate;
|
|
||||||
|
|
||||||
var type = typeof(T);
|
|
||||||
if (!_delegateDict.TryGetValue(type, out EventDelegate tempDeletage))
|
|
||||||
{
|
|
||||||
_delegateDict[type] = tempDeletage;
|
|
||||||
}
|
|
||||||
|
|
||||||
_delegateDict[type] += newDelegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DelListener<T>(EventDelegate<T> callback) where T : CommonEventBase
|
|
||||||
{
|
|
||||||
if (_delegateLookupDict.TryGetValue(callback, out EventDelegate targetDelegate))
|
|
||||||
{
|
|
||||||
var type = typeof(T);
|
|
||||||
if (_delegateDict.TryGetValue(type, out EventDelegate tempDelegate))
|
|
||||||
{
|
|
||||||
tempDelegate -= targetDelegate;
|
|
||||||
if (tempDelegate == null)
|
|
||||||
{
|
|
||||||
_delegateDict.Remove(type);
|
|
||||||
_delegateLookupDict.Remove(callback);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_delegateDict[type] = tempDelegate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ExecuteEvent(CommonEventBase cEvent)
|
|
||||||
{
|
|
||||||
if (Instance._delegateDict.TryGetValue(cEvent.GetType(), out EventDelegate callback))
|
|
||||||
{
|
|
||||||
callback.Invoke(cEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
_delegateDict.Clear();
|
|
||||||
_delegateLookupDict.Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 4e9bec8da5b8dd848a2fe26b3a997ba1
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 46c57a5edc113954c92ea81e20be4682
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 79590437eab636d45b613b2bcda6a904
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,93 +0,0 @@
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace FirstVillain.Singleton
|
|
||||||
{
|
|
||||||
public class UnitySingleton<T> : MonoBehaviour where T : UnityEngine.Component
|
|
||||||
{
|
|
||||||
private static T _instance = null;
|
|
||||||
|
|
||||||
public static T Instance
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_instance == null)
|
|
||||||
{
|
|
||||||
string name = (typeof(T)).ToString();
|
|
||||||
_instance = new GameObject(name).AddComponent<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
if (_instance != null && _instance != this)
|
|
||||||
{
|
|
||||||
Destroy(gameObject);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_instance = this as T;
|
|
||||||
}
|
|
||||||
|
|
||||||
DontDestroyOnLoad(gameObject);
|
|
||||||
|
|
||||||
AwakeSingleton();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
if (_instance == this)
|
|
||||||
{
|
|
||||||
_instance = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void AwakeSingleton()
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
public class UnitySingletonOnce<T> : MonoBehaviour where T : UnityEngine.Component
|
|
||||||
{
|
|
||||||
private static T _instance = null;
|
|
||||||
|
|
||||||
public static T Instance
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_instance == null)
|
|
||||||
{
|
|
||||||
string name = (typeof(T)).ToString();
|
|
||||||
_instance = new GameObject(name).AddComponent<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
if (_instance != null && _instance != this)
|
|
||||||
{
|
|
||||||
Destroy(gameObject);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_instance = this as T;
|
|
||||||
}
|
|
||||||
|
|
||||||
AwakeSingleton();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
if (_instance == this)
|
|
||||||
{
|
|
||||||
_instance = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void AwakeSingleton()
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 777a878dd9f43e349ac20fcd7e63dc31
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Reference in New Issue
Block a user