revival/game/Assets/Scripts/PressurePlate/Door.cs

72 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEditor;
using UnityEngine;
public class Door : MonoBehaviour
{
[SerializeField] private Transform _graphics;
[SerializeField] private Transform _endpoint;
[SerializeField] private float _animTime = 1.2f;
public float AnimTime => _animTime;
// private bool _opened = false;
private Vector3 _initialPos;
private void Awake()
{
_initialPos = _graphics.position;
}
public void Open()
{
_graphics
.DOMove(_endpoint.position, _animTime)
.SetEase(Ease.InOutSine);
}
public void Close()
{
_graphics
.DOMove(_initialPos, _animTime)
.SetEase(Ease.InOutSine);
}
public void Reset()
{
_graphics.DOKill();
_graphics.position = _initialPos;
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(Door))]
public class DoorEditor : Editor
{
private Door _door;
private void OnEnable()
{
_door = target as Door;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (!Application.isPlaying) return;
if (GUILayout.Button("Open"))
{
_door.Open();
}
if (GUILayout.Button("Close"))
{
_door.Close();
}
}
}
#endif