2021744738 2 years ago
parent 14d0ebdc17
commit 0676362cc1

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aae7c80ec51120d4ab7c750daa633c4e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class EventManager : MonoSingleton<EventManager>
{
protected override void Awake()
{
base.Awake();
}
public delegate void m_fun(params object[] args);
public static m_fun fun;
static Dictionary<string, m_fun> Events = new Dictionary<string, m_fun>();
//注意注册的事件参数应为params object[] args
public void register(string name, m_fun callback) {
if (!Events.ContainsKey(name))
{
Events.Add(name,callback);
Debug.Log("注册"+ name);
return;
}
Events[name] = callback;
}
public void emit(string name,params object[] args) {
if (Events.ContainsKey(name))
{
Events[name](args);
return;
}
Debug.Log("没有"+ name + "事件");
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94bf6090c22a88446b83d2d203e6b57c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc62637c6246ccc428064df41cb5be1d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadManager : MonoSingleton<LoadManager>
{
public T Load<T>(string path) where T:class
{
return Resources.Load(path) as T;
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c94f25fee4a4da34bbe263f631e5cd65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
private static T _instance;
public static T Instance
{
get {
return _instance;
}
}
protected virtual void Awake()
{
if (_instance!=null)
{
Destroy(_instance.gameObject);
}
_instance = this as T;
}
protected virtual void OnDestroy()
{
if (_instance == this)
{
_instance = null;
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4bc1a71e2c5baa4aabc37ace6ebe20f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0f0567f363b89b847b07c63968cf7b33
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,3 @@
public interface IObserver {
void Notify();
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46ec0ffc8508fa24aa92cddc19d59dcc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class MessageCenter : MonoSingleton<MessageCenter>
{
public delegate void Message();
Dictionary<string, Message> Events=new Dictionary<string, Message>();
protected override void Awake()
{
base.Awake();
DontDestroyOnLoad(gameObject);
Events = new Dictionary<string, Message>();
}
public void AddListen(string eventName, IObserver observer) {
if (!Events.ContainsKey(eventName))
{
Message message = new Message(observer.Notify);
Events.Add(eventName, message);
return;
}
Events[eventName]+=observer.Notify;
}
public void RemoveListen(string eventName, IObserver observer)
{
if (Events.ContainsKey(eventName))
{
Events[eventName] -= observer.Notify;
}
}
public void SendEvent(string eventName) {
if (!Events.ContainsKey(eventName)) return;
Events[eventName]();
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e86b7a137f0e0fe4baf15cad99c6bcff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save