Ejemplo n.º 1
0
    /// <summary>
    /// Adjust to the attitude base on current setting.
    /// Editor use this method to generate preview.
    /// </summary>
    public void Adjust2AttitudeBaseOnCurrentSetting()
    {
        groundMask  = 1 << groundLayer;
        objectPos   = CalculateCurrentObjectPosition();
        scrollValue = Mathf.Clamp01(scrollValue);

        float currentGroundHigh = groundHigh;

        RaycastHit hit;
        Vector3    emitPos = objectPos;

        emitPos.y += 9999f;
        if (groundHighTest && Physics.Raycast(emitPos, -Vector3.up, out hit, Mathf.Infinity, groundMask))
        {
            currentGroundHigh = hit.point.y;
        }

        emitPos    = transform.position;
        emitPos.y += 9999f;
        if (groundHighTest && Physics.Raycast(emitPos, -Vector3.up, out hit, Mathf.Infinity, groundMask))
        {
            currentGroundHigh = Mathf.Max(currentGroundHigh, hit.point.y);
        }

        Vector3 rot = transform.eulerAngles;

        rot.x      = ISMath.WrapAngle(rot.x);
        rot.y      = ISMath.WrapAngle(rot.y);
        wantYAngle = rot.y;

        objectPos.y = scrollHigh.Evaluate(scrollValue);
        wantXAngle  = scrollXAngle.Evaluate(scrollValue);

        Quaternion targetRot = Quaternion.Euler(wantXAngle, wantYAngle, 0f);

        transform.rotation = targetRot;

        float dist = objectPos.y * Mathf.Tan((90f - wantXAngle) * Mathf.Deg2Rad);

        Vector3 cameraPosDir = targetRot * (Vector3.forward * dist);

        Vector3 cameraPos = objectPos - cameraPosDir;

        cameraPos.y = objectPos.y + currentGroundHigh;

        transform.position = cameraPos;
    }
Ejemplo n.º 2
0
    public void Start()
    {
        objectPos   = CalculateCurrentObjectPosition();
        scrollValue = Mathf.Clamp01(scrollValue);
        objectPos.y = scrollHigh.Evaluate(scrollValue);
        wantXAngle  = scrollXAngle.Evaluate(scrollValue);

        Vector3 rot = selfT.eulerAngles;

        rot.x             = ISMath.WrapAngle(rot.x);
        rot.y             = ISMath.WrapAngle(rot.y);
        wantYAngle        = rot.y;
        rot.x             = scrollXAngle.Evaluate(scrollValue);
        wantXAngle        = rot.x;
        selfT.eulerAngles = rot;

        StartCoroutine(UpdateTransform());

        KeyboardControl(keyBoardControl);
        ScreenEdgeMovementControl(screenEdgeMovementControl);
        MouseDragControl(mouseDragControl);
        MouseScrollControl(mouseScrollControl);
        TouchControl(touchControl);
    }
Ejemplo n.º 3
0
 public void Rotate(float dir)
 {
     wantYAngle += dir;
     ISMath.WrapAngle(wantYAngle);
 }