protected override VisualAssets GetVisualAssets()
        {
            VisualAssets vizAssets = base.GetVisualAssets();

            int controllerVisualIndex = 0;

            if (ControllerInputDevice != null &&
                ControllerInputDevice.GetConfigurationType() ==
                GvrBetaControllerInput.Configuration.Is6DoF)
            {
                controllerVisualIndex = 1;
            }

            // Check that visualsAssets exists and that the visual index is within range.
            if (visualsAssets != null &&
                controllerVisualIndex < visualsAssets.Length)
            {
                vizAssets.material = visualsAssets[controllerVisualIndex].material;
                vizAssets.mesh     = visualsAssets[controllerVisualIndex].mesh;
            }
            return(vizAssets);
        }
Beispiel #2
0
    private void OnVisualUpdate(bool updateImmediately = false)
    {
        // Update the visual display based on the controller state
        if (readControllerState)
        {
            UpdateControllerState();
        }

        VisualAssets newAssets = GetVisualAssets();

        if (newAssets.mesh != meshFilter.sharedMesh)
        {
            meshFilter.sharedMesh = newAssets.mesh;
        }

        if (newAssets.material != controllerRenderer.sharedMaterial)
        {
            controllerRenderer.sharedMaterial = newAssets.material;
        }

        float deltaTime = Time.deltaTime;

        // If flagged to update immediately, set deltaTime to an arbitrarily large value.
        // This is particularly useful in editor, but also for resetting state quickly.
        if (updateImmediately)
        {
            deltaTime = IMMEDIATE_UPDATE_TIME;
        }

        if (displayState.clickButton)
        {
            controllerShaderData2.y = Mathf.Min(
                1, controllerShaderData2.y + (deltaTime / TOUCHPAD_CLICK_DURATION_SECONDS));
        }
        else
        {
            controllerShaderData2.y = Mathf.Max(
                0, controllerShaderData2.y - (deltaTime / TOUCHPAD_RELEASE_DURATION_SECONDS));
        }

        if (displayState.appButton)
        {
            controllerShaderData2.z = Mathf.Min(
                1, controllerShaderData2.z + (deltaTime / APP_BUTTON_ACTIVE_DURATION_SECONDS));
        }
        else
        {
            controllerShaderData2.z = Mathf.Max(
                0, controllerShaderData2.z - (deltaTime / APP_BUTTON_RELEASE_DURATION_SECONDS));
        }

        if (displayState.homeButton)
        {
            controllerShaderData2.w = Mathf.Min(
                1, controllerShaderData2.w + (deltaTime / SYSTEM_BUTTON_ACTIVE_DURATION_SECONDS));
        }
        else
        {
            controllerShaderData2.w = Mathf.Max(
                0, controllerShaderData2.w - (deltaTime / SYSTEM_BUTTON_RELEASE_DURATION_SECONDS));
        }

        // Set the material's alpha to the multiplied preferred alpha.
        controllerShaderData2.x = PreferredAlpha;
        materialPropertyBlock.SetVector(alphaId, controllerShaderData2);

        controllerShaderData.x = displayState.touchPos.x;
        controllerShaderData.y = displayState.touchPos.y;

        if (displayState.touching || displayState.clickButton)
        {
            if (!wasTouching)
            {
                wasTouching = true;
            }

            if (touchTime < 1)
            {
                touchTime = Mathf.Min(
                    touchTime + (deltaTime / TOUCHPAD_POINT_SCALE_DURATION_SECONDS), 1);
            }
        }
        else
        {
            wasTouching = false;
            if (touchTime > 0)
            {
                touchTime = Mathf.Max(
                    touchTime - (deltaTime / TOUCHPAD_POINT_SCALE_DURATION_SECONDS), 0);
            }
        }

        controllerShaderData.z = touchTime;

        UpdateBatteryIndicator();

        materialPropertyBlock.SetVector(touchId, controllerShaderData);
        materialPropertyBlock.SetColor(batteryColorId, currentBatteryColor);

        // Update the renderer
        controllerRenderer.SetPropertyBlock(materialPropertyBlock);
    }