1
This commit is contained in:
57
Assets/Artists/Scripts/Scenes/PlayerFixedPlace.cs
Normal file
57
Assets/Artists/Scripts/Scenes/PlayerFixedPlace.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user