103 lines
3.0 KiB
C#
103 lines
3.0 KiB
C#
using FishNet.Object;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.XR.CoreUtils;
|
|
using UnityEngine;
|
|
using FMOD.Studio;
|
|
|
|
public class ElevatorOuter : NetworkBehaviour
|
|
{
|
|
public ElevatorBox box;
|
|
|
|
public int floor;
|
|
public Transform boxPos;
|
|
|
|
public GameObject leftDoor;
|
|
public Transform leftDoorOpenPos;
|
|
public Transform leftDoorClosedPos;
|
|
|
|
public GameObject rightDoor;
|
|
public Transform rightDoorOpenPos;
|
|
public Transform rightDoorClosedPos;
|
|
|
|
private float doorOpenTime = 4f;
|
|
private float doorCloseTime = 5.6f;
|
|
|
|
public ElevatorStatusPlate statusPlate;
|
|
public AudioSource arrivalBeeper;
|
|
|
|
private EventInstance arrivalBeep;
|
|
private FirstPersonOcclusion occlusion;
|
|
|
|
private void Start()
|
|
{
|
|
doorOpenTime = box.doorOpenTime;
|
|
doorCloseTime = box.doorCloseTime;
|
|
|
|
arrivalBeep = AudioManager.Instance.CreateInstance(FMODEvents.Instance.ElevatorArrival); //initialising the variable
|
|
arrivalBeep.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //setting 3d attributes
|
|
|
|
occlusion = GetComponent<FirstPersonOcclusion>();
|
|
|
|
if (occlusion != null)
|
|
{
|
|
occlusion.InitialiseWithInstance(arrivalBeep);
|
|
}
|
|
|
|
}
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
Debug.Log("Something entered call area");
|
|
if (other.GetComponentInParent<XRPlayerMirror>() == null) return;
|
|
StartCoroutine(box.callElevator(floor));
|
|
Debug.Log("Player entered call area");
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
Debug.Log("Something entered call area");
|
|
if (other.GetComponentInParent<XRPlayerMirror>() == null) return;
|
|
box.interestExpired();
|
|
Debug.Log("Player exited call area");
|
|
}
|
|
public void CloseDoors()
|
|
{
|
|
StartCoroutine(MoveDoors(leftDoor, leftDoorClosedPos, rightDoor, rightDoorClosedPos, doorCloseTime));
|
|
|
|
|
|
}
|
|
public void OpenDoors()
|
|
{
|
|
arrivalBeeper.Play();
|
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ElevatorArrival, gameObject);
|
|
Debug.Log("Outer Doors opened");
|
|
StartCoroutine(MoveDoors(leftDoor, leftDoorOpenPos, rightDoor, rightDoorOpenPos, doorOpenTime));
|
|
|
|
}
|
|
|
|
private IEnumerator MoveDoors(GameObject left, Transform targetLeft, GameObject right, Transform targetRight, float moveTime)
|
|
{
|
|
Vector3 startL = left.transform.position;
|
|
Vector3 startR = right.transform.position;
|
|
float t = 0;
|
|
|
|
while (t < 1f)
|
|
{
|
|
t += Time.deltaTime / moveTime;
|
|
float easedT = Mathf.SmoothStep(0f, 1f, t); // ease in/out
|
|
left.transform.position = Vector3.Lerp(startL, targetLeft.position, easedT);
|
|
right.transform.position = Vector3.Lerp(startR, targetRight.position, easedT);
|
|
yield return null;
|
|
}
|
|
Debug.Log("Outer Doors moved");
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
arrivalBeep.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //updating the attributes
|
|
}
|
|
|
|
|
|
}
|
|
|