Exemplo n.º 1
0
        private void DrawWireframe()
        {
            var vertices = VRTK_SDK_Bridge.GetPlayAreaVertices(playArea.gameObject);

            if (vertices == null || vertices.Length == 0)
            {
                return;
            }

            var btmRight = 4;
            var btmLeft  = 5;
            var topLeft  = 6;
            var topRight = 7;

            var btmRightVertex = vertices[btmRight] * vrtk_RoomExtender.additionalMovementMultiplier;
            var btmLeftVertex  = vertices[btmLeft] * vrtk_RoomExtender.additionalMovementMultiplier;
            var topLeftVertex  = vertices[topLeft] * vrtk_RoomExtender.additionalMovementMultiplier;
            var topRightVertex = vertices[topRight] * vrtk_RoomExtender.additionalMovementMultiplier;

            var btmOffset = new Vector3(0f, vrtk_RoomExtender.transform.localPosition.y, 0f);
            var topOffset = btmOffset + transform.TransformVector(Vector3.up * wireframeHeight);

            Gizmos.color = color;
            //bottom rectangle
            Gizmos.DrawLine(btmRightVertex + btmOffset, btmLeftVertex + btmOffset);
            Gizmos.DrawLine(topLeftVertex + btmOffset, topRightVertex + btmOffset);
            Gizmos.DrawLine(btmRightVertex + btmOffset, topRightVertex + btmOffset);
            Gizmos.DrawLine(btmLeftVertex + btmOffset, topLeftVertex + btmOffset);

            //top rectangle
            Gizmos.DrawLine(btmRightVertex + topOffset, btmLeftVertex + topOffset);
            Gizmos.DrawLine(topLeftVertex + topOffset, topRightVertex + topOffset);
            Gizmos.DrawLine(btmRightVertex + topOffset, topRightVertex + topOffset);
            Gizmos.DrawLine(btmLeftVertex + topOffset, topLeftVertex + topOffset);

            //sides
            Gizmos.DrawLine(btmRightVertex + btmOffset, btmRightVertex + topOffset);
            Gizmos.DrawLine(btmLeftVertex + btmOffset, btmLeftVertex + topOffset);
            Gizmos.DrawLine(topRightVertex + btmOffset, topRightVertex + topOffset);
            Gizmos.DrawLine(topLeftVertex + btmOffset, topLeftVertex + topOffset);
        }
Exemplo n.º 2
0
        private void InitPlayAreaCursor()
        {
            var btmRightInner = 0;
            var btmLeftInner  = 1;
            var topLeftInner  = 2;
            var topRightInner = 3;

            var btmRightOuter = 4;
            var btmLeftOuter  = 5;
            var topLeftOuter  = 6;
            var topRightOuter = 7;

            Vector3[] cursorDrawVertices = VRTK_SDK_Bridge.GetPlayAreaVertices(playArea.gameObject);

            if (playAreaCursorDimensions != Vector2.zero)
            {
                var customAreaPadding = VRTK_SDK_Bridge.GetPlayAreaBorderThickness(playArea.gameObject);

                cursorDrawVertices[btmRightOuter] = new Vector3(playAreaCursorDimensions.x / 2, 0f, (playAreaCursorDimensions.y / 2) * -1);
                cursorDrawVertices[btmLeftOuter]  = new Vector3((playAreaCursorDimensions.x / 2) * -1, 0f, (playAreaCursorDimensions.y / 2) * -1);
                cursorDrawVertices[topLeftOuter]  = new Vector3((playAreaCursorDimensions.x / 2) * -1, 0f, playAreaCursorDimensions.y / 2);
                cursorDrawVertices[topRightOuter] = new Vector3(playAreaCursorDimensions.x / 2, 0f, playAreaCursorDimensions.y / 2);

                cursorDrawVertices[btmRightInner] = cursorDrawVertices[btmRightOuter] + new Vector3(-customAreaPadding, 0f, customAreaPadding);
                cursorDrawVertices[btmLeftInner]  = cursorDrawVertices[btmLeftOuter] + new Vector3(customAreaPadding, 0f, customAreaPadding);
                cursorDrawVertices[topLeftInner]  = cursorDrawVertices[topLeftOuter] + new Vector3(customAreaPadding, 0f, -customAreaPadding);
                cursorDrawVertices[topRightInner] = cursorDrawVertices[topRightOuter] + new Vector3(-customAreaPadding, 0f, -customAreaPadding);
            }

            var width  = cursorDrawVertices[btmRightOuter].x - cursorDrawVertices[topLeftOuter].x;
            var length = cursorDrawVertices[topLeftOuter].z - cursorDrawVertices[btmRightOuter].z;
            var height = 0.01f;

            playAreaCursor      = GameObject.CreatePrimitive(PrimitiveType.Cube);
            playAreaCursor.name = string.Format("[{0}]WorldPointer_PlayAreaCursor", gameObject.name);
            Utilities.SetPlayerObject(playAreaCursor, VRTK_PlayerObject.ObjectTypes.Pointer);
            playAreaCursor.transform.parent     = null;
            playAreaCursor.transform.localScale = new Vector3(width, height, length);
            playAreaCursor.SetActive(false);

            playAreaCursor.GetComponent <Renderer>().enabled = false;

            CreateCursorCollider(playAreaCursor);

            playAreaCursor.AddComponent <Rigidbody>().isKinematic = true;

            var playAreaCursorScript = playAreaCursor.AddComponent <VRTK_PlayAreaCollider>();

            playAreaCursorScript.SetParent(gameObject);
            playAreaCursorScript.SetIgnoreTarget(ignoreTargetWithTagOrClass, targetTagOrScriptListPolicy);
            playAreaCursor.layer = LayerMask.NameToLayer("Ignore Raycast");

            var playAreaBoundaryX = playArea.transform.localScale.x / 2;
            var playAreaBoundaryZ = playArea.transform.localScale.z / 2;
            var heightOffset      = 0f;

            DrawPlayAreaCursorBoundary(0, cursorDrawVertices[btmLeftOuter].x, cursorDrawVertices[btmRightOuter].x, cursorDrawVertices[btmRightInner].z, cursorDrawVertices[btmRightOuter].z, height, new Vector3(0f, heightOffset, playAreaBoundaryZ));
            DrawPlayAreaCursorBoundary(1, cursorDrawVertices[btmLeftOuter].x, cursorDrawVertices[btmLeftInner].x, cursorDrawVertices[topLeftOuter].z, cursorDrawVertices[btmLeftOuter].z, height, new Vector3(playAreaBoundaryX, heightOffset, 0f));
            DrawPlayAreaCursorBoundary(2, cursorDrawVertices[btmLeftOuter].x, cursorDrawVertices[btmRightOuter].x, cursorDrawVertices[btmRightInner].z, cursorDrawVertices[btmRightOuter].z, height, new Vector3(0f, heightOffset, -playAreaBoundaryZ));
            DrawPlayAreaCursorBoundary(3, cursorDrawVertices[btmLeftOuter].x, cursorDrawVertices[btmLeftInner].x, cursorDrawVertices[topLeftOuter].z, cursorDrawVertices[btmLeftOuter].z, height, new Vector3(-playAreaBoundaryX, heightOffset, 0f));
        }