Complete reorga
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Core.Interaction;
|
||||
using Unheimlich.Core.Utils;
|
||||
|
||||
namespace Unheimlich.World.Environment
|
||||
{
|
||||
public class DoorInteractable : InteractableBase
|
||||
{
|
||||
[Header("Door Settings")]
|
||||
public bool IsOpen = false;
|
||||
[SerializeField] private float _openAngle = 90f;
|
||||
[SerializeField] private float _animationDuration = 0.5f;
|
||||
[SerializeField] private LeanTweenType _easeType = LeanTweenType.easeInOutQuad;
|
||||
|
||||
private Quaternion _closedRotation;
|
||||
private Quaternion _openRotation;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
_closedRotation = transform.rotation;
|
||||
_openRotation = _closedRotation * Quaternion.Euler(0, _openAngle, 0);
|
||||
|
||||
InteractionText = IsOpen ? "Close" : "Open";
|
||||
}
|
||||
|
||||
public override void Interact()
|
||||
{
|
||||
ToggleDoor();
|
||||
}
|
||||
|
||||
public void ToggleDoor()
|
||||
{
|
||||
gameObject.CancelAllTweens();
|
||||
|
||||
if (!IsOpen)
|
||||
{
|
||||
TweenHelper.RotateLocal(gameObject, _openRotation.eulerAngles, _animationDuration, null, _easeType);
|
||||
IsOpen = true;
|
||||
InteractionText = "Close";
|
||||
}
|
||||
else
|
||||
{
|
||||
TweenHelper.RotateLocal(gameObject, _closedRotation.eulerAngles, _animationDuration, null, _easeType);
|
||||
IsOpen = false;
|
||||
InteractionText = "Open";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d620ab476d55f2542a31783a6684f189
|
||||
@@ -0,0 +1,99 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Features.Player;
|
||||
|
||||
namespace Unheimlich.World.Environment
|
||||
{
|
||||
|
||||
public class SecurityCameraController : MonoBehaviour
|
||||
{
|
||||
[Header("Tracking Settings")]
|
||||
[SerializeField] private float _trackingDistance = 10f;
|
||||
[SerializeField] private float _rotationSpeed = 2f;
|
||||
[SerializeField] private Transform _pivotPoint;
|
||||
|
||||
[Header("LED Settings")]
|
||||
[SerializeField] private MeshRenderer _ledRenderer;
|
||||
[SerializeField] private float _blinkSpeed = 2f;
|
||||
[SerializeField] private float _minSmoothness = 0f;
|
||||
[SerializeField] private float _maxSmoothness = 0.5f;
|
||||
|
||||
private CharacterController _playerController;
|
||||
private Material _ledMaterial;
|
||||
private float _blinkTimer;
|
||||
private bool _isTracking;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (PlayerController.Instance != null)
|
||||
_playerController = PlayerController.Instance.GetComponent<CharacterController>();
|
||||
|
||||
if (_ledRenderer != null)
|
||||
{
|
||||
_ledMaterial = _ledRenderer.material;
|
||||
}
|
||||
|
||||
if (_pivotPoint == null)
|
||||
_pivotPoint = transform;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_playerController == null) return;
|
||||
|
||||
float distanceToPlayer = Vector3.Distance(_pivotPoint.position, _playerController.transform.position);
|
||||
_isTracking = distanceToPlayer <= _trackingDistance;
|
||||
|
||||
if (_isTracking)
|
||||
{
|
||||
TrackPlayer();
|
||||
}
|
||||
|
||||
UpdateLedBlink();
|
||||
}
|
||||
|
||||
void TrackPlayer()
|
||||
{
|
||||
Vector3 directionToPlayer = _playerController.transform.position - _pivotPoint.position;
|
||||
|
||||
if (directionToPlayer.sqrMagnitude > 0.001f)
|
||||
{
|
||||
Vector3 forward = -directionToPlayer.normalized;
|
||||
Vector3 right = Vector3.Cross(Vector3.up, forward).normalized;
|
||||
Vector3 up = Vector3.Cross(forward, right);
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation(up, forward);
|
||||
_pivotPoint.rotation = Quaternion.Slerp(_pivotPoint.rotation, targetRotation, Time.deltaTime * _rotationSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateLedBlink()
|
||||
{
|
||||
if (_ledMaterial == null) return;
|
||||
|
||||
_blinkTimer += Time.deltaTime * _blinkSpeed;
|
||||
|
||||
float smoothness = Mathf.Lerp(_minSmoothness, _maxSmoothness, Mathf.PingPong(_blinkTimer, 1f));
|
||||
|
||||
_ledMaterial.SetFloat("_Smoothness", smoothness);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_ledMaterial != null)
|
||||
Destroy(_ledMaterial);
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
if (_pivotPoint == null)
|
||||
_pivotPoint = transform;
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(_pivotPoint.position, _trackingDistance);
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawLine(_pivotPoint.position, _pivotPoint.position + _pivotPoint.forward * 2f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17a573927733b4343acc662995710bc2
|
||||
Reference in New Issue
Block a user