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

74 lines
1.5 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 System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
2021-05-13 19:20:44 +02:00
using DG.Tweening;
using UnityEditor;
using UnityEngine;
2021-05-13 19:20:44 +02:00
using UnityEngine.Windows.WebCam;
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;
// 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