This commit is contained in:
CortexCore
2023-10-20 19:31:12 +08:00
parent 5cd094ed9a
commit a160813262
1878 changed files with 630581 additions and 4485 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BITKit;
using BITKit.Core.Entites;
using Unity.Mathematics;
using UnityEngine;
namespace BITFALL.Player.Movement
{
public class PlayerFixedPlace :MonoBehaviour, IPlayerFixedPlace,IDescription
{
[SerializeField] private Transform fixedPoint;
[SerializeField] private Transform exitPoint;
[SerializeField] private string description;
public float3 FixedPosition => fixedPoint.position;
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;
}
}