This commit is contained in:
CortexCore
2024-04-19 21:43:30 +08:00
parent e12a6e5a46
commit 3cc6491973
46 changed files with 6792 additions and 23887 deletions

View File

@@ -81,8 +81,8 @@ namespace BITKit.Entities
{
public override DamageMessage ReadBinary(BinaryReader reader)
{
UnityEntitiesService.TryGetEntity(reader.ReadUInt64(),out var initiator);
UnityEntitiesService.TryGetEntity(reader.ReadUInt64(),out var target);
UnityEntitiesService.TryGetEntity(reader.ReadInt32(),out var initiator);
UnityEntitiesService.TryGetEntity(reader.ReadInt32(),out var target);
return new DamageMessage()
{
Initiator = initiator as Entity,

View File

@@ -3,7 +3,9 @@ using System.Collections.Generic;
using BITFALL.Rig;
using BITKit.Entities;
using Cysharp.Threading.Tasks.Triggers;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace BITKit
@@ -14,6 +16,7 @@ namespace BITKit
[SerializeField] private EntityHitbox[] hitboxes;
[SerializeReference,SubclassSelector] private IReference[] tagReferences;
#if UNITY_EDITOR
[BIT]
private void Build()
{
@@ -73,5 +76,6 @@ namespace BITKit
}
EditorUtility.SetDirty(this);
}
#endif
}
}

View File

@@ -20,7 +20,7 @@ namespace BITKit.Entities
private readonly GenericEvent genericEvent = new();
public ulong Id { get; set; }
public int Id { get; set; }
public CancellationToken CancellationToken { get; private set; }
public IEntityBehavior[] Behaviors { get;private set; }
public IEntityComponent[] Components => Behaviors.Cast<IEntityComponent>().ToArray();
@@ -131,7 +131,7 @@ namespace BITKit.Entities
private void Awake()
{
if (Id.IsDefault())
Id = (ulong)Guid.NewGuid().GetHashCode();
Id = GetInstanceID();
CancellationToken = gameObject.GetCancellationTokenOnDestroy();
Set(CancellationToken);
}

View File

@@ -38,10 +38,10 @@ public class UnityEntitiesServiceSingleton:IEntitiesService
public CancellationToken CancellationToken => UnityEntitiesService.CancellationToken;
public IEntity Get(ulong id) => UnityEntitiesService.Get(id);
public bool TryGetEntity(ulong id, out IEntity entity) => UnityEntitiesService.TryGetEntity(id, out entity);
public IEntity Get(int id) => UnityEntitiesService.Get(id);
public bool TryGetEntity(int id, out IEntity entity) => UnityEntitiesService.TryGetEntity(id, out entity);
public IEntity GetOrAdd(ulong id, Func<ulong, IEntity> factory)=>UnityEntitiesService.GetOrAdd(id,factory);
public IEntity GetOrAdd(int id, Func<int, IEntity> factory)=>UnityEntitiesService.GetOrAdd(id,factory);
public IEntity[] Query<T>()
@@ -85,7 +85,7 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
return false;
}
public static CancellationToken CancellationToken;
private static readonly ConcurrentDictionary<ulong,IEntity> Dictionary=new();
private static readonly ConcurrentDictionary<int,IEntity> Dictionary=new();
private static readonly Queue<IEntity> RegisterQueue = new();
private static readonly Queue<IEntity> UnRegisterQueue = new();
private void Awake()
@@ -126,18 +126,18 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
}
CancellationToken IEntitiesService.CancellationToken => CancellationToken;
public static IEntity Get(ulong id)=>Dictionary[id];
IEntity IEntitiesService.Get(ulong id)=>Get(id);
public static bool TryGetEntity(ulong id, out IEntity entity)
public static IEntity Get(int id)=>Dictionary[id];
IEntity IEntitiesService.Get(int id)=>Get(id);
public static bool TryGetEntity(int id, out IEntity entity)
{
return Dictionary.TryGetValue(id, out entity);
}
bool IEntitiesService.TryGetEntity(ulong id, out IEntity entity)=>TryGetEntity(id,out entity);
public static IEntity GetOrAdd(ulong id, Func<ulong, IEntity> factory)
bool IEntitiesService.TryGetEntity(int id, out IEntity entity)=>TryGetEntity(id,out entity);
public static IEntity GetOrAdd(int id, Func<int, IEntity> factory)
{
return Dictionary.GetOrAdd(id, factory);
}
IEntity IEntitiesService.GetOrAdd(ulong id, Func<ulong, IEntity> factory)=>GetOrAdd(id,factory);
IEntity IEntitiesService.GetOrAdd(int id, Func<int, IEntity> factory)=>GetOrAdd(id,factory);
IEntity[] IEntitiesService.Query<T>()=>Query<T>();
public static IEntity[] Query<T>()

View File

