59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using BITKit;
|
||
|
using Unity.Mathematics;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.AI;
|
||
|
|
||
|
namespace BITFALL.Scene
|
||
|
{
|
||
|
public interface IDoorConfig
|
||
|
{
|
||
|
string Name { get; }
|
||
|
Transform Transform { get; }
|
||
|
Vector3 OpenEuler { get; }
|
||
|
Vector3 CloseEuler { get; }
|
||
|
}
|
||
|
[Serializable]
|
||
|
public class BasicDoorConfig:IDoorConfig
|
||
|
{
|
||
|
[SerializeField] private string name;
|
||
|
[SerializeField] private Transform transform;
|
||
|
[SerializeField] private Vector3 openEuler;
|
||
|
[SerializeField] private Vector3 closeEuler;
|
||
|
public string Name => name;
|
||
|
public Transform Transform => transform;
|
||
|
public Vector3 OpenEuler => openEuler;
|
||
|
public Vector3 CloseEuler => closeEuler;
|
||
|
}
|
||
|
public sealed class BasicDoor : MonoBehaviour,IAction,IDescription,ISceneBlockArea
|
||
|
{
|
||
|
[SerializeReference,SubclassSelector] private IReference objName;
|
||
|
[SerializeField] private bool isOpened;
|
||
|
[SerializeField] private bool isLocked;
|
||
|
[SerializeField] private new Collider collider;
|
||
|
[SerializeField] private NavMeshObstacle obstacle;
|
||
|
[SerializeReference, SubclassSelector] private IDoorConfig[] doors;
|
||
|
public void Execute()
|
||
|
{
|
||
|
if(isLocked)return;
|
||
|
isOpened = !isOpened;
|
||
|
foreach (var door in doors)
|
||
|
{
|
||
|
door.Transform.localRotation = Quaternion.Euler(isOpened ? door.OpenEuler : door.CloseEuler);
|
||
|
}
|
||
|
if(obstacle)obstacle.enabled = !isOpened;
|
||
|
}
|
||
|
public string Name => objName.Value;
|
||
|
public bool IsBlocked =>isLocked || !isOpened;
|
||
|
public bool InRange(float3 position)=>collider.bounds.Contains(position);
|
||
|
public bool InRange(float3 position, float3 direction)
|
||
|
{
|
||
|
var ray = new Ray(position, ((Vector3)direction).normalized);
|
||
|
return collider.Raycast(ray, out _, 1f);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|