1
This commit is contained in:
@@ -1,7 +1,39 @@
|
||||
using System;
|
||||
|
||||
#if UNITY_64
|
||||
using UnityEngine;
|
||||
#endif
|
||||
namespace BITKit
|
||||
{
|
||||
public class ConstantHash
|
||||
{
|
||||
public ConstantHash(object value)
|
||||
{
|
||||
#if UNITY_64
|
||||
HashCode = Animator.StringToHash(value.ToString());
|
||||
#else
|
||||
HashCode = value.GetHashCode();
|
||||
#endif
|
||||
AsString = value.ToString();
|
||||
}
|
||||
public readonly int HashCode;
|
||||
public readonly string AsString;
|
||||
public static implicit operator string (ConstantHash self)
|
||||
{
|
||||
return self.AsString;
|
||||
}
|
||||
public static implicit operator int (ConstantHash self)
|
||||
{
|
||||
return self.HashCode;
|
||||
}
|
||||
public static implicit operator ConstantHash(string value)
|
||||
{
|
||||
return new ConstantHash(value);
|
||||
}
|
||||
public static implicit operator ConstantHash(int value)
|
||||
{
|
||||
return new ConstantHash(value);
|
||||
}
|
||||
}
|
||||
public static partial class Constant
|
||||
{
|
||||
public partial struct Header
|
||||
|
@@ -15,6 +15,10 @@ namespace BITKit
|
||||
void AddListener<T>(TKey key, Action<T> action);
|
||||
void Invoke<T>(TKey key, T value);
|
||||
void RemoveListener<T>(TKey key, Action<T> action);
|
||||
|
||||
void SetDirect(int key, object value);
|
||||
void GetDirect(int key, out object value);
|
||||
void GetDirect<T>(int key,out T value);
|
||||
}
|
||||
/// <summary>泛型数据库,主要使用方式为Get和Set</summary>
|
||||
public interface IDatabase
|
||||
@@ -25,8 +29,10 @@ namespace BITKit
|
||||
}
|
||||
public class GenericEvent : IGenericEvent<string>, IDatabase, IDiagnostics
|
||||
{
|
||||
Dictionary<string, List<object>> events = new();
|
||||
Dictionary<string, object> dictionary = new();
|
||||
private readonly Dictionary<int,object> _directDirection = new();
|
||||
|
||||
private readonly Dictionary<string, List<object>> events = new();
|
||||
private readonly Dictionary<string, object> dictionary = new();
|
||||
public const string defaultEventName = nameof(GenericEvent);
|
||||
public void AddListener<T>(Action<T> action) =>
|
||||
AddListener<T>(defaultEventName, action);
|
||||
@@ -120,6 +126,28 @@ namespace BITKit
|
||||
var list = events.Get(key);
|
||||
list.TryRemove(action);
|
||||
}
|
||||
|
||||
public void SetDirect(int key, object value)
|
||||
{
|
||||
_directDirection.Set(key, value);
|
||||
}
|
||||
|
||||
public void GetDirect(int key,out object value)
|
||||
{
|
||||
value = _directDirection.Get(key);
|
||||
}
|
||||
public void GetDirect<T>(int key,out T value)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = (T) _directDirection.Get(key);
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
value = default;
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugAllValues()
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
|
@@ -28,6 +28,10 @@
|
||||
{
|
||||
current++;
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
current = max;
|
||||
}
|
||||
public bool AllowOnly => current > 0;
|
||||
public bool Allow => CanUpdate();
|
||||
public bool CanUpdate()
|
||||
|
@@ -3,7 +3,24 @@ using System.Collections.Generic;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class ValidHandle
|
||||
public interface IValidHandle
|
||||
{
|
||||
bool Allow { get; }
|
||||
void AddElement(object obj);
|
||||
void RemoveElement(object obj);
|
||||
void AddDisableElements(object obj);
|
||||
void RemoveDisableElements(object obj);
|
||||
void SetElements(object obj, bool add = true);
|
||||
void SetDisableElements(object obj, bool add = true);
|
||||
void Invoke();
|
||||
void Invoke(bool value);
|
||||
void AddListener(Action<bool> action);
|
||||
void RemoveListener(Action<bool> action);
|
||||
void Clear();
|
||||
}
|
||||
|
||||
[CustomType(typeof(IValidHandle))]
|
||||
public sealed class ValidHandle: IValidHandle
|
||||
{
|
||||
public ValidHandle() {}
|
||||
public ValidHandle(Action<bool> boolDelegate)
|
||||
@@ -24,7 +41,7 @@ namespace BITKit
|
||||
private bool tempEnable;
|
||||
private Action<bool> EventOnEnableChanged;
|
||||
|
||||
public virtual void AddElement(object obj)
|
||||
public void AddElement(object obj)
|
||||
{
|
||||
if (objs.Contains(obj))
|
||||
{
|
||||
@@ -36,7 +53,8 @@ namespace BITKit
|
||||
}
|
||||
CheckEnable();
|
||||
}
|
||||
protected void CheckEnable()
|
||||
|
||||
private void CheckEnable()
|
||||
{
|
||||
tempEnable = objs.Count > 0 && disableObjs.Count == 0;
|
||||
if (tempEnable != enableHandle)
|
||||
@@ -46,7 +64,7 @@ namespace BITKit
|
||||
EventOnEnableChanged.Invoke(enableHandle);
|
||||
}
|
||||
}
|
||||
public virtual void RemoveElement(object obj)
|
||||
public void RemoveElement(object obj)
|
||||
{
|
||||
if (objs.Contains(obj))
|
||||
{
|
||||
@@ -58,8 +76,8 @@ namespace BITKit
|
||||
}
|
||||
CheckEnable();
|
||||
}
|
||||
public virtual int lenght => objs.Count;
|
||||
public virtual string[] GetElements()
|
||||
public int lenght => objs.Count;
|
||||
public string[] GetElements()
|
||||
{
|
||||
List<string> elementNames = new List<string>();
|
||||
for (int i = 0; i < objs.Count; i++)
|
||||
@@ -68,8 +86,8 @@ namespace BITKit
|
||||
}
|
||||
return elementNames.ToArray();
|
||||
}
|
||||
public virtual bool Contains(object obj) => objs.Contains(obj);
|
||||
public virtual void AddDisableElements(object obj)
|
||||
public bool Contains(object obj) => objs.Contains(obj);
|
||||
public void AddDisableElements(object obj)
|
||||
{
|
||||
if (disableObjs.Contains(obj))
|
||||
{
|
||||
@@ -103,7 +121,7 @@ namespace BITKit
|
||||
RemoveElement(obj);
|
||||
}
|
||||
}
|
||||
public virtual void SetDisableElements(object obj, bool add = true)
|
||||
public void SetDisableElements(object obj, bool add = true)
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
|
Reference in New Issue
Block a user