2018年6月22日 星期五

Week12.玄的筆記


一、本週開始研究介面設計



1.研究介面的設置和按鈕的功能


此程式碼為"關閉"按鈕的功能

程式碼:

using System.Collections; using System.Collections.Generic; using UnityEngine; public class ButtonClose : MonoBehaviour { public GameObject panel01; public GameObject panel02; public GameObject panel03; // Use this for initialization private void Awake() { } void Start () { } // Update is called once per frame void Update () { } public void Close () { panel01.SetActive(false); panel02.SetActive(false); panel03.SetActive(false); Debug.Log ("Close"); } }


2.研究手把的雷射操控和觸發點的控制

此程式是手把的雷射和觸控物件


程式碼:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; // 宣告程式需要的 SteamVR_TrackedObject Component [RequireComponent(typeof(SteamVR_TrackedObject))] public class ControlMenu : MonoBehaviour { //bool IsShock = false; public GameObject MainMenuManager; public GameObject Panel1; public GameObject Panel2; public GameObject Panel3; GameObject HitObj; SteamVR_TrackedObject trackedObj; SteamVR_Controller.Device device; void Awake () { trackedObj = GetComponent<SteamVR_TrackedObject> (); } private Vector3 hitPoint; int laserAction; void FixedUpdate () { RaycastHit hit; if (trackedObj.isValid) { trackedObj = GetComponent<SteamVR_TrackedObject>(); } device = SteamVR_Controller.Input ((int)trackedObj.index); if (device.GetPress (SteamVR_Controller.ButtonMask.Trigger)) { if (Physics.Raycast(trackedObj.transform.position, transform.forward, out hit, 100)) { laserAction = 1; HitObj = hit.collider.gameObject; } } if (device.GetPressUp (SteamVR_Controller.ButtonMask.Trigger)) { switch (laserAction) { case 1: textt(HitObj); break; } } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { Debug.Log ("Grip Down"); //*IsShock = false; //每次按下,IsShock为false,才能保证手柄震动 //StartCoroutine("Shock",0.5f); //开启协程Shock(),第二个参数0.5f 即为协程Shock()的形参 if (!MainMenuManager.activeInHierarchy) { MainMenuManager.SetActive (true); } else { MainMenuManager.SetActive (false); } // 將 physics(物理引擎) 關掉 ///col.attachedRigidbody.isKinematic = true; // 設定controller為parent ///col.gameObject.transform.SetParent(gameObject.transform); } // . . . . } void textt(GameObject target) { switch (target.tag) { case "1": Debug.Log("Cube 1"); if (MainMenuManager.activeInHierarchy) { MainMenuManager.SetActive(false); } Panel1.SetActive(true); Panel2.SetActive(false); Panel3.SetActive(false); break; case "2": Debug.Log ("Cube 2"); if (MainMenuManager.activeInHierarchy) { MainMenuManager.SetActive (false); } Panel2.SetActive(true); Panel1.SetActive(false); Panel3.SetActive(false); break; case "3": Debug.Log("Cube 2"); if (MainMenuManager.activeInHierarchy) { MainMenuManager.SetActive(false); } Panel3.SetActive(true); Panel1.SetActive(false); Panel2.SetActive(false); break; } } /*void OnTriggerStay(Collider col) { Debug.Log ("碰到"); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { other.TogglePlay (); Debug.Log ("抓起"); // 將 physics(物理引擎) 關掉 ///col.attachedRigidbody.isKinematic = true; // 設定controller為parent ///col.gameObject.transform.SetParent(gameObject.transform); } if (device.GetTouchUp (SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log ("放開"); col.gameObject.transform.SetParent (null); col.attachedRigidbody.isKinematic = false; } }*/ /*IEnumerator Shock(float durationTime) { //Invoke函数,表示durationTime秒后,执行StopShock函数; Invoke("StopShock", durationTime); //协程一直使得手柄产生震动,直到布尔型变量IsShock为false; while (!IsShock) { device.TriggerHapticPulse(500); yield return new WaitForEndOfFrame(); } } void StopShock() { IsShock = true; //关闭手柄的震动 }*/ }

沒有留言:

張貼留言