public override void DefineControlLevel() { State textSlide = new State("TextSlide"); State blankSlide = new State("BlankSlide"); AddActiveStates(new List <State> { textSlide, blankSlide }); this.AddInitializationMethod(() => { panelObj.SetActive(true); }); //display text textSlide.AddStateInitializationMethod(() => { textObj.SetActive(true); textObj.GetComponent <Text>().text = slideText[slideCount] + defaultEndText; slideCount++; }); textSlide.SpecifyTermination(() => InputBroker.GetKeyDown(defaultKey), blankSlide, () => textObj.SetActive(false)); //blank slide to make slide change more obvious blankSlide.AddTimer(blankDur, textSlide, () => panelObj.SetActive(true)); blankSlide.SpecifyTermination(() => slideCount == slideText.Length, null, () => panelObj.SetActive(false)); }
// Update is called once per frame void Update() { // Check if no object is being collided and if no object is grabbed if (collidedObject == null && grabbedObject == null) { // If A and B are pressed, treat the virtual hand as a fist by turning off the collider's trigger if (InputBroker.GetKeyDown(WiimoteName + ":A") && InputBroker.GetKeyDown(WiimoteName + ":B")) { collider.isTrigger = false; } // Otherwise, ensure the collider is treated as a trigger else { collider.isTrigger = true; } } // Check if an object is being collided (but no object is grabbed yet) else if (collidedObject != null && grabbedObject == null) { // If A and B are pressed, grab the object, turn off its physics, and add it to the virtual hand's empty parent if (InputBroker.GetKeyDown(WiimoteName + ":A") && InputBroker.GetKeyDown(WiimoteName + ":B")) { // Turn off physics by turning on kinematics grabbedObject = collidedObject; grabbedObject.rigidbody.isKinematic = true; // Find the root of the grabbed object (for hierarchical objects) rootObject = grabbedObject.transform; while (rootObject.transform.parent != null) { rootObject = rootObject.transform.parent; } // Move the root of the grabbed object under the virtual hand's parent rootObject.parent = transform.parent; // Determine the root's initial position and rotation relative to the virtual hand's parent grabbedPosition = rootObject.localPosition; grabbedRotation = rootObject.localRotation; } } // Check if an object is grabbed else if (grabbedObject != null) { // Update the root's position and rotation relative to the virtual hand's parent rootObject.localPosition = grabbedPosition; rootObject.localRotation = grabbedRotation; // If A and B are NOT pressed, turn the object's physics back on and release it if (!InputBroker.GetKeyDown(WiimoteName + ":A") || !InputBroker.GetKeyDown(WiimoteName + ":B")) { grabbedObject.rigidbody.isKinematic = false; rootObject.parent = null; grabbedObject = null; } } }
// Update is called once per frame void Update() { // Up button moves forwards relative to the object's transformation if (InputBroker.GetKeyDown(WiimoteName + ":Up")) { CommonVariables.mappedPosition += transform.forward * TravelSpeed * Time.deltaTime; } // Down button moves backwards relative to the object's transformation if (InputBroker.GetKeyDown(WiimoteName + ":Down")) { CommonVariables.mappedPosition -= transform.forward * TravelSpeed * Time.deltaTime; } // Left button rotates the virtual world left (heading only) if (InputBroker.GetKeyDown(WiimoteName + ":Left")) { CommonVariables.mappedRotation.y -= RotationSpeed * Time.deltaTime; } // Right button rotates the virtual world right (heading only) if (InputBroker.GetKeyDown(WiimoteName + ":Right")) { CommonVariables.mappedRotation.y += RotationSpeed * Time.deltaTime; } // 1 button increases the travel speed if (InputBroker.GetKeyDown(WiimoteName + ":One")) { // Check for a click (not a continued press) if (!OneDown) { TravelSpeed *= 2.0f; } OneDown = true; } else { OneDown = false; } // 2 button decreases the travel speed if (InputBroker.GetKeyDown(WiimoteName + ":Two")) { // Check for a click (not a continued press) if (!TwoDown) { TravelSpeed /= 2.0f; } TwoDown = true; } else { TwoDown = false; } }
// Update is called once per frame5 void Update() { // Minus button decreases the IPD if (InputBroker.GetKeyDown(WiimoteName + ":Minus")) { CommonVariables.dynamicIPD -= RateOfChange * Time.deltaTime; } // Plus button increases the IPD if (InputBroker.GetKeyDown(WiimoteName + ":Plus")) { CommonVariables.dynamicIPD += RateOfChange * Time.deltaTime; } }
// Update is called once per frame void Update() { GameObject car = GameObject.Find("carbox"); car.transform.Translate(forward * Time.deltaTime * speed); car.transform.Rotate(up * Time.deltaTime * rotation); Debug.Log(forward); //Wii control if (InputBroker.GetKeyDown(RightWiimoteName + ":A")) { speed += 0.05f; Debug.Log(speed); } if (InputBroker.GetKeyDown(RightWiimoteName + ":B")) { if (speed >= 0.5) { speed -= 0.5f; } if (speed > 0 && speed < 0.5) { speed = 0; } Debug.Log(speed); } if (InputBroker.GetKeyDown(LeftWiimoteName + ":A")) { rotation = 30f; Debug.Log("Test"); } if (InputBroker.GetKeyDown(LeftWiimoteName + ":B")) { rotation = -30f; } if (!InputBroker.GetKeyDown(LeftWiimoteName + ":A") & !InputBroker.GetKeyDown(LeftWiimoteName + ":B")) { rotation = 0f; } // Keyboard control if (Input.GetKey(KeyCode.W)) { speed += 0.05f; Debug.Log(speed); } if (!Input.GetKey(KeyCode.W)) { if (speed >= 0.5) { speed -= 0.08f; } if (speed > 0 && speed < 0.5) { speed = 0; } Debug.Log(speed); } if (Input.GetKey(KeyCode.S)) { if (speed >= 0.5) { speed -= 0.5f; } if (speed > 0 && speed < 0.5) { speed = 0; } Debug.Log(speed); } if (Input.GetKey(KeyCode.A)) { rotation = -30f; } if (Input.GetKey(KeyCode.D)) { rotation = 30f; } if (!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D)) { rotation = 0f; } }
// Update is called once per frame void Update() { //virtual world Vector3 origin = transform.position + (transform.forward * 0.3f); Vector3 direction = transform.forward; RaycastHit hit; if (Physics.Raycast(origin, direction, out hit)) { Debug.Log("we hit something " + hit.collider.gameObject.name); //Debug.DrawLine(origin, hit.point,Color.red); myLine.SetPosition(0, origin); myLine.SetPosition(1, hit.point); myLine.SetColors(Color.red, Color.red); myLine.SetWidth(0.01f, 0.01f); if (InputBroker.GetKeyDown(RightWiimote + ":A")) { hit.collider.gameObject.tag = "Player"; taglist.Add(hit.collider.gameObject); } if (InputBroker.GetKeyDown(RightWiimote + ":Up")) { if (hit.collider.gameObject.tag == "Player") { hit.collider.gameObject.layer = 2; } } if (InputBroker.GetKeyDown(RightWiimote + ":Down")) { if (taglist.Count != 0) { foreach (GameObject obj in taglist) { obj.tag = "Untagged"; obj.layer = 0; } } } if (InputBroker.GetKeyPress(RightWiimote + ":B")) //select { SelectObjLst.Add(hit.collider.gameObject); hit.collider.gameObject.renderer.material.color = Color.red; } if (InputBroker.GetKeyPress(RightWiimote + ":One")) //remove one { SelectObjLst.Remove(hit.collider.gameObject); hit.collider.gameObject.renderer.material.SetColor("_Color", Color.white); } if (InputBroker.GetKeyPress(RightWiimote + ":Two")) //remove all, restart { if (SelectObjLst.Count != 0) { foreach (GameObject obj in SelectObjLst) { obj.renderer.material.SetColor("_Color", Color.white); } } if (taglist.Count != 0) { foreach (GameObject obj in taglist) { obj.tag = "Untagged"; obj.layer = 0; } } SelectObjLst.Clear(); taglist.Clear(); } } else { Debug.Log("we did not"); myLine.SetPosition(0, origin); myLine.SetPosition(1, origin); myLine.SetColors(Color.red, Color.red); myLine.SetWidth(0.01f, 0.01f); } if (InputBroker.GetKeyDown(LeftWiimote + ":A")) { MakeRotation(); } if (InputBroker.GetKeyDown(LeftWiimote + ":B")) { changeColor(); } if (InputBroker.GetKeyDown(LeftWiimote + ":Left")) { CommonVariables.mappedRotation.y -= RotationSpeed * Time.deltaTime; } // Right button rotates the virtual world right (heading only) if (InputBroker.GetKeyDown(LeftWiimote + ":Right")) { CommonVariables.mappedRotation.y += RotationSpeed * Time.deltaTime; } }
// Update is called once per frame void Update() { // Check if no object is being collided and if no object is grabbed if (collidedObject == null && grabbedObject == null) { // If A and B are pressed, treat the virtual hand as a fist by turning off the collider's trigger if (InputBroker.GetKeyDown(WiimoteName + ":A") && InputBroker.GetKeyDown(WiimoteName + ":B")) { collider.isTrigger = false; } // Otherwise, ensure the collider is treated as a trigger else { collider.isTrigger = true; } } // Check if an object is being collided (but no object is grabbed yet) else if (collidedObject != null && grabbedObject == null) { // If A and B are pressed, grab the object, turn off its physics, and add it to the virtual hand's empty parent if (InputBroker.GetKeyDown(WiimoteName + ":A") && InputBroker.GetKeyDown(WiimoteName + ":B")) { // Turn off physics by turning on kinematics grabbedObject = collidedObject; grabbedObject.rigidbody.isKinematic = true; // Find the root of the grabbed object (for hierarchical objects) rootObject = grabbedObject.transform; while (rootObject.transform.parent != null) { rootObject = rootObject.transform.parent; } // Move the root of the grabbed object under the virtual hand's parent rootObject.parent = transform.parent; // Determine the root's initial position and rotation relative to the virtual hand's parent grabbedPosition = rootObject.localPosition; grabbedRotation = rootObject.localRotation; } } // Check if an object is grabbed else if (grabbedObject != null) { // Update the root's position and rotation relative to the virtual hand's parent rootObject.localPosition = grabbedPosition; rootObject.localRotation = grabbedRotation; // If A and B are NOT pressed, turn the object's physics back on and release it if (!InputBroker.GetKeyDown(WiimoteName + ":A") || !InputBroker.GetKeyDown(WiimoteName + ":B")) { grabbedObject.rigidbody.isKinematic = false; rootObject.parent = null; grabbedObject = null; } } //detect if we have passed the go-go threshold GameObject hmdObject = GameObject.Find("HMD"); GameObject handObject = GameObject.Find("RightWiimote"); //phyical hand Vector3 hmdPosition = hmdObject.transform.localPosition; Vector3 handPosition = handObject.transform.localPosition; Vector3 handheadDiff = new Vector3(0.0f, 0.0f, 0.0f); //handheadDiff.x = handPosition.x - hmdPosition.x; handheadDiff.z = handPosition.z - hmdPosition.z; Debug.Log("position " + this.transform.localPosition); float factor = 2.0f; if (handheadDiff.magnitude > threshold) { float magCalc = handheadDiff.magnitude; magCalc *= factor; if (InputBroker.GetKeyDown(WiimoteName + ":Plus")) { magCalc = magCalc * magCalc * magCalc * magCalc * magCalc; Debug.Log("Plus "); magCalc /= factor * factor * factor * factor * factor; } else if (InputBroker.GetKeyDown(WiimoteName + ":Minus")) { magCalc = magCalc * magCalc; Debug.Log("Minus"); magCalc /= factor * factor; } else { magCalc = magCalc * magCalc * magCalc * magCalc; Debug.Log("Normal"); magCalc /= factor * factor * factor * factor; } this.transform.localPosition = handheadDiff.normalized * magCalc; grabbedObject.transform.localPosition = handheadDiff.normalized * magCalc; Debug.Log("position after threshold " + handheadDiff); } else { this.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); Debug.Log("position below threshold " + this.transform.localPosition); } }