1
This commit is contained in:
@@ -26,9 +26,9 @@ namespace BITKit
|
||||
public static event Action OnNextLine;
|
||||
private static Type currentType;
|
||||
#if UNITY_64
|
||||
[HideInCallstack]
|
||||
//[HideInCallstack]
|
||||
#endif
|
||||
public static void Log(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White)
|
||||
public static void Log(object x, ConsoleColor color = ConsoleColor.White)
|
||||
{
|
||||
OnSetConsoleColor?.Invoke(color);
|
||||
OnLog?.Invoke(x?.ToString());
|
||||
@@ -36,16 +36,16 @@ namespace BITKit
|
||||
#if UNITY_64
|
||||
[HideInCallstack]
|
||||
#endif
|
||||
public static void Log<T>(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White)
|
||||
public static void Log<T>(object x, ConsoleColor color = ConsoleColor.White)
|
||||
{
|
||||
if (currentType != typeof(T))
|
||||
{
|
||||
OnNextLine?.Invoke();
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
Log($"[{DateTime.Now}]{typeof(T).Name}:{x}", debugLevel);
|
||||
Log($"[{DateTime.Now}]{typeof(T).Name}:{x}");
|
||||
#else
|
||||
Log($"{typeof(T).Name}:{x}", debugLevel);
|
||||
Log($"{typeof(T).Name}:{x}");
|
||||
#endif
|
||||
|
||||
currentType = typeof(T);
|
||||
@@ -60,16 +60,16 @@ namespace BITKit
|
||||
#if UNITY_64
|
||||
[HideInCallstack]
|
||||
#endif
|
||||
public static void Warning(object x, int debugLevel = 0)
|
||||
public static void Warning(object x)
|
||||
{
|
||||
OnWarning?.Invoke(x.ToString());
|
||||
}
|
||||
#if UNITY_64
|
||||
[HideInCallstack]
|
||||
#endif
|
||||
public static void Warning<T>(object x, int debugLevel = 0)
|
||||
public static void Warning<T>(object x)
|
||||
{
|
||||
Warning($"{typeof(T).Name}:{x}", debugLevel);
|
||||
Warning($"{typeof(T).Name}:{x}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,8 +15,10 @@ namespace BITKit
|
||||
bool IsEntered { get; set; }
|
||||
void Entry();
|
||||
UniTask EntryAsync();
|
||||
void Entered();
|
||||
void Exit();
|
||||
UniTask ExitAsync();
|
||||
void Exited();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -92,6 +94,7 @@ namespace BITKit
|
||||
try
|
||||
{
|
||||
await currentElement.ExitAsync();
|
||||
currentElement.Exited();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -107,6 +110,7 @@ namespace BITKit
|
||||
try
|
||||
{
|
||||
await nextElement.EntryAsync();
|
||||
nextElement.Entered();
|
||||
}
|
||||
catch (OperationCanceledException){}
|
||||
OnEntry?.Invoke(nextElement);
|
||||
|
@@ -1,4 +1,6 @@
|
||||
namespace BITKit
|
||||
using System;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IOptional
|
||||
{
|
||||
@@ -34,6 +36,10 @@
|
||||
{
|
||||
return Allow ? Value : other;
|
||||
}
|
||||
public T IfNotAllow(Func<T> other)
|
||||
{
|
||||
return Allow ? Value : other.Invoke();
|
||||
}
|
||||
|
||||
public void SetValueThenAllow(T newValue)
|
||||
{
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
// ReSharper disable UnassignedGetOnlyAutoProperty
|
||||
|
||||
namespace BITKit.UX
|
||||
@@ -10,7 +12,7 @@ namespace BITKit.UX
|
||||
/// <para>⭐异步打开与关闭</para>
|
||||
/// <para>⭐当前可见状态</para>
|
||||
/// <para>⭐基本UI导航回调</para>
|
||||
public interface IUXPanel
|
||||
public interface IUXPanel:IEntryElement,IUpdate
|
||||
{
|
||||
/// <summary>
|
||||
/// 该面板是否具有动画
|
||||
@@ -32,8 +34,6 @@ namespace BITKit.UX
|
||||
/// 该面板是否启用玩家输入
|
||||
/// </summary>
|
||||
bool AllowInput { get; }
|
||||
void Entry();
|
||||
void Exit();
|
||||
/// <summary>
|
||||
/// 事件回调,当面板被打开时触发
|
||||
/// </summary>
|
||||
@@ -57,16 +57,42 @@ namespace BITKit.UX
|
||||
|
||||
public bool AllowInput => _iuxPanelImplementation.AllowInput;
|
||||
|
||||
public bool IsEntered
|
||||
{
|
||||
get => service.IsEntered;
|
||||
set => service.IsEntered = value;
|
||||
}
|
||||
|
||||
public void Entry()
|
||||
{
|
||||
_iuxPanelImplementation.Entry();
|
||||
}
|
||||
|
||||
public UniTask EntryAsync()
|
||||
{
|
||||
return service.EntryAsync();
|
||||
}
|
||||
|
||||
public void Entered()
|
||||
{
|
||||
service.Entered();
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
_iuxPanelImplementation.Exit();
|
||||
}
|
||||
|
||||
public UniTask ExitAsync()
|
||||
{
|
||||
return service.ExitAsync();
|
||||
}
|
||||
|
||||
public void Exited()
|
||||
{
|
||||
service.Exited();
|
||||
}
|
||||
|
||||
public event Action OnEntry
|
||||
{
|
||||
add => _iuxPanelImplementation.OnEntry += value;
|
||||
@@ -78,5 +104,10 @@ namespace BITKit.UX
|
||||
add => _iuxPanelImplementation.OnExit += value;
|
||||
remove => _iuxPanelImplementation.OnExit -= value;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
service.OnUpdate(deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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