@@ -7,14 +7,14 @@ namespace BITKit.Entities
{
public interface IdComponent
{
ulong Id { get; }
int Id { get; }
string Name { get; }
}
public class UnityIdComponent : EntityBehavior,IdComponent
{
[SerializeField] private ulong id;
[SerializeField] private int id;
[SerializeField] private string unityName;
public ulong Id => id;
public int Id => id;
public string Name => unityName;
public override void Initialize(IEntity _entity)
{

View File

@@ -19,7 +19,7 @@ namespace BITKit.Entities
public struct EntitiesNetSyncBatchCommand
{
public int Length;
public ulong[] Ids;
public int[] Ids;
public ulong[] AddressablePaths;
public EntitiesNetSyncCommand[] Commands;
}
@@ -81,7 +81,7 @@ namespace BITKit.Entities
{
using var ms = new MemoryStream(obj.Data);
using var reader = new BinaryReader(ms);
var id = reader.ReadUInt64();
var id = reader.ReadInt32();
var path = reader.ReadUInt64();
entitiesService.GetOrAdd(id, x => AddEntity(id, path)).TryGetComponent<IEntityBinaryHeader>(out var header);
header.Deserialize(reader);
@@ -100,7 +100,7 @@ namespace BITKit.Entities
header.Deserialize(reader);
}
}
private static IEntity AddEntity(ulong id,ulong addressableId)
private static IEntity AddEntity(int id,ulong addressableId)
{
var entity = AddressableHelper.Get<GameObject>(addressableId);
var instance = Instantiate(entity).GetComponent<Entity>();
@@ -146,7 +146,7 @@ namespace BITKit.Entities
var batchCommand = new EntitiesNetSyncBatchCommand()
{
Length = headers.Length,
Ids = new ulong[headers.Length],
Ids = new int[headers.Length],
AddressablePaths = new ulong[headers.Length],
Commands = new EntitiesNetSyncCommand[headers.Length]
};

View File

@@ -15,8 +15,8 @@ namespace BITKit.Entities.Player
[SerializeField] private MonoStateMachine<T> stateMachine;
public override void OnAwake()
{
stateMachine?.Initialize();
base.OnAwake();
stateMachine?.Initialize();
}
public bool Enabled

View File

@@ -9,6 +9,7 @@ namespace BITKit
{
public interface IClosePoint
{
Vector3 CurrentPoint { get; }
Collider Collider { get; }
bool TryGetClosePoint(out Vector3 vector3);
}
@@ -18,6 +19,7 @@ namespace BITKit
public Transform root;
public LayerMask layerMask;
public float distance;
public Vector3 CurrentPoint { get; set; }
public Collider Collider { get; set; }
public bool TryGetClosePoint(out Vector3 vector3)
@@ -51,6 +53,7 @@ namespace BITKit
}
Collider = collider;
CurrentPoint = vector3;
return true;
//return vector3.y >= collider.bounds.center.y + collider.bounds.extents.y;
//return true;
@@ -75,6 +78,7 @@ namespace BITKit
public Vector3 StartPosition;
public Vector3 EndPosition;
public Vector3 CurrentPoint { get; set; }
public Collider Collider { get; set; }
private Rigidbody rigidbody;
@@ -233,6 +237,9 @@ namespace BITKit
if(reportBuilder is not null)
BIT4Log.Log<GetVaultPointFromCollider>(reportBuilder.ToString());
CurrentPoint = vector3;
Collider = hit;
return true;
}

View File

@@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Quadtree
{
@@ -405,10 +407,12 @@ namespace Quadtree
public void DrawBounds(bool displayNumberOfItems = false)
{
#if UNITY_EDITOR
if (displayNumberOfItems)
Handles.Label(Bounds.center, _items.Count.ToString());
Gizmos.DrawWireCube(Bounds.center, Bounds.size);
#endif
foreach (var subNode in SubNodes)
subNode.DrawBounds(displayNumberOfItems);
}

View File

@@ -5,7 +5,6 @@ using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Pool;
using System.Linq;
using UnityEditor.Search;
namespace BITKit.Sensors
{

View File

@@ -16,7 +16,7 @@ namespace BITKit.OpenWorld
base.OnLodChanged(oldLod, newLod);
OnLodChangedEvent?.Invoke(oldLod,newLod);
}
#if UNITY_EDITOR
[BIT]
private void CalculateBounds()
{
@@ -41,6 +41,7 @@ namespace BITKit.OpenWorld
offset = bounds.center - transform.position;
EditorUtility.SetDirty(this);
}
#endif
}
}

View File

@@ -3,7 +3,9 @@ using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Quadtree;
#if UNITY_EDITOR
using UnityEditor.SceneManagement;
#endif
using UnityEngine;
using UnityEngine.SceneManagement;
using YooAsset;
@@ -16,9 +18,7 @@ namespace BITKit.OpenWorld
[SerializeField] private Vector3 size;
[SerializeField] private Vector3 position;
[SerializeField, ReadOnly] private int lod = -1;
private SceneHandle _sceneHandle;
[BIT]
public async void Load()
{