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

72 lines
1.4 KiB
C#
Raw Normal View History

2021-05-13 19:20:44 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
2021-05-13 19:20:44 +02:00
using DG.Tweening;
using UnityEditor;
using UnityEngine;
public class Door : MonoBehaviour
{
2021-05-13 19:20:44 +02:00
[SerializeField] private Transform _graphics;
[SerializeField] private Transform _endpoint;
[SerializeField] private float _animTime = 1.2f;
2021-05-18 00:37:20 +02:00
public float AnimTime => _animTime;
2021-05-13 19:20:44 +02:00
// private bool _opened = false;
private Vector3 _initialPos;
private void Awake()
{
_initialPos = _graphics.position;
}
public void Open()
{
2021-05-13 19:20:44 +02:00
_graphics
.DOMove(_endpoint.position, _animTime)
.SetEase(Ease.InOutSine);
}
public void Close()
{
2021-05-13 19:20:44 +02:00
_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();
}
}
}
2021-05-13 19:20:44 +02:00
#endif