add kcp
This commit is contained in:
@@ -11,6 +11,7 @@ namespace BITKit
|
||||
public const string Status = "Status";
|
||||
public const string State = "State";
|
||||
public const string Settings = "Settings";
|
||||
public const string Services = "Services";
|
||||
public const string AudioClip = "AudioClip";
|
||||
public const string AudioSource = "AudioSource";
|
||||
public const string Paths = "Paths";
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@
|
||||
{
|
||||
string Get();
|
||||
string Value => Get();
|
||||
string Replace(string value) => Get().Replace("{x}",value);
|
||||
}
|
||||
|
||||
public interface IReference<T>
|
||||
@@ -37,9 +38,12 @@
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.TextArea]
|
||||
#endif
|
||||
public string value;
|
||||
public override string Get() => value;
|
||||
public override string ToString() => value;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
@@ -5,17 +5,12 @@ namespace BITKit
|
||||
{
|
||||
public class ValidHandle
|
||||
{
|
||||
public ValidHandle() { Init(); }
|
||||
public ValidHandle() {}
|
||||
public ValidHandle(Action<bool> boolDelegate)
|
||||
{
|
||||
AddListener(boolDelegate);
|
||||
Init();
|
||||
EventOnEnableChanged?.Invoke(enableHandle);
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
AddListener(OnInoke);
|
||||
}
|
||||
public static implicit operator bool(ValidHandle validHandle)
|
||||
{
|
||||
return validHandle.enableHandle;
|
||||
@@ -24,8 +19,6 @@ namespace BITKit
|
||||
public bool Allow => this;
|
||||
|
||||
private bool enableHandle;
|
||||
private int enableElementCount;
|
||||
private int disableElementCount;
|
||||
private readonly List<object> objs = new List<object>();
|
||||
private readonly List<object> disableObjs = new List<object>();
|
||||
private bool tempEnable;
|
||||
@@ -43,7 +36,7 @@ namespace BITKit
|
||||
}
|
||||
CheckEnable();
|
||||
}
|
||||
protected virtual void CheckEnable()
|
||||
protected void CheckEnable()
|
||||
{
|
||||
tempEnable = objs.Count > 0 && disableObjs.Count == 0;
|
||||
if (tempEnable != enableHandle)
|
||||
@@ -51,13 +44,8 @@ namespace BITKit
|
||||
enableHandle = tempEnable;
|
||||
if (EventOnEnableChanged is not null)
|
||||
EventOnEnableChanged.Invoke(enableHandle);
|
||||
OnEnable(enableHandle);
|
||||
|
||||
}
|
||||
enableElementCount = objs.Count;
|
||||
disableElementCount = disableObjs.Count;
|
||||
}
|
||||
protected virtual void OnEnable(bool enable) { }
|
||||
public virtual void RemoveElement(object obj)
|
||||
{
|
||||
if (objs.Contains(obj))
|
||||
@@ -93,7 +81,7 @@ namespace BITKit
|
||||
}
|
||||
CheckEnable();
|
||||
}
|
||||
public virtual void RemoveDisableElements(object obj)
|
||||
public void RemoveDisableElements(object obj)
|
||||
{
|
||||
if (disableObjs.Contains(obj))
|
||||
{
|
||||
@@ -104,7 +92,7 @@ namespace BITKit
|
||||
}
|
||||
CheckEnable();
|
||||
}
|
||||
public virtual void SetElements(object obj, bool add = true)
|
||||
public void SetElements(object obj, bool add = true)
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
@@ -126,29 +114,33 @@ namespace BITKit
|
||||
RemoveDisableElements(obj);
|
||||
}
|
||||
}
|
||||
public virtual void Invoke()
|
||||
public void Invoke()
|
||||
{
|
||||
bool enable = disableObjs.Count == 0 && objs.Count > 0;
|
||||
EventOnEnableChanged.Invoke(enable);
|
||||
var enable = disableObjs.Count == 0 && objs.Count > 0;
|
||||
EventOnEnableChanged?.Invoke(enable);
|
||||
}
|
||||
public virtual void Invoke(bool value)
|
||||
public void Invoke(bool value)
|
||||
{
|
||||
EventOnEnableChanged.Invoke(value);
|
||||
EventOnEnableChanged?.Invoke(value);
|
||||
}
|
||||
public virtual void OnInoke(bool value)
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void AddListener(Action<bool> action)
|
||||
public void AddListener(Action<bool> action)
|
||||
{
|
||||
EventOnEnableChanged+= action;
|
||||
}
|
||||
public virtual void RemoveListener(Action<bool> action)
|
||||
public void RemoveListener(Action<bool> action)
|
||||
{
|
||||
if(EventOnEnableChanged is not null && action is not null)
|
||||
{
|
||||
EventOnEnableChanged -= action;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
objs.Clear();
|
||||
disableObjs.Clear();
|
||||
Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user