Пример #1
0
        protected override void Start()
        {
            base.Start();

            if (Initialized == false)
            {
                StartCoroutine(DelayedCameraInit());

                Player = this.GetComponent <NVRPlayer>();

                Cursors = new RectTransform[Player.Hands.Length];
                Lasers  = new LineRenderer[Cursors.Length];

                for (int index = 0; index < Cursors.Length; index++)
                {
                    GameObject cursor = new GameObject("Cursor for " + Player.Hands[index].gameObject.name);
                    cursor.transform.parent        = this.transform;
                    cursor.transform.localPosition = Vector3.zero;
                    cursor.transform.localRotation = Quaternion.identity;

                    Canvas canvas = cursor.AddComponent <Canvas>();
                    cursor.AddComponent <CanvasRenderer>();
                    cursor.AddComponent <CanvasScaler>();
                    cursor.AddComponent <NVRUIIgnoreRaycast>();
                    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 = CursorMaterial;

                    if (LaserEnabled == true)
                    {
                        Lasers[index]                = cursor.AddComponent <LineRenderer>();
                        Lasers[index].material       = new Material(Shader.Find("Standard"));
                        Lasers[index].material.color = LaserColor;
                        NVRHelpers.LineRendererSetColor(Lasers[index], LaserColor, LaserColor);
                        NVRHelpers.LineRendererSetWidth(Lasers[index], LaserStartWidth, LaserEndWidth);
                        Lasers[index].useWorldSpace = true;
                        Lasers[index].enabled       = false;
                    }

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

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

                Initialized = true;
            }
        }
Пример #2
0
        protected override void Start()
        {
            base.Start();

            if (Initialized == false)
            {
                Player = this.GetComponent <NVRPlayer>();

                ControllerCamera = new GameObject("Controller UI Camera").AddComponent <Camera>();
                ControllerCamera.transform.parent = Player.transform;
                ControllerCamera.clearFlags       = CameraClearFlags.Nothing;
                ControllerCamera.cullingMask      = 0; // 1 << LayerMask.NameToLayer("UI");
                ControllerCamera.stereoTargetEye  = StereoTargetEyeMask.None;

                Cursors = new RectTransform[Player.Hands.Length];
                Lasers  = new LineRenderer[Cursors.Length];

                for (int index = 0; index < Cursors.Length; index++)
                {
                    GameObject cursor = new GameObject("Cursor for " + Player.Hands[index].gameObject.name);
                    cursor.transform.parent        = this.transform;
                    cursor.transform.localPosition = Vector3.zero;
                    cursor.transform.localRotation = Quaternion.identity;

                    Canvas canvas = cursor.AddComponent <Canvas>();
                    cursor.AddComponent <CanvasRenderer>();
                    cursor.AddComponent <CanvasScaler>();
                    cursor.AddComponent <NVRUIIgnoreRaycast>();
                    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 = CursorMaterial;

                    if (LaserEnabled == true)
                    {
                        Lasers[index]                = cursor.AddComponent <LineRenderer>();
                        Lasers[index].material       = new Material(Shader.Find("Standard"));
                        Lasers[index].material.color = LaserColor;
                        NVRHelpers.LineRendererSetColor(Lasers[index], LaserColor, LaserColor);
                        NVRHelpers.LineRendererSetWidth(Lasers[index], LaserStartWidth, LaserEndWidth);
                        Lasers[index].useWorldSpace = true;
                        Lasers[index].enabled       = false;
                    }

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

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

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

                Initialized = true;
            }
        }