Exemplo n.º 1
0
    private void OnCubeTest(CubeTestEvent evt)
    {
        controller.cubeCollider.gameObject.SetActive(false);
        controller.magicCube.enableCollision = true;

        Vector3 forward = AxisUtil.Axis2Direction(controller.magicCube.transform, evt.forwardAxis);
        Vector3 right = AxisUtil.Axis2Direction(controller.magicCube.transform, evt.rightAxis);
        Vector3 up = AxisUtil.Axis2Direction(controller.magicCube.transform, evt.upAxis);

        controller.cubeCollider.transform.rotation = Quaternion.LookRotation(forward, up);
        controller.cubeCollider.transform.position = evt.cube.transform.position;

        float size = controller.magicCube.step * controller.magicCube.distance * 4;
        controller.cubeCollider.size = new Vector3(size, controller.magicCube.distance * 0.5f, size);
        controller.cubeCollider.gameObject.SetActive(true);
    }
Exemplo n.º 2
0
    private void OnCubeRoll(CubeRollEvent evt)
    {
        if (this != controller.stateMachine.state
            || Vector3.zero == evt.deltaPosition)
        {
            return;
        }

        Vector3 direction = controller.camera.transform.right * evt.deltaPosition.x + controller.camera.transform.up * evt.deltaPosition.y;
        Vector3 forward = controller.camera.transform.forward;
        AxisType rightAxis, upAxis, forwardAxis;
        AxisUtil.GetRollAxis(controller.magicCube.transform, direction, forward, out rightAxis, out upAxis, out forwardAxis);

        controller.rollAxis = upAxis;

        bool isHorizontal = Mathf.Abs(evt.deltaPosition.x) > Mathf.Abs(evt.deltaPosition.y);
        if (isHorizontal)
        {
            float dot = Vector3.Dot(controller.camera.transform.up, AxisUtil.Axis2Direction(controller.magicCube.transform, upAxis));
            controller.rollAngle = evt.deltaPosition.x * dot > 0 ? -90 : 90;
        }
        else
        {
            float dot = Vector3.Dot(controller.camera.transform.right, AxisUtil.Axis2Direction(controller.magicCube.transform, upAxis));
            controller.rollAngle = evt.deltaPosition.y * dot > 0 ? 90 : -90;
        }

        controller.stateMachine.Enter<TestState>();

        CubeTestEvent cubeTestEvent = new CubeTestEvent();
        cubeTestEvent.cube = evt.cube;
        cubeTestEvent.rightAxis = rightAxis;
        cubeTestEvent.upAxis = upAxis;
        cubeTestEvent.forwardAxis = forwardAxis;
        EventSystem<CubeTestEvent>.Broadcast(cubeTestEvent);
    }