Compare commits
18 Commits
1.0
...
d869053029
Author | SHA1 | Date | |
---|---|---|---|
|
d869053029 | ||
|
2c714da5b7 | ||
|
5b7ac3c361 | ||
|
0fddf0dc2a | ||
|
d502501b27 | ||
|
21b4f9091a | ||
|
90de0962a4 | ||
|
6fdd2fba21 | ||
|
960d33a60c | ||
|
5d7530adef | ||
|
fba360f1b8 | ||
|
ce049035e2 | ||
|
5d19061fab | ||
|
faf72b05e9 | ||
|
1650126d55 | ||
|
4ba741408d | ||
|
056e2cada5 | ||
|
79985ad6f5 |
16
Src/Blazor/BITKit.Blazor.asmdef
Normal file
16
Src/Blazor/BITKit.Blazor.asmdef
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "BITKit.Blazor",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"Blazor"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": true
|
||||
}
|
7
Src/Blazor/BITKit.Blazor.asmdef.meta
Normal file
7
Src/Blazor/BITKit.Blazor.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c853a9c32bc3a44eaa6b21b813d1b43
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RiderProjectSettingsUpdater">
|
||||
<option name="vcsConfiguration" value="2" />
|
||||
</component>
|
||||
</project>
|
6
Src/Core/.idea/.idea.Core.dir/.idea/vcs.xml
generated
6
Src/Core/.idea/.idea.Core.dir/.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
2899
Src/Core/.idea/.idea.Core.dir/.idea/workspace.xml
generated
2899
Src/Core/.idea/.idea.Core.dir/.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87bc33909c0bd1c49987c7095fb608c2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IEnableRequest
|
||||
{
|
||||
bool Enable { get; set; }
|
||||
object Sender { get; set; }
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d4d7ddcd2c941a2b2ebb06541c0b4f1
|
||||
timeCreated: 1689956335
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3a7547a71484b039d72c5fc8123d158
|
||||
timeCreated: 1686143117
|
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IAddressable
|
||||
{
|
||||
string AddressablePath { get; }
|
||||
|
||||
ulong AddressableId
|
||||
{
|
||||
get => ulong.MinValue;
|
||||
set
|
||||
{
|
||||
if (value <= 0) throw new ArgumentOutOfRangeException(nameof(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b1a0980868f4005bd4358f5cbf3dc0f
|
||||
timeCreated: 1686143127
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f928fa31b478e14ab62eae14d1135f9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,13 +0,0 @@
|
||||
using Unity.Mathematics;
|
||||
namespace BITKit.Animations
|
||||
{
|
||||
public interface IAnimator
|
||||
{
|
||||
void Play(string name, int index = 0, float normalizedTimeOffset = 0);
|
||||
void CrossFade(string name, float duration, int index = 0, float normalizedTimeOffset = 0);
|
||||
void OnStateEnter(int index, string name);
|
||||
void OnStateExit(int index, string name);
|
||||
float3 GetRootVelocity();
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6650f4c338c2b24c9ed54360510c7ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -7,6 +7,8 @@ using Cysharp.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
// ReSharper disable StringLiteralTypo
|
||||
#if NET5_0_OR_GREATER
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -18,21 +20,20 @@ namespace BITKit
|
||||
{
|
||||
public override string Message => "Application Is Not Playing";
|
||||
}
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public class BITApp
|
||||
{
|
||||
public static int Count => _count++;
|
||||
private static int _count;
|
||||
public static async UniTask SwitchToMainThread()
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
await UniTask.SwitchToMainThread();
|
||||
return;
|
||||
#endif
|
||||
if (SynchronizationContext is null)
|
||||
#else
|
||||
if (SynchronizationContext is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await UniTask.SwitchToSynchronizationContext(SynchronizationContext);
|
||||
#endif
|
||||
}
|
||||
public static class Time
|
||||
{
|
||||
@@ -168,21 +169,19 @@ namespace BITKit
|
||||
"MySql",
|
||||
};
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// 依赖服务集合
|
||||
/// </summary>
|
||||
public static ServiceCollection ServiceCollection { get; internal set; } = new();
|
||||
public static ServiceCollection ServiceCollection { get; set; } = new();
|
||||
/// <summary>
|
||||
/// 依赖服务提供接口
|
||||
/// </summary>
|
||||
public static ServiceProvider ServiceProvider { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// 服务创建后的回调
|
||||
/// </summary>
|
||||
public static Action<ServiceProvider> OnServiceProviderBuilded;
|
||||
#endif
|
||||
public static ServiceProvider ServiceProvider
|
||||
{
|
||||
get=>_serviceProvider??=ServiceCollection.BuildServiceProvider();
|
||||
set => _serviceProvider = value;
|
||||
}
|
||||
private static ServiceProvider _serviceProvider;
|
||||
/// <summary>
|
||||
/// 主线程
|
||||
/// </summary>
|
||||
@@ -190,7 +189,7 @@ namespace BITKit
|
||||
SynchronizationContext.Current;
|
||||
|
||||
[System.Serializable]
|
||||
public class OpenPath : IAction, IDisposable
|
||||
public class OpenPath : IDisposable
|
||||
{
|
||||
public string path;
|
||||
|
||||
@@ -218,7 +217,7 @@ namespace BITKit
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class OpenAPP : IAction, IDisposable
|
||||
public class OpenAPP : IDisposable
|
||||
{
|
||||
public string path;
|
||||
public string WorkingDirectory;
|
||||
@@ -254,7 +253,6 @@ namespace BITKit
|
||||
private static DateTime InitialTime { get; set; }=DateTime.Now;
|
||||
public static async UniTask Start(string appName = nameof(BITApp),AppSettings settings=default)
|
||||
{
|
||||
_count = 0;
|
||||
Time.TimeAsDouble = 0;
|
||||
Time.DeltaTime = 1 / 60f;
|
||||
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27a89b225d6709840bda913c68c0e51a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace BITKit.IO
|
||||
{
|
||||
public record BITAsset : IAsset
|
||||
{
|
||||
public BITAsset() { }
|
||||
public BITAsset(string name) {
|
||||
this.Name = name;
|
||||
}
|
||||
public BITAsset(string name,string str) {
|
||||
this.Name = name;
|
||||
Buffer=StringHelper.GetBytes(str);
|
||||
}
|
||||
public BITAsset(string name, byte[] bytes) {
|
||||
this.Name = name;
|
||||
this.Buffer = bytes;
|
||||
}
|
||||
public BITAsset(byte[] buffer)
|
||||
{
|
||||
this.Name = Guid.NewGuid().ToString();
|
||||
this.Buffer=buffer;
|
||||
}
|
||||
public string Name { get; set; }
|
||||
public byte[] Buffer { get; set; }
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 167aaa91f17608d41bf5fff1e9732640
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,154 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
using System.IO.Compression;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BITKit.IO
|
||||
{
|
||||
public record BITHeader
|
||||
{
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
||||
public string Name { get; set; }
|
||||
public DateTime CreateTime;
|
||||
public DateTime LastModifiedTime;
|
||||
|
||||
// ReSharper disable once CollectionNeverQueried.Global
|
||||
// ReSharper disable once FieldCanBeMadeReadOnly.Global
|
||||
public List<string> Files = new List<string>();
|
||||
}
|
||||
public class BITAssets : List<IAsset>
|
||||
{
|
||||
public static BITHeader ReadHeader(string path)
|
||||
{
|
||||
return Read<BITHeader>(path,"manifest.json");
|
||||
}
|
||||
public static void Build(string path, params IAsset[] assets)
|
||||
{
|
||||
List<IAsset> assetList = new();
|
||||
var header = new BITHeader
|
||||
{
|
||||
Name = path,
|
||||
CreateTime = DateTime.Now,
|
||||
LastModifiedTime = DateTime.Now
|
||||
};
|
||||
foreach (var asset in assets)
|
||||
{
|
||||
header.Files.Add(asset.Name);
|
||||
}
|
||||
|
||||
assetList.Add(new BITAsset()
|
||||
{
|
||||
Name = "manifest.json",
|
||||
Buffer = StringHelper.GetBytes(JsonConvert.SerializeObject(header, Formatting.Indented)),
|
||||
});
|
||||
assetList.AddRange(assets);
|
||||
var file = new FileInfo(path);
|
||||
if (file.Exists)
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
|
||||
using var zipFile = ZipFile.Open(path, ZipArchiveMode.Create);
|
||||
|
||||
foreach (var x in assetList)
|
||||
{
|
||||
var entry = zipFile.CreateEntry(x.Name);
|
||||
using var ms = new MemoryStream(x.Buffer);
|
||||
using var writer = entry.Open();
|
||||
ms.CopyTo(writer);
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
zipFile.Dispose();
|
||||
|
||||
BIT4Log.Log<BITAssets>($"已创建Assets:\n{path}");
|
||||
}
|
||||
|
||||
public static T ReadAs<T>(string path)
|
||||
{
|
||||
return Read<T>(path, typeof(T).Name);
|
||||
}
|
||||
public static T Read<T>(string path, string bufferPath, IStorageFile provider = null)
|
||||
{
|
||||
var json = ReadText(path, bufferPath, provider);
|
||||
return Read<T>(json);
|
||||
}
|
||||
|
||||
public static async Task<T> ReadAsync<T>(string path, string bufferPath, IStorageFile provider = null)
|
||||
{
|
||||
var json = await ReadTextAsync(path, bufferPath, provider);
|
||||
return Read<T>(json);
|
||||
}
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static T Read<T>(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static async Task<IAsset> ReadAssetAsync(string path, string bufferPath, IStorageFile provider = null)
|
||||
{
|
||||
provider = provider ?? new FileProvider(path);
|
||||
return ReadAsset(await provider.OpenReadAsync(), bufferPath);
|
||||
}
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static IAsset ReadAsset(string path, string bufferPath, IStorageFile provider = null)
|
||||
{
|
||||
provider = provider ?? new FileProvider(path);
|
||||
return ReadAsset(provider.OpenRead(), bufferPath);
|
||||
}
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static IAsset ReadAsset(Stream stream, string bufferPath)
|
||||
{
|
||||
BITAsset asset = new()
|
||||
{
|
||||
Name = bufferPath
|
||||
};
|
||||
using var zip = new ZipArchive(stream, ZipArchiveMode.Read);
|
||||
var entry = zip.GetEntry(bufferPath);
|
||||
if (entry is null)
|
||||
{
|
||||
StringBuilder stringBuilder = new($"未找到{bufferPath}");
|
||||
stringBuilder.AppendLine("已找到的Entry:");
|
||||
foreach (var _entry in zip.Entries)
|
||||
{
|
||||
stringBuilder.AppendLine($"{_entry!.Name}\t{_entry!.FullName}");
|
||||
}
|
||||
|
||||
throw new NullReferenceException(stringBuilder.ToString());
|
||||
}
|
||||
|
||||
using var _stream = entry!.Open();
|
||||
using var ms = new MemoryStream();
|
||||
_stream.CopyTo(ms);
|
||||
|
||||
asset.Buffer = ms.ToArray();
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static string ReadText(string path, string bufferPath, IStorageFile provider = null)
|
||||
{
|
||||
var asset = ReadAsset(path, bufferPath, provider);
|
||||
return StringHelper.GetString(asset.Buffer);
|
||||
}
|
||||
|
||||
public static async Task<string> ReadTextAsync(string path, string bufferPath, IStorageFile provider = null)
|
||||
{
|
||||
var asset = await ReadAssetAsync(path, bufferPath, provider);
|
||||
return StringHelper.GetString(asset.Buffer);
|
||||
}
|
||||
|
||||
public void Build(string path)
|
||||
{
|
||||
Build(path, ToArray());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 958be32f91d069c4f882b73d2ac58925
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef5795e833a88cd4b8c1485d4b50ebfd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b869357f0380e864eb445105d35c68b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,87 +0,0 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace BITKit.Auth
|
||||
{
|
||||
/// <summary>
|
||||
/// 授权服务
|
||||
/// </summary>
|
||||
public interface IAuthService
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否已授权
|
||||
/// </summary>
|
||||
bool IsAuthorized { get; }
|
||||
/// <summary>
|
||||
/// 是否正在授权
|
||||
/// </summary>
|
||||
bool IsAuthorizing { get; }
|
||||
/// <summary>
|
||||
/// 异步开始授权
|
||||
/// </summary>
|
||||
/// <param name="token">令牌</param>
|
||||
UniTask AuthorizeAsync(string token);
|
||||
/// <summary>
|
||||
/// 异步取消授权
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
UniTask CancelAuthorizationAsync();
|
||||
/// <summary>
|
||||
/// 开始授权的回调
|
||||
/// </summary>
|
||||
event Action<string> OnAuthorize;
|
||||
/// <summary>
|
||||
/// 已授权的回调
|
||||
/// </summary>
|
||||
event Action<string> OnAuthorized;
|
||||
/// <summary>
|
||||
/// 取消授权的回调
|
||||
/// </summary>
|
||||
event Action<string> UnAuthorize;
|
||||
/// <summary>
|
||||
/// 授权失败的回调
|
||||
/// </summary>
|
||||
event Action<string> OnAuthorizeFailure;
|
||||
}
|
||||
public abstract class AuthServiceImplement:IAuthService
|
||||
{
|
||||
protected abstract IAuthService service { get; }
|
||||
bool IAuthService.IsAuthorized => service.IsAuthorized;
|
||||
|
||||
bool IAuthService.IsAuthorizing => service.IsAuthorizing;
|
||||
|
||||
UniTask IAuthService.AuthorizeAsync(string token)
|
||||
{
|
||||
return service.AuthorizeAsync(token);
|
||||
}
|
||||
|
||||
UniTask IAuthService.CancelAuthorizationAsync()
|
||||
{
|
||||
return service.CancelAuthorizationAsync();
|
||||
}
|
||||
|
||||
event Action<string> IAuthService.OnAuthorize
|
||||
{
|
||||
add => service.OnAuthorize += value;
|
||||
remove => service.OnAuthorize -= value;
|
||||
}
|
||||
|
||||
event Action<string> IAuthService.OnAuthorized
|
||||
{
|
||||
add => service.OnAuthorized += value;
|
||||
remove => service.OnAuthorized -= value;
|
||||
}
|
||||
|
||||
event Action<string> IAuthService.UnAuthorize
|
||||
{
|
||||
add => service.UnAuthorize += value;
|
||||
remove => service.UnAuthorize -= value;
|
||||
}
|
||||
|
||||
event Action<string> IAuthService.OnAuthorizeFailure
|
||||
{
|
||||
add => service.OnAuthorizeFailure += value;
|
||||
remove => service.OnAuthorizeFailure -= value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df16dad99b7205a40b655489e7f19076
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public static class BITMapper
|
||||
{
|
||||
public static void Map<T>(T source, T target) where T : class
|
||||
public static T Map<T>(object source, T target) where T : class
|
||||
{
|
||||
foreach (var info in source.GetType().GetProperties(ReflectionHelper.Flags))
|
||||
{
|
||||
@@ -23,6 +23,7 @@
|
||||
targetInfo?.SetValue(target, value);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -137,9 +137,9 @@ namespace BITKit
|
||||
}
|
||||
public static void Write(BinaryWriter writer, object value)
|
||||
{
|
||||
if (value is not string && value is IList enumerable)
|
||||
try
|
||||
{
|
||||
try
|
||||
if (value is not string && value is IList enumerable)
|
||||
{
|
||||
var pars = enumerable.Cast<object>().ToArray();
|
||||
writer.Write(true);
|
||||
@@ -150,44 +150,45 @@ namespace BITKit
|
||||
WriteInterel(writer, obj);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(false);
|
||||
WriteInterel(writer,value);
|
||||
}
|
||||
return;
|
||||
void WriteInterel(BinaryWriter writer, object value)
|
||||
{
|
||||
var typeName = value.GetType().FullName;
|
||||
writer.Write(typeName!);
|
||||
if (netReaders.TryGetValue(typeName, out var netReader))
|
||||
{
|
||||
netReader.WriteBinaryAsObject(writer,value);
|
||||
}
|
||||
else if (value is IBinarySerialize serialize)
|
||||
{
|
||||
serialize.Write(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.Write(JsonConvert.SerializeObject(value));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.Warning<BITBinary>(typeName);
|
||||
throw;
|
||||
}
|
||||
|
||||
writer.Write(false);
|
||||
WriteInterel(writer,value);
|
||||
}
|
||||
return;
|
||||
void WriteInterel(BinaryWriter writer, object value)
|
||||
{
|
||||
var typeName = value.GetType().FullName;
|
||||
writer.Write(typeName!);
|
||||
if (netReaders.TryGetValue(typeName, out var netReader))
|
||||
{
|
||||
netReader.WriteBinaryAsObject(writer,value);
|
||||
}
|
||||
else if (value is IBinarySerialize serialize)
|
||||
{
|
||||
serialize.Write(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.Write(JsonConvert.SerializeObject(value));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
BIT4Log.Warning<BITBinary>(typeName);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
public static bool IsSupport(object obj) => IsSupport(obj.GetType().FullName);
|
||||
public static bool IsSupport(Type type) => IsSupport(type.FullName);
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de545a8f794806c468d90c634c53582a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using BITKit;
|
||||
namespace BITKit.IO
|
||||
{
|
||||
public class BITCache
|
||||
{
|
||||
public struct CacheInfo
|
||||
{
|
||||
public DateTime CreateTime;
|
||||
public Guid Guid;
|
||||
}
|
||||
public static Guid Guid = Guid.NewGuid();
|
||||
static string GetPath(string name) => PathHelper.GetFilePath("Cache", name);
|
||||
public static bool Read<T>(string name, out T value)
|
||||
{
|
||||
value = default;
|
||||
|
||||
var guid = BITAssets.Read<Guid>(GetPath(name), Constant.Authentication.Token);
|
||||
|
||||
if (guid == Guid)
|
||||
{
|
||||
value = BITAssets.Read<T>(GetPath(name), Constant.Value);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static void Write<T>(string name, T value)
|
||||
{
|
||||
List<BITAsset> assets = new();
|
||||
assets.Add(
|
||||
new(
|
||||
Constant.Authentication.Token,
|
||||
JsonConvert.SerializeObject(Guid)
|
||||
)
|
||||
);
|
||||
assets.Add(
|
||||
new(
|
||||
Constant.Value,
|
||||
JsonConvert.SerializeObject(value, Formatting.Indented)
|
||||
)
|
||||
);
|
||||
BITAssets.Build(GetPath(name), assets.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac9eaaab2af6fd14aa0b7ee692c7f6a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -28,7 +28,7 @@ namespace BITKit.CommandPattern
|
||||
void Release();
|
||||
}
|
||||
|
||||
public sealed class CommandSequence:List<ICommand>,IBinarySerialize
|
||||
public sealed class CommandSequence:List<ICommand>,Microsoft.SqlServer.Server.IBinarySerialize
|
||||
{
|
||||
public void Read(BinaryReader r)
|
||||
{
|
||||
|
@@ -9,47 +9,6 @@ using UnityEngine;
|
||||
#endif
|
||||
namespace BITKit
|
||||
{
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[Serializable]
|
||||
public sealed class ExecuteCommandAction : IAction
|
||||
{
|
||||
[SerializeField] private string command;
|
||||
public void Execute()
|
||||
{
|
||||
BITCommands.Excute(command);
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class DataCondition : ICondition
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private IReference key;
|
||||
public bool OnCheck()
|
||||
{
|
||||
return Data.Get<bool>(key.Value);
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class DataCommand : IAction,IConfigProvider
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private IReference key;
|
||||
[SerializeReference, SubclassSelector] private IReference value = new Reference();
|
||||
public void Execute()
|
||||
{
|
||||
//Data.Set(key.Value, value.Value);
|
||||
DataParser.Set(key.Value, value.Value);
|
||||
}
|
||||
|
||||
public string GetConfig(params object[] args)
|
||||
{
|
||||
return $"{key.Value} {value.Value}";
|
||||
}
|
||||
|
||||
public void Configure(params object[] args)
|
||||
{
|
||||
Execute();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
public static class BITCommands
|
||||
{
|
||||
[BITCommand]
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa98aca39a218e24cafafaf926cafa1c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f6fa3863d946c3498c578173c3d1fc7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bee0d6986688b7e4e9be6ebbdc1f90e1
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd8b926bc80cd5a449ef9935cc823425
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8396f90324bace74aafc8dc0867f1bdf
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16f85431055be764689c20d6c67707f2
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 312367e2057e9fd47a5442471a704ebe
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 537cdbd276ddd4146868419a9f799472
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7c81956d5c700b439fafad6e36b9f38
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51bb64493859aee419a58d193df15545
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c37fc4b5ef76dc04e8392d77de2ac40b
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4d5fbc238973c64e806d033116ea99e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 708d58ffd7eb8e646937789bdd962feb
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d15c60b4c9265e34bb990f342cf35cd9
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36dfb55b2db43804b9207700acf8da23
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f35ddeeb3f279a479e112661725ff95
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15d6e47d1d63e5f41a7e0676a19085e2
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11c54e9541abd79499031d2fd92af224
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit.IData
|
||||
{
|
||||
public class DataRecorder<T> : Player<T>
|
||||
{
|
||||
public int minLength;
|
||||
public event Action<List<T>> output;
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
list.Add(current);
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
list.Clear();
|
||||
}
|
||||
protected override void OnStop()
|
||||
{
|
||||
if (list.Count >= minLength)
|
||||
output.Invoke(list);
|
||||
list.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 328fb661a19494545977bc36935957fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,7 +0,0 @@
|
||||
namespace BITKit.IData
|
||||
{
|
||||
public interface IDataRecorder<TData> : IPlayer<TData>, IProvider<TData>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93a0a727bd68acb43984268230d94e1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4273bb14e8bf75943bcac37ef781c9fd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IDebuger
|
||||
{
|
||||
void Log(string context);
|
||||
void Log(string title, string context);
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93e219758c75ed542a536688b7cb21d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8016d8e2215fd544b81c945f11090744
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,177 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public abstract class InjectFromDI<T>
|
||||
{
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value ??= DI.Get<T>();
|
||||
}
|
||||
}
|
||||
private T _value;
|
||||
}
|
||||
public sealed class DI
|
||||
{
|
||||
static readonly ConcurrentDictionary<Type, object> dictionary = new();
|
||||
[ExcuteOnStop]
|
||||
public static void Clear()
|
||||
{
|
||||
//dictionary.Clear();
|
||||
}
|
||||
|
||||
public static void Register<Interface, Class>() where Class : new()
|
||||
{
|
||||
var type = typeof(Interface);
|
||||
|
||||
lock (dictionary)
|
||||
{
|
||||
if (dictionary.ContainsKey(typeof(Interface)))
|
||||
{
|
||||
BIT4Log.Log<DI>($"正在替换{type.Name}为{typeof(Class)}");
|
||||
}
|
||||
}
|
||||
|
||||
lock (dictionary)
|
||||
{
|
||||
dictionary.GetOrAdd(typeof(Interface), new Class());
|
||||
}
|
||||
}
|
||||
public static void Register<Interface>(Interface c)
|
||||
{
|
||||
lock (dictionary)
|
||||
{
|
||||
dictionary.AddOrUpdate(typeof(Interface), c, (x, y) => c);
|
||||
}
|
||||
}
|
||||
public static void Register(Type t, Type c)
|
||||
{
|
||||
lock (dictionary)
|
||||
dictionary.AddOrUpdate(t, c, (x, y) => Activator.CreateInstance(c));
|
||||
}
|
||||
public static void Register(Type t, object c)
|
||||
{
|
||||
lock (dictionary)
|
||||
dictionary.AddOrUpdate(t, c, (x, y) => c);
|
||||
}
|
||||
public static T GetOrCreate<T>() where T : new()
|
||||
{
|
||||
lock (dictionary)
|
||||
{
|
||||
var di = dictionary.GetOrAdd(typeof(T), new T());
|
||||
if (di is T value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
public static T GetOrAdd<T>(Func<T> craftFactory)
|
||||
{
|
||||
lock (dictionary)
|
||||
{
|
||||
var di = dictionary.GetOrAdd(typeof(T), craftFactory.Invoke());
|
||||
if (di is T value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
public static T Get<T>()
|
||||
{
|
||||
lock (dictionary)
|
||||
{
|
||||
if (dictionary.TryGetValue(typeof(T), out var obj))
|
||||
{
|
||||
if (obj is T i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw new NullReferenceException($"没有找到{typeof(T).Name}");
|
||||
}
|
||||
}
|
||||
public static bool TryGet<T>(out T value)
|
||||
{
|
||||
lock (dictionary)
|
||||
{
|
||||
if (dictionary.TryGetValue(typeof(T), out var obj))
|
||||
{
|
||||
if (obj is T i)
|
||||
{
|
||||
value = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
public static async Task<Interface> GetAsync<Interface>()
|
||||
{
|
||||
await TaskHelper.WaitUntil(() => dictionary.ContainsKey(typeof(Interface)) && dictionary[typeof(Interface) ]is not null);
|
||||
|
||||
return Get<Interface>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 自动依赖注入,将所有带有<see cref="InjectAttribute"/>的字段注入
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public static void Inject(object obj)
|
||||
{
|
||||
foreach (var propertyInfo in obj.GetType().GetProperties(ReflectionHelper.Flags))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (propertyInfo.GetCustomAttribute<ObsoleteAttribute>() is null &&
|
||||
propertyInfo.GetCustomAttribute<InjectAttribute>() is not null)
|
||||
{
|
||||
lock (dictionary)
|
||||
{
|
||||
if(dictionary!.TryGetValue(propertyInfo.PropertyType,out var value))
|
||||
{
|
||||
BIT4Log.Log<DI>($"已为{obj.GetType().Name}.{propertyInfo.Name}注入{value.GetType().Name}");
|
||||
propertyInfo.SetValue(obj,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
}
|
||||
foreach (var field in obj.GetType().GetFields(ReflectionHelper.Flags))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (field.GetCustomAttribute<ObsoleteAttribute>() is null &&
|
||||
field.GetCustomAttribute<InjectAttribute>() is not null)
|
||||
{
|
||||
lock (dictionary)
|
||||
{
|
||||
if(dictionary!.TryGetValue(field.FieldType,out var value))
|
||||
{
|
||||
BIT4Log.Log<DI>($"已为{obj.GetType().Name}.{field.Name}注入{value.GetType().Name}");
|
||||
field.SetValue(obj,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ba2ab8dab7f62d498a061f9554ace3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,6 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6987850473ae19b48b355d08911c2989
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -3,5 +3,6 @@ namespace BITKit
|
||||
public interface IDescription
|
||||
{
|
||||
public string Name { get; }
|
||||
public string Description { get; }
|
||||
}
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 549453866297ec84f8fcb28c9da7b1f0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IDiagnostics
|
||||
{
|
||||
string GetName();
|
||||
object GetDiagnostics();
|
||||
}
|
||||
public static class Diagnostics
|
||||
{
|
||||
static List<IDiagnostics> List = new();
|
||||
public static Action<string> Output;
|
||||
public static void Register(IDiagnostics x)
|
||||
{
|
||||
List.Add(x);
|
||||
}
|
||||
public static void UnRegister(IDiagnostics x)
|
||||
{
|
||||
List.Remove(x);
|
||||
}
|
||||
[BITCommand]
|
||||
public static void Diagnostic()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed21fc6661bcef548b4b3cf94460416c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f0710f16fd119f44a922b5e83c7d57b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -54,79 +54,87 @@ namespace BITKit.Entities
|
||||
|
||||
public T[] QueryComponents<T>()
|
||||
{
|
||||
return _queryCache.GetOrAdd(typeof(T), type =>
|
||||
{
|
||||
return _entities.Values.Where(entity => entity.TryGetComponent(out T component)).ToArray();
|
||||
}).Cast<T>().ToArray();
|
||||
throw new NotImplementedException();
|
||||
// return _queryCache.GetOrAdd(typeof(T), type =>
|
||||
// {
|
||||
// return _entities.Values.Where(entity => entity.TryGetComponent(out T component)).ToArray();
|
||||
// }).Cast<T>().ToArray();
|
||||
}
|
||||
public (T, T1)[] QueryComponents<T, T1>()
|
||||
{
|
||||
List<(T, T1)> list = new();
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1))
|
||||
list.Add((t, t1));
|
||||
}
|
||||
return list.ToArray();
|
||||
throw new NotImplementedException();
|
||||
// List<(T, T1)> list = new();
|
||||
// foreach (var entity in _entities.Values)
|
||||
// {
|
||||
// if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1))
|
||||
// list.Add((t, t1));
|
||||
// }
|
||||
// return list.ToArray();
|
||||
}
|
||||
public (T, T1, T2)[] QueryComponents<T, T1, T2>()
|
||||
{
|
||||
List<(T, T1, T2)> list = new();
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2))
|
||||
list.Add((t, t1, t2));
|
||||
}
|
||||
return list.ToArray();
|
||||
throw new NotImplementedException();
|
||||
// List<(T, T1, T2)> list = new();
|
||||
// foreach (var entity in _entities.Values)
|
||||
// {
|
||||
// if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2))
|
||||
// list.Add((t, t1, t2));
|
||||
// }
|
||||
// return list.ToArray();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3)[] QueryComponents<T, T1, T2, T3>()
|
||||
{
|
||||
List<(T, T1, T2, T3)> list = new();
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3))
|
||||
list.Add((t, t1, t2, t3));
|
||||
}
|
||||
return list.ToArray();
|
||||
throw new NotImplementedException();
|
||||
// List<(T, T1, T2, T3)> list = new();
|
||||
// foreach (var entity in _entities.Values)
|
||||
// {
|
||||
// if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3))
|
||||
// list.Add((t, t1, t2, t3));
|
||||
// }
|
||||
// return list.ToArray();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3, T4)[] QueryComponents<T, T1, T2, T3, T4>()
|
||||
{
|
||||
List<(T, T1, T2, T3, T4)> list = new();
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3) && entity.TryGetComponent(out T4 t4))
|
||||
list.Add((t, t1, t2, t3, t4));
|
||||
}
|
||||
return list.ToArray();
|
||||
throw new NotImplementedException();
|
||||
// List<(T, T1, T2, T3, T4)> list = new();
|
||||
// foreach (var entity in _entities.Values)
|
||||
// {
|
||||
// if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3) && entity.TryGetComponent(out T4 t4))
|
||||
// list.Add((t, t1, t2, t3, t4));
|
||||
// }
|
||||
// return list.ToArray();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3, T4, T5)[] QueryComponents<T, T1, T2, T3, T4, T5>()
|
||||
{
|
||||
List<(T, T1, T2, T3, T4, T5)> list = new();
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3) && entity.TryGetComponent(out T4 t4) && entity.TryGetComponent(out T5 t5))
|
||||
list.Add((t, t1, t2, t3, t4, t5));
|
||||
}
|
||||
return list.ToArray();
|
||||
throw new NotImplementedException();
|
||||
// List<(T, T1, T2, T3, T4, T5)> list = new();
|
||||
// foreach (var entity in _entities.Values)
|
||||
// {
|
||||
// if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3) && entity.TryGetComponent(out T4 t4) && entity.TryGetComponent(out T5 t5))
|
||||
// list.Add((t, t1, t2, t3, t4, t5));
|
||||
// }
|
||||
// return list.ToArray();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3, T4, T5, T6)[] QueryComponents<T, T1, T2, T3, T4, T5, T6>()
|
||||
{
|
||||
List<(T, T1, T2, T3, T4, T5, T6)> list = new();
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3) && entity.TryGetComponent(out T4 t4) && entity.TryGetComponent(out T5 t5) && entity.TryGetComponent(out T6 t6))
|
||||
list.Add((t, t1, t2, t3, t4, t5, t6));
|
||||
}
|
||||
return list.ToArray();
|
||||
throw new NotImplementedException();
|
||||
// List<(T, T1, T2, T3, T4, T5, T6)> list = new();
|
||||
// foreach (var entity in _entities.Values)
|
||||
// {
|
||||
// if (entity.TryGetComponent(out T t) && entity.TryGetComponent(out T1 t1) && entity.TryGetComponent(out T2 t2) && entity.TryGetComponent(out T3 t3) && entity.TryGetComponent(out T4 t4) && entity.TryGetComponent(out T5 t5) && entity.TryGetComponent(out T6 t6))
|
||||
// list.Add((t, t1, t2, t3, t4, t5, t6));
|
||||
// }
|
||||
// return list.ToArray();
|
||||
}
|
||||
|
||||
public ValueTuple<T, T1, T2, T3, T4, T5, T6, TRest>[] QueryComponents<T, T1, T2, T3, T4, T5, T6, TRest>() where TRest : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
46
Src/Core/ECS/Entity.cs
Normal file
46
Src/Core/ECS/Entity.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public class Entity : IEntity, IDisposable
|
||||
{
|
||||
public Entity()
|
||||
{
|
||||
ServiceCollection.AddSingleton<IEntity>(this);
|
||||
}
|
||||
public void WaitForInitializationComplete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public int Id { get; set; } = Guid.NewGuid().GetHashCode();
|
||||
public CancellationToken CancellationToken => _cancellationTokenSource.Token;
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = new();
|
||||
|
||||
public IServiceProvider ServiceProvider => _serviceProvider ??= ServiceCollection.BuildServiceProvider();
|
||||
private ServiceProvider _serviceProvider;
|
||||
public IServiceCollection ServiceCollection { get; } = new ServiceCollection();
|
||||
|
||||
public object[] GetServices() => ServiceCollection.ToArray()
|
||||
.Select(x => _serviceProvider.GetService(x.ServiceType)).ToArray();
|
||||
public void Inject(object obj)
|
||||
{
|
||||
foreach (var fieldInfo in obj.GetType().GetFields(ReflectionHelper.Flags))
|
||||
{
|
||||
if (Attribute.IsDefined(fieldInfo, typeof(InjectAttribute)))
|
||||
{
|
||||
fieldInfo.SetValue(obj, ServiceProvider.GetService(fieldInfo.FieldType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
_serviceProvider.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
11
Src/Core/ECS/Entity.cs.meta
Normal file
11
Src/Core/ECS/Entity.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 881c97aa8732ace4796d97874c8f8769
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,6 +1,7 @@
|
||||
using System.Threading;
|
||||
using System;
|
||||
using System.ComponentModel.Design;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#if NET5_0_OR_GREATER
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#endif
|
||||
@@ -11,44 +12,14 @@ namespace BITKit.Entities
|
||||
/// </summary>
|
||||
public interface IEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待初始化完成,通常用于其他系统需要等待实体初始化完成
|
||||
/// </summary>
|
||||
void WaitForInitializationComplete();
|
||||
int Id { get; }
|
||||
CancellationToken CancellationToken { get; }
|
||||
bool TryGetComponent<T>(out T component);
|
||||
bool TryGetComponent(Type type, out IEntityComponent component);
|
||||
IEntityComponent[] Components { get; }
|
||||
bool RegisterComponent<T>(T component);
|
||||
IServiceProvider ServiceProvider { get; }
|
||||
#if NET5_0_OR_GREATER
|
||||
IServiceCollection ServiceCollection { get; }
|
||||
object[] GetServices();
|
||||
#endif
|
||||
void Inject(object obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// 基本实体组件
|
||||
/// </summary>
|
||||
public interface IEntityComponent
|
||||
{
|
||||
IEntity Entity { get; set; }
|
||||
#if NET5_0_OR_GREATER
|
||||
void BuildService(IServiceCollection serviceCollection);
|
||||
#endif
|
||||
}
|
||||
public interface IEntityBehavior:IEntityComponent
|
||||
{
|
||||
void Initialize(IEntity _entity);
|
||||
void OnAwake();
|
||||
void OnStart();
|
||||
void OnUpdate(float deltaTime);
|
||||
void OnFixedUpdate(float deltaTime);
|
||||
void OnLateUpdate(float deltaTime);
|
||||
void OnDestroyComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// 基本实体服务
|
||||
/// </summary>
|
||||
public interface IEntitiesService
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ca7db14bd1dc33459de160d09804e8b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
57
Src/Core/Extensions/DisplayAttributeExtensions.cs
Normal file
57
Src/Core/Extensions/DisplayAttributeExtensions.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public static class DisplayAttributeExtensions
|
||||
{
|
||||
public static string GetDisplayName(this PropertyInfo self)
|
||||
{
|
||||
if (self.GetCustomAttribute<DisplayNameAttribute>() is not { } displayNameAttribute) return self.Name;
|
||||
var name = displayNameAttribute.DisplayName;
|
||||
return string.IsNullOrEmpty(name) ? self.Name : name;
|
||||
}
|
||||
public static string GetDisplayName(this FieldInfo self)
|
||||
{
|
||||
if (self.GetCustomAttribute<DisplayNameAttribute>() is not { } displayNameAttribute) return self.Name;
|
||||
var name = displayNameAttribute.DisplayName;
|
||||
return string.IsNullOrEmpty(name) ? self.Name : name;
|
||||
}
|
||||
public static string GetDisplayName(this object self)
|
||||
{
|
||||
{
|
||||
if (self.GetType().GetCustomAttribute<DisplayNameAttribute>() is { } displayNameAttribute)
|
||||
{
|
||||
return displayNameAttribute.DisplayName;
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
if (self.GetType().GetCustomAttribute<DisplayAttribute>() is { } displayAttribute)
|
||||
{
|
||||
return displayAttribute.Name;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
{
|
||||
if (self is Enum)
|
||||
{
|
||||
var field = self.GetType().GetField(self.ToString()!);
|
||||
|
||||
if (field.GetCustomAttribute<DisplayNameAttribute>() is DisplayNameAttribute displayNameAttribute)
|
||||
{
|
||||
return displayNameAttribute.DisplayName;
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
if (field.GetCustomAttribute<DisplayAttribute>() is DisplayAttribute displayAttribute)
|
||||
{
|
||||
return displayAttribute.Name;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return self.ToString();
|
||||
}
|
||||
}
|
||||
}
|
11
Src/Core/Extensions/DisplayAttributeExtensions.cs.meta
Normal file
11
Src/Core/Extensions/DisplayAttributeExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56c780c378f03f4419272fb5ae8dfb1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -8,7 +8,8 @@ namespace BITKit
|
||||
{
|
||||
public static IEnumerable<Func<T>> CastAsFunc<T>(this Func<T> self)
|
||||
{
|
||||
return self is null ? Array.Empty<Func<T>>() : self?.GetInvocationList().Cast<Func<T>>();
|
||||
var value = self;
|
||||
return value is null? Array.Empty<Func<T>>() : self?.GetInvocationList().Cast<Func<T>>();
|
||||
}
|
||||
public static IEnumerable<Func<T0, T1>> CastAsFunc<T0, T1>(this Func<T0, T1> self)
|
||||
{
|
||||
@@ -38,5 +39,29 @@ namespace BITKit
|
||||
{
|
||||
return self?.GetInvocationList().Cast<Func<T0, T1, T2, T3>>();
|
||||
}
|
||||
|
||||
public static IEnumerable<Func<T0, T1, T2, T3, T4>> CastAsFunc<T0, T1, T2, T3, T4>(
|
||||
this Func<T0, T1, T2, T3, T4> self)
|
||||
{
|
||||
return self?.GetInvocationList().Cast<Func<T0, T1, T2, T3, T4>>();
|
||||
}
|
||||
|
||||
public static IEnumerable<Func<T0, T1, T2, T3, T4, T5>> CastAsFunc<T0, T1, T2, T3, T4, T5>(
|
||||
this Func<T0, T1, T2, T3, T4, T5> self)
|
||||
{
|
||||
return self?.GetInvocationList().Cast<Func<T0, T1, T2, T3, T4, T5>>();
|
||||
}
|
||||
|
||||
public static IEnumerable<Func<T0, T1, T2, T3, T4, T5, T6>> CastAsFunc<T0, T1, T2, T3, T4, T5, T6>(
|
||||
this Func<T0, T1, T2, T3, T4, T5, T6> self)
|
||||
{
|
||||
return self?.GetInvocationList().Cast<Func<T0, T1, T2, T3, T4, T5, T6>>();
|
||||
}
|
||||
|
||||
public static IEnumerable<Func<T0, T1, T2, T3, T4, T5, T6, T7>> CastAsFunc<T0, T1, T2, T3, T4, T5, T6, T7>(
|
||||
this Func<T0, T1, T2, T3, T4, T5, T6, T7> self)
|
||||
{
|
||||
return self?.GetInvocationList().Cast<Func<T0, T1, T2, T3, T4, T5, T6, T7>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,10 @@ namespace BITKit
|
||||
public static async UniTask<string> PostJsonAsync(this HttpClient self, string requestUrl, object value , CancellationToken cancellationToken=default)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(value);
|
||||
if (value is string j)
|
||||
{
|
||||
json = j;
|
||||
}
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
var response =await self.PostAsync(requestUrl, content, cancellationToken);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
|
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.Mathematics;
|
||||
using Random = System.Random;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
@@ -166,6 +169,13 @@ namespace BITKit
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> RemoveIn<T>(this IEnumerable<T> self, T t)
|
||||
{
|
||||
var list = self.ToList();
|
||||
list.Remove(t);
|
||||
return list.ToArray();
|
||||
}
|
||||
public static bool TryRemove<TKey, TValue>(this IDictionary<TKey, TValue> self, TKey t)
|
||||
{
|
||||
if (self.ContainsKey(t))
|
||||
@@ -186,6 +196,26 @@ namespace BITKit
|
||||
self.Add(key, value);
|
||||
}
|
||||
}
|
||||
public static TValue Get<TKey,TValue>(this IDictionary<Type,TValue> self)
|
||||
{
|
||||
return self[typeof(TKey)];
|
||||
}
|
||||
|
||||
public static TValue[] TakeRandom<TValue>(this TValue[] self, int count)
|
||||
{
|
||||
//自动实现
|
||||
var random = new Random();
|
||||
var newList = self.ToList();
|
||||
count = math.min(count, newList.Count);
|
||||
var result = new TValue[count];
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var value = newList[random.Next(0, newList.Count)];
|
||||
newList.Remove(value);
|
||||
result[i] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> self, TKey key) where TValue : new()
|
||||
{
|
||||
lock (self)
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07743e56508d72f4bbfa9a075927d42c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,7 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit.UniversalInputSystem
|
||||
{
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 752666e8ffc64d74ea6a34b805789c51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
namespace BITKit.IO
|
||||
{
|
||||
public interface IAsset
|
||||
{
|
||||
string Name { get; set; }
|
||||
byte[] Buffer{ get; set; }
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3eb498b90aa487048a9fd9a3e9253dd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface INameProvider
|
||||
{
|
||||
string GetName(object obj, params object[] extensions);
|
||||
}
|
||||
[Serializable]
|
||||
public abstract class NameProvider : INameProvider
|
||||
{
|
||||
public abstract string GetName(object obj, params object[] extensions);
|
||||
protected string GetExtension(params object[] extensions)
|
||||
{
|
||||
return string.Concat(extensions.Select(x => x.ToString()));
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public class StringNameProvider : NameProvider
|
||||
{
|
||||
public string name;
|
||||
public override string GetName(object obj, params object[] extensions)
|
||||
{
|
||||
|
||||
return string.Concat(name, GetExtension(extensions));
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public class HashNameProvider : NameProvider
|
||||
{
|
||||
public override string GetName(object obj, params object[] extensions)
|
||||
{
|
||||
return string.Concat(obj.GetHashCode().ToString(), GetExtension(extensions));
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public class GuidNameProvider:NameProvider
|
||||
{
|
||||
public override string GetName(object obj, params object[] extensions)
|
||||
{
|
||||
return string.Concat(Guid.NewGuid().ToString(), GetExtension(extensions));
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public class DateTimeNameProvider : NameProvider
|
||||
{
|
||||
public string timeFormat;
|
||||
public override string GetName(object obj, params object[] extensions)
|
||||
{
|
||||
return string.Concat(DateTime.Now.ToString(timeFormat), GetExtension(extensions));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04b1d377d14b06c4c85a126fe8cc6bb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,103 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Timers;
|
||||
using Timer = System.Timers.Timer;
|
||||
namespace BITKit
|
||||
{
|
||||
public enum PlayerState
|
||||
{
|
||||
None,
|
||||
Playing,
|
||||
Paused,
|
||||
}
|
||||
public enum PlayerType
|
||||
{
|
||||
None,
|
||||
Player,
|
||||
Recorder,
|
||||
}
|
||||
public interface IPlayer<TSource>
|
||||
{
|
||||
void Start();
|
||||
void Pause();
|
||||
void Stop();
|
||||
int GetIndex();
|
||||
float GetTime();
|
||||
void SetIndex(int index);
|
||||
void SetTime(float time);
|
||||
PlayerState GetPlayState();
|
||||
}
|
||||
public class Player<T>
|
||||
{
|
||||
public int frameRate = 30;
|
||||
public PlayerState state;
|
||||
public List<T> list { get; protected set; } =new();
|
||||
public bool isPlaying;
|
||||
public event Action onStart;
|
||||
public event Action onStop;
|
||||
protected T current;
|
||||
private Timer timer = new() { AutoReset = true };
|
||||
public void Start()
|
||||
{
|
||||
if (isPlaying is false)
|
||||
{
|
||||
list ??= new();
|
||||
timer ??= new();
|
||||
isPlaying = true;
|
||||
timer.Interval = TimeSpan.FromSeconds(1f / (float)frameRate).Milliseconds;
|
||||
timer.Elapsed += Update;
|
||||
timer.Start();
|
||||
state = PlayerState.Playing;
|
||||
OnStart();
|
||||
onStart?.Invoke();
|
||||
}
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
if (isPlaying)
|
||||
{
|
||||
timer.Stop();
|
||||
timer.Elapsed -= Update;
|
||||
isPlaying = false;
|
||||
state = 0;
|
||||
OnStop();
|
||||
onStop?.Invoke();
|
||||
}
|
||||
}
|
||||
public void Cancel()
|
||||
{
|
||||
timer?.Stop();
|
||||
list?.Clear();
|
||||
onStop?.Invoke();
|
||||
timer = null;
|
||||
isPlaying = false;
|
||||
state = 0;
|
||||
}
|
||||
public void PlayOrPause()
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case PlayerState.None:
|
||||
Start();
|
||||
break;
|
||||
case PlayerState.Playing:
|
||||
state = PlayerState.Paused;
|
||||
break;
|
||||
case PlayerState.Paused:
|
||||
state = PlayerState.Playing;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void Set(T t)
|
||||
{
|
||||
current = t;
|
||||
}
|
||||
void Update(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
OnUpdate();
|
||||
}
|
||||
protected virtual void OnUpdate() { }
|
||||
protected virtual void OnStart() { }
|
||||
protected virtual void OnStop() { }
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user