123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- /*
- * Control center, processing interaction, menu display, robot lock etc.
- *
- */
- using UnityEngine;
- using System.Collections;
- using Valve.VR;
- using UnityEngine.UI;
- using Valve.VR.InteractionSystem;
- using Valve.VR.InteractionSystem.Sample;
- using TMPro;
- public class InteractionManagement : MonoBehaviour
- {
- public static InteractionManagement Instance { get; private set; }
- public bool Robot_Locked = false;
- public bool Menu_Opened = true;
- public GameObject MenuGUI;
- public TextMeshPro playerText;
- public GameObject playerTextPanel;
- public CameraCreator cc;
- public GameObject[] Laser;
-
- // Listener(Handle the Change of the attribute)
- private bool Robot_Locked_Listener{
- get{return Robot_Locked; }
- set{
- if(Robot_Locked){
- SetPlayerText("Robot is locked",7,false);
- }
- else{
- SetPlayerText ("Robot is unlocked",7,false);
- }
- }
- }
- private bool Menu_Opened_Listener{
- get{return Menu_Opened; }
- set{
- if(Menu_Opened)
- {
- // open the menu
- SetPlayerText("Open the Menu", 3, false);
- foreach(GameObject child in Laser){
- child.SetActive(true);
- }
- MenuGUI.SetActive(true);
- LockRobot(true);
- ShowController();
- }
- else
- {
- MenuGUI.SetActive(false);
- foreach(GameObject child in Laser){
- child.SetActive(false);
- }
- }
- }
- }
- private void Awake()
- {
- Instance = this;
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- // Open the menu if open = true
- public void SetMenu(bool open){
- Menu_Opened = open;
- Menu_Opened_Listener = Menu_Opened;
-
- }
- // Closes menu if already open. Opens and updates menu if menu was closed.
- public void SetMenu(){
- Menu_Opened = !Menu_Opened;
- Menu_Opened_Listener = Menu_Opened;
- }
-
- // Lock Robot, if lockRobot = true
- public void LockRobot(bool lockRobot)
- {
- Robot_Locked = lockRobot;
- Robot_Locked_Listener = Robot_Locked;
- }
- // Locks robot if robot was not locked. Unlocks robot if robot was locked before.
- public void LockRobot()
- {
- Robot_Locked = !Robot_Locked;
- Robot_Locked_Listener = Robot_Locked;
- }
- // Show messages to palyer
- // time: the duraton(second) that msg will remain
- public void SetPlayerText(string msg, float time = 0, bool showOldText = true){
- if(time == 0 ){
- playerText.text = msg;
- playerTextPanel.SetActive(true);
- }
- else{
- StartCoroutine(PrintInfoForXSeconds(msg,time,showOldText));
- }
- }
- // close the message box
- public void SetPlayerText(){
- playerText.text = "";
- playerTextPanel.SetActive(false);
- }
- IEnumerator PrintInfoForXSeconds(string text, float seconds, bool showOldText)
- {
- string oldPlayerText = playerText.text;
- SetPlayerText(text);
- yield return new WaitForSecondsRealtime(seconds);
- if(showOldText)
- SetPlayerText(oldPlayerText);
- else
- {
- SetPlayerText();
- }
- }
-
- // Updates camera images and loads new image data on buttons.
- // Need CameraAutoLoader.cs
- // has not been tested. This function is copied directly from the origin project -Jingyi
- public void SetCamera(MenuMaker CameraContent){
- cc.updateCams();
- StartCoroutine(Load(CameraContent));
- //CameraGUI.SetActive(true);
- }
- IEnumerator Load(MenuMaker CameraContent)
- {
- yield return new WaitWhile(() => !cc.finishedUpdating);
- Debug.Log("VRInput.cs: Starting to render updated camera Images");
- foreach(string camera in cc.getDictionary().Keys)
- {
- Debug.Log("VRInput.cs: Load : " + camera);
- GameObject button = GameObject.Find("/camera360/right/image_raw/compressedButton");
- CameraContent.loadTexture(camera);
- }
- SetPlayerText("Cameras Updated.");
-
- yield return new WaitForSeconds(2);
- SetPlayerText();
-
- }
-
- // Depending on input scrolls menu up or down.
- public void Scroll(string direction, ScrollRect CameraScrollView){
- if(direction == "down")
- {
- if(CameraScrollView.verticalNormalizedPosition >=0.03)
- {
- CameraScrollView.verticalNormalizedPosition-=0.05f;
- Debug.Log("VRInput.cs: Scroll down ");
- }
- }
- else if(direction == "up")
- {
- if(CameraScrollView.verticalNormalizedPosition <=0.98)
- {
- CameraScrollView.verticalNormalizedPosition+=0.05f;
- Debug.Log("VRInput.cs: Scroll up ");
- }
- }
- }
- //SteamVR.Interactionsystem.Samples SelektonUIOptions
- public void SetHandSelekton(RenderModelChangerUI prefabsLeft,RenderModelChangerUI prefabsRight)
- {
- for (int handIndex = 0; handIndex < Player.instance.hands.Length; handIndex++)
- {
- Hand hand = Player.instance.hands[handIndex];
- if (hand != null)
- {
- if (hand.handType == SteamVR_Input_Sources.RightHand)
- hand.SetRenderModel(prefabsRight.rightPrefab);
- if (hand.handType == SteamVR_Input_Sources.LeftHand)
- hand.SetRenderModel(prefabsLeft.leftPrefab);
- }
- }
- }
- public void ShowController()
- {
- for (int handIndex = 0; handIndex < Player.instance.hands.Length; handIndex++)
- {
- Hand hand = Player.instance.hands[handIndex];
- if (hand != null)
- {
- hand.ShowController(true);
- }
- }
- }
- public void HideController()
- {
- for (int handIndex = 0; handIndex < Player.instance.hands.Length; handIndex++)
- {
- Hand hand = Player.instance.hands[handIndex];
- if (hand != null)
- {
- hand.HideController(true);
- }
- }
- }
- }
|