示例#1
0
        private IEnumerator DoSetDeviceIndex(int index)
        {
            yield return(new WaitForSeconds(1f));

            yield return(null); //wait for children to be initialized

            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic = true;

            Transform trackhat = this.transform.FindChild("trackhat");

            Collider trackhatCollider = trackhat.GetComponent <Collider>();

            if (trackhatCollider == null)
            {
                trackhatCollider = trackhat.gameObject.AddComponent <SphereCollider>();
            }
            trackhatCollider.isTrigger = true;

            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    = new Collider[] { trackhatCollider };
                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
示例#2
0
        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;
        }
示例#3
0
        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;
            Rigidbody.maxAngularVelocity = float.MaxValue;
            Rigidbody.useGravity         = false;

            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 if (RenderModelInitialized == false)
            {
                RenderModelInitialized = true;
                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);
                }

                if (Colliders != null)
                {
                    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);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
示例#4
0
        private IEnumerator DoInitialize()
        {
            yield return null; //wait for children to be initialized

            Rigidbody = this.GetComponent<Rigidbody>();
            if (Rigidbody == null)
                Rigidbody = this.gameObject.AddComponent<Rigidbody>();
            Rigidbody.isKinematic = true;
            
            Transform trackhat = this.transform.FindChild("trackhat");

            Collider trackhatCollider = trackhat.GetComponent<Collider>();
            if (trackhatCollider == null)
                trackhatCollider = trackhat.gameObject.AddComponent<SphereCollider>();
            trackhatCollider.isTrigger = true;

            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 = new Collider[] { trackhatCollider };
                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
示例#5
0
        public void DoInitialize()
        {
            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)
            {
                GameObject CustomModelObject = GameObject.Instantiate(CustomModel);
                Colliders = CustomModelObject.GetComponentsInChildren <Collider>();
                foreach (var collider in Colliders)
                {
                    collider.isTrigger = true;
                }

                CustomModelObject.transform.parent        = this.transform;
                CustomModelObject.transform.localScale    = Vector3.one;
                CustomModelObject.transform.localPosition = Vector3.zero;
                CustomModelObject.transform.localRotation = Quaternion.identity;
            }
            else if (GhostColliders == null)
            {
                Colliders = this.GetComponentsInChildren <Collider>();
            }

            if (ExternalColliders != null)
            {
                ExternalColliders.Subscribe(this);
            }

            player.RegisterHand(this);

            if (player.PhysicalHands == true)
            {
                bool InitialState = false;

                if (PhysicalController != null)
                {
                    if (PhysicalController.State == true)
                    {
                        InitialState = true;
                    }
                    else
                    {
                        InitialState = false;
                    }
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, InitialState);

                if (InitialState == true)
                {
                    ForceGhost();
                }

                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    Color transparentcolor = new Color(0.38f, 0.67f, 0.85f); // GhostRenderers[rendererIndex].material.color;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }
            else
            {
                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    Color transparentcolor = new Color(0.38f, 0.67f, 0.85f);// GhostRenderers[rendererIndex].material.color;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
示例#6
0
        private IEnumerator DoInitialize()
        {
            Debug.Log("DoInitialize() on " + this.name);

            while (RenderModelInitialized == false)
            {
                yield return(null); //wait for render model to be initialized
            }
            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic = true;

            Collider[] Colliders = null;

            string controllerModel = GetDeviceName();

            switch (controllerModel)
            {
            case "vr_controller_05_wireless_b":
                Transform dk1Trackhat = this.transform.FindChild("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 = this.transform.FindChild("trackhat");
                if (dk2Trackhat == null)
                {
                    dk2Trackhat                  = new GameObject("trackhat").transform;
                    dk2Trackhat.parent           = this.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;
            }

            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;
            }

            CurrentHandState = HandState.Idle;
        }
示例#7
0
        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;
            Rigidbody.maxAngularVelocity = float.MaxValue;
            Rigidbody.useGravity = false;

            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 if (RenderModelInitialized == false)
            {
                RenderModelInitialized = true;
                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);
                }

                if (Colliders != null)
                {
                    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);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }