140 lines
4.1 KiB
C#
140 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using KinematicCharacterController;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace BITFALL.Entites
|
|
{
|
|
public class EntityProxyMovement : EntityComponent, ICharacterController, IHealthCallback, IEntityMovement
|
|
{
|
|
public KinematicCharacterMotor motor;
|
|
public List<Collider> ignoreColliders;
|
|
public Vector3 currentVelocity;
|
|
public Vector3 currentPos;
|
|
public Quaternion currentRot;
|
|
public bool isGrounded;
|
|
public override void Initialize(IEntity entity)
|
|
{
|
|
base.Initialize(entity);
|
|
entity.Set<IEntityMovement>(this);
|
|
}
|
|
public void AfterCharacterUpdate(float deltaTime)
|
|
{
|
|
|
|
}
|
|
|
|
public void BeforeCharacterUpdate(float deltaTime)
|
|
{
|
|
}
|
|
|
|
public bool IsColliderValidForCollisions(Collider coll)
|
|
{
|
|
return ignoreColliders.Contains(coll) is false;
|
|
}
|
|
|
|
public void OnDiscreteCollisionDetected(Collider hitCollider)
|
|
{
|
|
}
|
|
|
|
public void OnGroundHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport)
|
|
{
|
|
}
|
|
|
|
public void OnMovementHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport)
|
|
{
|
|
}
|
|
|
|
public void PostGroundingUpdate(float deltaTime)
|
|
{
|
|
}
|
|
|
|
public void ProcessHitStabilityReport(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, Vector3 atCharacterPosition, Quaternion atCharacterRotation, ref HitStabilityReport hitStabilityReport)
|
|
{
|
|
}
|
|
|
|
public void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
|
|
{
|
|
currentRotation = currentRot;
|
|
}
|
|
|
|
public void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
|
|
{
|
|
currentVelocity = this.currentVelocity;
|
|
if (motor.GroundingStatus.FoundAnyGround)
|
|
{
|
|
currentVelocity.y = 0;
|
|
}
|
|
else
|
|
{
|
|
//currentVelocity -= Vector3.up * deltaTime;
|
|
}
|
|
}
|
|
public override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
|
|
motor.CharacterController = this;
|
|
KinematicCharacterSystem.CharacterMotors.Add(motor);
|
|
|
|
entity.RegisterCallback<IHealthCallback>(this);
|
|
}
|
|
public override void OnDestroyComponent()
|
|
{
|
|
KinematicCharacterSystem.CharacterMotors.Remove(motor);
|
|
}
|
|
|
|
public Vector3 Velocity { get; set; }
|
|
public Vector3 GroundVelocity { get; set; }
|
|
public bool IsGrounded { get; set; }
|
|
|
|
public void SyncMovement(Vector3 currentVelocity, Vector3 currentPos, Quaternion rotation, bool isGrounded)
|
|
{
|
|
this.currentVelocity = currentVelocity;
|
|
this.currentPos = currentPos;
|
|
this.currentRot = rotation;
|
|
this.isGrounded = isGrounded;
|
|
if (Vector3.Distance(currentPos,motor.TransientPosition)>0.32f)
|
|
{
|
|
motor.SetPosition(currentPos);
|
|
}
|
|
if(isGrounded is false && motor.GroundingStatus.FoundAnyGround)
|
|
{
|
|
motor.ForceUnground();
|
|
}
|
|
else if (isGrounded is false && motor.GroundingStatus.FoundAnyGround is false)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public void Movement(Vector3 relativeVector)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public void Movement(InputAction.CallbackContext context)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
[BIT]
|
|
public void ResetPosition()
|
|
{
|
|
motor.SetPosition(Vector3.zero);
|
|
}
|
|
|
|
public void OnSetAlive(bool alive)
|
|
{
|
|
motor.SetCapsuleCollisionsActivation(alive);
|
|
motor.SetGroundSolvingActivation(alive);
|
|
motor.SetMovementCollisionsSolvingActivation(alive);
|
|
}
|
|
public void OnSetHP(int hp)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |