public void Initialize() { Rigidbody = this.GetComponent <Rigidbody>(); if (Rigidbody == null) { Rigidbody = this.gameObject.AddComponent <Rigidbody>(); } Rigidbody.isKinematic = true; Rigidbody.maxAngularVelocity = float.MaxValue; Rigidbody.useGravity = false; Collider[] colliders = null; if (CustomModel == null) { colliders = InputDevice.SetupDefaultColliders(); } else { colliders = RenderModel.GetComponentsInChildren <Collider>(); //note: these should be trigger colliders } Player.RegisterHand(this); if (Player.PhysicalHands == true) { if (PhysicalController != null) { PhysicalController.Kill(); } PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>(); PhysicalController.Initialize(this, false); if (Player.AutomaticallySetControllerTransparency == true) { Color transparentcolor = Color.white; transparentcolor.a = (float)VisibilityLevel.Ghost / 100f; GhostRenderers = this.GetComponentsInChildren <Renderer>(); for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++) { NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor); } } if (colliders != null) { GhostColliders = colliders; } CurrentVisibility = VisibilityLevel.Ghost; } else { if (Player.AutomaticallySetControllerTransparency == true) { Color transparentcolor = Color.white; transparentcolor.a = (float)VisibilityLevel.Ghost / 100f; GhostRenderers = this.GetComponentsInChildren <Renderer>(); for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++) { NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor); } } if (colliders != null) { GhostColliders = colliders; } CurrentVisibility = VisibilityLevel.Ghost; } CurrentHandState = HandState.Idle; }
private IEnumerator DoInitialize() { do { yield return(null); //wait for render model to be initialized } while (RenderModelInitialized == false && CustomModel == null); Rigidbody = this.GetComponent <Rigidbody>(); if (Rigidbody == null) { Rigidbody = this.gameObject.AddComponent <Rigidbody>(); } Rigidbody.isKinematic = true; Collider[] Colliders = null; if (CustomModel == null) { string controllerModel = GetDeviceName(); SteamVR_RenderModel renderModel = this.GetComponentInChildren <SteamVR_RenderModel>(); switch (controllerModel) { case "vr_controller_05_wireless_b": Transform dk1Trackhat = renderModel.transform.Find("trackhat"); if (dk1Trackhat == null) { // Dk1 controller model has trackhat } else { dk1Trackhat.gameObject.SetActive(true); } SphereCollider dk1TrackhatCollider = dk1Trackhat.gameObject.GetComponent <SphereCollider>(); if (dk1TrackhatCollider == null) { dk1TrackhatCollider = dk1Trackhat.gameObject.AddComponent <SphereCollider>(); dk1TrackhatCollider.isTrigger = true; } Colliders = new Collider[] { dk1TrackhatCollider }; break; case "vr_controller_vive_1_5": Transform dk2Trackhat = renderModel.transform.FindChild("trackhat"); if (dk2Trackhat == null) { dk2Trackhat = new GameObject("trackhat").transform; dk2Trackhat.gameObject.layer = this.gameObject.layer; dk2Trackhat.parent = renderModel.transform; dk2Trackhat.localPosition = new Vector3(0, -0.033f, 0.014f); dk2Trackhat.localScale = Vector3.one * 0.1f; dk2Trackhat.localEulerAngles = new Vector3(325, 0, 0); dk2Trackhat.gameObject.SetActive(true); } else { dk2Trackhat.gameObject.SetActive(true); } Collider dk2TrackhatCollider = dk2Trackhat.gameObject.GetComponent <SphereCollider>(); if (dk2TrackhatCollider == null) { dk2TrackhatCollider = dk2Trackhat.gameObject.AddComponent <SphereCollider>(); dk2TrackhatCollider.isTrigger = true; } Colliders = new Collider[] { dk2TrackhatCollider }; break; default: Debug.LogError("Error. Unsupported device type: " + controllerModel); break; } } else { GameObject CustomModelObject = GameObject.Instantiate(CustomModel); Colliders = CustomModelObject.GetComponentsInChildren <Collider>(); //note: these should be trigger colliders CustomModelObject.transform.parent = this.transform; CustomModelObject.transform.localScale = Vector3.one; CustomModelObject.transform.localPosition = Vector3.zero; CustomModelObject.transform.localRotation = Quaternion.identity; } NVRPlayer.Instance.RegisterHand(this); if (NVRPlayer.Instance.PhysicalHands == true) { if (PhysicalController != null) { PhysicalController.Kill(); } PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>(); PhysicalController.Initialize(this, false); Color transparentcolor = Color.white; transparentcolor.a = (float)VisibilityLevel.Ghost / 100f; GhostRenderers = this.GetComponentsInChildren <Renderer>(); for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++) { NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor); } GhostColliders = Colliders; CurrentVisibility = VisibilityLevel.Ghost; } else { Color transparentcolor = Color.white; transparentcolor.a = (float)VisibilityLevel.Ghost / 100f; GhostRenderers = this.GetComponentsInChildren <Renderer>(); for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++) { NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor); } GhostColliders = Colliders; CurrentVisibility = VisibilityLevel.Ghost; } CurrentHandState = HandState.Idle; }