Example #1
0
 /** when target is null, this mode is activated*/
 protected void WaitMode()
 {
     if (target != null)
     {
         SetMode = CameraModeNames.RPG_Camera;
     }
 }
Example #2
0
 /** */
 void OnValidate()
 {
     // watching for the Mode param
     SetMode = Mode;
     // warching on axis inversion for rts camera
     InversionX = inversionX;
     InversionY = inversionY;
 }
Example #3
0
    /**
     * camera rotation around the specified object (RPG_Camera)
     */
    protected void RPGCamera()
    {
        if (target == null)
        {
            SetMode = CameraModeNames.RPG_Camera;
            return;
        }
        else
        {
            newPosition = Vector3.Lerp(newPosition, target.position, Smoothness);
        }
        if (Input.GetMouseButton(0))
        {
            Vector3 newDeltaFingerPos = CheckTouchDistance(deltaFingerPos, Input.mousePosition, lastFingerPos, touchThreshold);
            deltaFingerPos = Vector3.Lerp(deltaFingerPos, newDeltaFingerPos, rotationSmoothness);

            //deltaFingerPos  = CheckTouchDistance(deltaFingerPos, Input.mousePosition, lastFingerPos, touchThreshold);
            fingerPathDist       += Vector3.Distance(deltaFingerPos, Vector3.zero);
            isResetFingerMoveDist = false;
        }
        else
        {
            deltaFingerPos = Vector3.Lerp(deltaFingerPos, Vector3.zero, 0.1f);
            // we need dump FingerMoveDist, but with delay. This is for check total finger dist|length of a way
            //big length of a way - that touching to a 3d world point isn't activated. See CheckTouchDistance()
            //small length of a way - is considered that it is simple a click - touch the point will execute the action.
            // Without this we saw a very faster rotation camera if make many screen touches. This need only for "touch windows"
            // With mouse no problem
            if (!isResetFingerMoveDist)
            {
                ResetFingerMoveDist();
            }
        }

        // FOR DEMO
        if (Input.GetMouseButtonUp(0))
        {
            CheckClickPoint_RTS(Input.mousePosition);
        }

        if (minDistance > maxDistance)        // from Update
        {
            minDistance = maxDistance;
        }

        // multytouch zoom. support in windows 7|vista|8|8.1(thanks unity)
        newDist -= Input.GetAxis("Mouse ScrollWheel") * zoomSensitivity;
        newDist  = Mathf.Clamp(newDist, minDistance, maxDistance);
        Distance = Mathf.Lerp(Distance, newDist, 0.1f);

        // add offset in camera position
        if (isCamOffset)
        {
            currVectCamOffset = Vector3.Lerp(currVectCamOffset, vectCamOffset, 0.1f);
        }
        else
        {
            currVectCamOffset = Vector3.Lerp(currVectCamOffset, Vector3.zero, 0.1f);
        }

        if (!followMode)
        {
            //new displacement of the finger|mouse
            xDelta = Mathf.Lerp(xDelta, xDelta + (deltaFingerPos.x) * xSpeed * SPEED_CORRECTION, Smoothness);
            yDelta = Mathf.Lerp(yDelta, yDelta - (deltaFingerPos.y) * ySpeed * SPEED_CORRECTION, Smoothness);

            yDelta = ClampAngle(yDelta, yMinLimit, yMaxLimit);

            Quaternion rotation = Quaternion.Euler(yDelta, xDelta, 0);
            //Quaternion    rotation    = Quaternion.Lerp(mainCamera.transform.rotation, Quaternion.Euler(new Vector3(yDelta, xDelta, 0)), 0.1f);
            Vector3 totalOffset = new Vector3(0.0f, 0.0f, -Distance) + currVectCamOffset * Distance;
            Vector3 position    = newPosition + rotation * totalOffset;
            // set new params
            mainCamera.transform.rotation = rotation;
            mainCamera.transform.position = position;
        }
        else         // Follow Mode On
        {
            Vector3    vect      = newPosition + currVectCamOffset * Distance;
            Quaternion rot       = Quaternion.LookRotation(vect - mainCamera.transform.position);
            Vector3    totOffset = new Vector3(0.0f, 0.0f, -Distance);

            mainCamera.transform.position = vect + rot * totOffset;
            mainCamera.transform.rotation = Quaternion.Slerp(mainCamera.transform.rotation, rot, Smoothness);
        }

        // update finger|mouse position
        lastFingerPos = Input.mousePosition;

        // reset values ingerMoveDist
        if (resetFingerMoveDistTimer > 0.0f)
        {
            resetFingerMoveDistTimer -= Time.deltaTime;
        }
        else if (isResetFingerMoveDist)
        {
            fingerPathDist        = 0.0f;
            isResetFingerMoveDist = false;
        }
    }