add kcp
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
/// <summary>泛型事件,简单的事件接口</summary>
|
||||
@@ -39,6 +40,12 @@ namespace BITKit
|
||||
var list = events.Get(key);
|
||||
list.Add(action);
|
||||
}
|
||||
|
||||
public void AddListenerDirect(string key, Action<object> action)
|
||||
{
|
||||
events.Get(key).Add(action);
|
||||
}
|
||||
|
||||
public void Invoke<T>(string key, T value)
|
||||
{
|
||||
key = key.GetType<T>();
|
||||
@@ -52,6 +59,17 @@ namespace BITKit
|
||||
}
|
||||
});
|
||||
}
|
||||
public void InvokeDirect(string key,object value)
|
||||
{
|
||||
var list = events.Get(key);
|
||||
list.ToArray().ForEach(x =>
|
||||
{
|
||||
if (x is Action<object> action)
|
||||
{
|
||||
action.Invoke(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
public void Invoke(string typeName, object value)
|
||||
{
|
||||
var key = $"{typeName}.{defaultEventName}";
|
||||
@@ -80,6 +98,7 @@ namespace BITKit
|
||||
public void Set<T>(T value) => dictionary.Set(Constant.System.Internal.GetType<T>(), value);
|
||||
public void Set<T>(string key, T value) => dictionary.Set(key.GetType<T>(), value);
|
||||
public void Set(Type type, object value) => dictionary.Set($"{type.FullName}.{Constant.System.Internal}", value);
|
||||
public void SetDirect(string key, object value) => dictionary.Set(key, value);
|
||||
public void RemoveListener<T>(string key, Action<T> action)
|
||||
{
|
||||
key = key.GetType<T>();
|
||||
@@ -115,5 +134,10 @@ namespace BITKit
|
||||
}
|
||||
|
||||
public void Invoke<T>() where T : new() => Invoke(new T());
|
||||
|
||||
public bool TryGetObjectDirect(string key, out object value)
|
||||
{
|
||||
return dictionary.TryGetValue(key, out value);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user