60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Player.Movement
|
|
{
|
|
public class PlayerFixedPlace :MonoBehaviour, IPlayerFixedPlace,IDescription
|
|
{
|
|
[SerializeField] private new Rigidbody rigidbody;
|
|
[SerializeField] private Transform fixedPoint;
|
|
[SerializeField] private Transform exitPoint;
|
|
[SerializeField] private string description;
|
|
public float3 FixedPosition =>fixedPoint.position;
|
|
public float3 Velocity => rigidbody.velocity;
|
|
public quaternion FixedRotation=> fixedPoint.rotation;
|
|
public float3 ExitPosition => exitPoint.position;
|
|
public quaternion ExitRotation => exitPoint.rotation;
|
|
|
|
public bool TryGetFixedEntity(out IEntity entity)
|
|
{
|
|
entity = _fixedEntity;
|
|
return _fixedEntity is not null;
|
|
}
|
|
public event Func<IEntity, bool> OnPlayerEntry;
|
|
public event Func<IEntity, bool> OnPlayerExit;
|
|
public event Action<IEntity> OnPlayerEntered;
|
|
public event Action<IEntity> OnPlayerExited;
|
|
public bool Entry(IEntity player)
|
|
{
|
|
if (_fixedEntity is not null) return false;
|
|
if (OnPlayerEntry is not null && OnPlayerEntry.CastAsFunc().Any(x => x.Invoke(player) is false))
|
|
{
|
|
return false;
|
|
}
|
|
_fixedEntity = player;
|
|
OnPlayerEntered?.Invoke(player);
|
|
return true;
|
|
}
|
|
public bool Exit(IEntity player)
|
|
{
|
|
if(_fixedEntity is null) return false;
|
|
if(OnPlayerExit is not null && OnPlayerExit.CastAsFunc().Any(x=>x.Invoke(player) is false))
|
|
{
|
|
return false;
|
|
}
|
|
_fixedEntity = null;
|
|
OnPlayerExited?.Invoke(player);
|
|
return true;
|
|
}
|
|
private IEntity _fixedEntity { get; set; }
|
|
public string Name => description;
|
|
}
|
|
|
|
}
|