zz
This commit is contained in:
51
GlobalShared/OcTree/Data/ControllableEntityData.cs
Normal file
51
GlobalShared/OcTree/Data/ControllableEntityData.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using Global.Shared.API;
|
||||
using Global.Shared.Plugin;
|
||||
using Sandbox.Game.Entities;
|
||||
using Sandbox.Game.Entities.Character;
|
||||
using VRage.Game.Components;
|
||||
using VRageMath;
|
||||
|
||||
namespace Global.Shared.OcTree.Data
|
||||
{
|
||||
public class ControllableEntityData : IControllableEntityData, IOcTreeData
|
||||
{
|
||||
public ControllableEntityData(IMyControllableEntity entity)
|
||||
{
|
||||
Entity = entity;
|
||||
Id = entity.Entity.EntityId;
|
||||
Recompute();
|
||||
entity.Entity.PositionComp.OnPositionChanged += PositionChanged;
|
||||
}
|
||||
|
||||
public IMyControllableEntity Entity { get; set; }
|
||||
public long Id { get; }
|
||||
public List<long> ChildIds { get; } = new List<long>();
|
||||
public long Flags { get; private set; }
|
||||
public BoundingBoxD BoundingBox { get; private set; }
|
||||
|
||||
public void Recompute()
|
||||
{
|
||||
Flags = PlayerFlag.None;
|
||||
Flags |= Entity is MyCharacter ? PlayerFlag.Character : PlayerFlag.Controlled;
|
||||
BoundingBox = Entity.Entity.PositionComp.WorldAABB;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Recompute();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Entity.Entity.PositionComp.OnPositionChanged -= PositionChanged;
|
||||
Entity = null;
|
||||
BoundingBox = default;
|
||||
}
|
||||
|
||||
private void PositionChanged(MyPositionComponentBase obj)
|
||||
{
|
||||
GlobalStatic.OcTreeHandler.CharacterTree.Update(Id);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user