private void FindHands()
        {
            // Lazily create the wand input module

            if (wandInputModule == null)
            {
                GameObject eventSystemObj = new GameObject("Isolated Event System");
                eventSystemObj.transform.SetParent(this.transform, false);

                eventSystemObj.gameObject.AddComponent <IsolatedEventSystem> ();

                wandInputModule = eventSystemObj.gameObject.AddComponent <WandInputModule> ();
                wandInputModule.CursorSprite   = cursorSprite;
                wandInputModule.CursorMaterial = cursorMaterial;
            }

            // Lazily create the lasers

            if (leftLaser == null)
            {
                leftLaser = CreateLaser();
            }
            if (rightLaser == null)
            {
                rightLaser = CreateLaser();
            }

            // Do Api specific binding

            if (activeBinding == null)
            {
                // No active binding, try all known bindings to see what catches on

                if (steamVrBinding.FindHands() > 0)
                {
                    // SteamVR found hands, so use SteamVR from now on
                    activeBinding = steamVrBinding;
                }
                else if (manualBinding.FindHands() > 0)
                {
                    activeBinding = manualBinding;
                }
                // other api bindings here...
            }
            else
            {
                // We have an active binding, check it again to see if it found any more hands
                activeBinding.FindHands();
            }

            if (activeBinding != null)
            {
                // We have a new binding, so hook up all the things

                wandInputModule = GameObject.FindObjectOfType(typeof(WandInputModule)) as WandInputModule;
                if (wandInputModule != null)
                {
                    wandInputModule.OnHandsDetected(this);
                }

                leftLaser.OnHandDetected(activeBinding.LeftHandIndex, activeBinding.LeftHand, wandInputModule);
                rightLaser.OnHandDetected(activeBinding.RightHandIndex, activeBinding.RightHand, wandInputModule);

                VrDebugPanel[] panels = GameObject.FindObjectsOfType(typeof(VrDebugPanel)) as VrDebugPanel[];
                foreach (VrDebugPanel panel in panels)
                {
                    panel.OnHandsDetected(this, wandInputModule.GetControllerCamera());
                }
            }
        }
Example #2
0
        private void Initialise()
        {
            if (Initialized == false)
            {
                Instance = this;

                if (cursorColours == null || cursorColours.Length != 2)
                {
                    cursorColours    = new Color[2];
                    cursorColours[0] = Color.white;
                    cursorColours[1] = Color.white;
                }

                ControllerCamera               = new GameObject("Virtual Console UI Camera").AddComponent <Camera>();
                ControllerCamera.clearFlags    = CameraClearFlags.Nothing;
                ControllerCamera.cullingMask   = 0;
                ControllerCamera.nearClipPlane = 0.01f;
#if UNITY_5_4_OR_NEWER
                ControllerCamera.stereoTargetEye = StereoTargetEyeMask.None;
#endif
                ControllerCamera.transform.SetParent(this.transform, false);

                Cursors = new RectTransform[2];                 // for left hand, right hand

                for (int index = 0; index < Cursors.Length; index++)
                {
                    GameObject cursor = new GameObject("Virtual Console Cursor " + index);
                    cursor.transform.SetParent(this.transform, false);
                    Canvas canvas = cursor.AddComponent <Canvas>();
                    cursor.AddComponent <CanvasRenderer>();
                    cursor.AddComponent <CanvasScaler>();
                    cursor.AddComponent <UiIgnoreRaycast>();
                    cursor.AddComponent <GraphicRaycaster>();

                    canvas.renderMode   = RenderMode.WorldSpace;
                    canvas.sortingOrder = 1000;                     //set to be on top of everything

                    Image image = cursor.AddComponent <Image>();
                    image.sprite   = CursorSprite;
                    image.material = new Material(CursorMaterial);

                    if (CursorSprite == null)
                    {
                        Debug.LogWarning("Set CursorSprite on " + this.gameObject.name + " to the sprite you want to use as your cursor.", this.gameObject);
                    }

                    image.material.SetColor("_Color", cursorColours[index]);

                    Cursors[index] = cursor.GetComponent <RectTransform>();
                }

                CurrentPoint           = new GameObject[Cursors.Length];
                CurrentPressed         = new GameObject[Cursors.Length];
                CurrentDragging        = new GameObject[Cursors.Length];
                PointEvents            = new PointerEventData[Cursors.Length];
                CurrentRaycastPosition = new Vector3[Cursors.Length];
                LastRays = new Ray[Cursors.Length];

                latchedDownEdges = new bool[Cursors.Length];
                latchedUpEdges   = new bool[Cursors.Length];

                Canvas[] canvases = GameObject.FindObjectsOfType <Canvas>();
                foreach (Canvas canvas in canvases)
                {
                    canvas.worldCamera = ControllerCamera;
                }

                Initialized = true;
            }
        }
Example #3
0
 public void OnHandDetected(int index, GameObject handObj, WandInputModule wandInputModule)
 {
     this.targetHand  = handObj;
     this.inputModule = wandInputModule;
 }