1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-12-15 10:51:15 +01:00
MaiDXR/Assets/Scripts/Configurations/Locker.cs

60 lines
1.7 KiB
C#
Raw Normal View History

2022-08-12 02:20:00 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class Locker : MonoBehaviour
{
public float Delay = 2.0f;
float targetTime;
public List<GameObject> buttons;
public GameObject LocalMotion;
2022-08-16 23:22:52 +02:00
public List<GameObject> RayObjects;
2022-08-12 02:20:00 +02:00
bool isLocked = false;
Material material;
void Start()
{
targetTime = Delay;
material = GetComponent<Renderer>().material;
material.color = Color.green;
Debug.Log("ButtonLock Start");
}
// Update is called once per frame
void ToggleLocker()
{
2022-08-16 23:22:52 +02:00
ToggleButtons();
ToggleLocalmotion();
ToggleRay();
2022-08-12 02:20:00 +02:00
isLocked = !isLocked;
if (isLocked)
material.color = Color.red;
else
material.color = Color.green;
}
void OnTriggerStay(Collider other)
{
targetTime -= Time.deltaTime;
if (targetTime <= 0.0f)
{
ToggleLocker();
targetTime = Delay;
}
}
2022-08-16 23:22:52 +02:00
void ToggleLocalmotion()
{
LocalMotion.GetComponent<ContinuousMoveProviderBase>().enabled = !LocalMotion.GetComponent<ContinuousMoveProviderBase>().enabled;
LocalMotion.GetComponent<ContinuousTurnProviderBase>().enabled = !LocalMotion.GetComponent<ContinuousTurnProviderBase>().enabled;
}
void ToggleButtons()
{
for (int i = 0; i < buttons.Count; i++)
buttons[i].SetActive(!buttons[i].activeSelf);
}
void ToggleRay()
{
for (int i = 0; i < RayObjects.Count; i++)
RayObjects[i].GetComponent<RayManager>().RaySwitch= !RayObjects[i].GetComponent<RayManager>().RaySwitch;
}
2022-08-12 02:20:00 +02:00
}