Exemplo n.º 1
0
 protected void EnsureCamera(MovingEntityBase p)
 {
     if (!myCamera)           // make sure there is a camera to control!
     {
         myCamera = Camera.main;
         if (myCamera == null)
         {
             myCamera     = (new GameObject("<main camera>")).AddComponent <Camera> ();
             myCamera.tag = "MainCamera";
         }
     }
     else
     {
         cameraOffset   = camHandle.position - p.transform.position;
         cameraDistance = cameraOffset.magnitude;
     }
     if (UnityEngine.XR.XRDevice.isPresent)
     {
         camHandle = (new GameObject("<camera handle>")).transform;
         myCamera.transform.position = Vector3.zero;
         myCamera.transform.SetParent(camHandle);
     }
     else
     {
         camHandle = myCamera.transform;
     }
     UpdateCamera(p, true);
 }
Exemplo n.º 2
0
    public override void LateUpdate(MovingEntityBase me)
    {
        if (!pc.AutomaticallyFollowPositionOnPlatform && pc.gravityApplication != MovingEntity.GravityState.none)
        {
            pc.FollowPositionOnPlatform();
        }
        bool mustUpdateCamera = OrientUp() | ChangeCameraDistanceBasedOnScrollWheel();

        UpdateCamera(me, mustUpdateCamera);
    }
Exemplo n.º 3
0
    void Start()
    {
        MovingEntityBase toControl = controlling;

        controlling = null;
        if (toControl == null)
        {
            toControl = GetComponent <MovingEntityBase> ();
        }
        Control(toControl);
    }
Exemplo n.º 4
0
    public override void Start(MovingEntityBase me)
    {
        pc = me as MovingEntity;
        base.Start(me);
        // calculate current pitch based on camera
        Vector3    currentRight       = Vector3.Cross(cameraUp, camHandle.forward);
        Vector3    currentMoveForward = Vector3.Cross(currentRight, cameraUp);
        Quaternion playerIdentity     = Quaternion.LookRotation(currentMoveForward, cameraUp);

        currentPitch = Quaternion.Angle(playerIdentity, camHandle.rotation);
        pc.AutomaticallyFollowPositionOnPlatform = false;
        pc.AutomaticallyTurnToFaceLookDirection  = false;
    }
Exemplo n.º 5
0
 public override void Release(MovingEntityBase me)
 {
     if (pc == null)
     {
         Debug.LogError(pc + " strange state... camera/input controller should always have a target");
     }
     if (me != pc)
     {
         Debug.LogError(pc + " never released!");
     }
     pc.AutomaticallyFollowPositionOnPlatform = true;
     pc.AutomaticallyTurnToFaceLookDirection  = true;
     pc = null;
 }
Exemplo n.º 6
0
    public virtual Vector3 Update(MovingEntityBase me)
    {
        float   inputF = Input.GetAxis(controls.forward), inputR = Input.GetAxis(controls.right);
        Vector3 MoveDirection = default(Vector3);

        if (inputF != 0 || inputR != 0)
        {
            Transform t = myCamera.transform;
            MoveDirection = (inputR * t.right) + (inputF * t.forward);
            MoveDirection.Normalize();
        }
        else if (AutoSlowdown)
        {
            me.IsBrakeOn = true;
        }
        if (!me.AutomaticallyTurnToFaceLookDirection)
        {
            me.TurnToFace(myCamera.transform.forward, myCamera.transform.up);
        }
        return(MoveDirection);
    }
Exemplo n.º 7
0
    public override Vector3 Update(MovingEntityBase me)
    {
        float   input_forward = Input.GetAxis(controls.forward);
        float   input_right   = Input.GetAxis(controls.right);
        Vector3 MoveDirection = Vector3.zero;

        if (input_forward != 0 || input_right != 0)
        {
            Vector3 currentRight, currentMoveForward;
            if (pc.gravityApplication == MovingEntity.GravityState.useGravity)
            {
                GetMoveVectors(pc.GroundNormal /*isStableOnGround?GroundNormal:GetUpOrientation()*/, out currentMoveForward, out currentRight);
            }
            else
            {
                currentMoveForward = camHandle.forward; currentRight = camHandle.right;
            }
            MoveDirection = (currentRight * input_right) + (currentMoveForward * input_forward);
            MoveDirection.Normalize();
        }
        else if (AutoSlowdown)
        {
            me.IsBrakeOn = true;
        }
        pc.jump.SecondsToPressJump = Input.GetButton(controls.jump)?1:0;
        if (!pc.AutomaticallyTurnToFaceLookDirection)
        {
            if (pc.gravityApplication != MovingEntity.GravityState.none)
            {
                pc.UpdateFacing();
            }
            else
            {
                pc.TurnToFace(myCamera.transform.forward, myCamera.transform.up);
            }
        }
        return(MoveDirection);
    }
Exemplo n.º 8
0
 public void Control(MovingEntityBase me)
 {
     // un-control previous
     if (controlling != null)
     {
         controlling.transform.tag = "Untagged";
         inputController.Release(controlling);
     }
     // take control of current
     controlling = me;
     if (controlling.transform.tag == "Untagged" || controlling.transform.tag.Length == 0)
     {
         controlling.transform.tag = "Player";
     }
     if (controlling is MovingEntity)
     {
         if (!(inputController is GroundedInputController))
         {
             if (inputController != null)
             {
                 inputController = new GroundedInputController(inputController);
             }
             else
             {
                 inputController = new GroundedInputController();
             }
         }
     }
     else
     {
         if (inputController == null)
         {
             inputController = new BaseInputController();
         }
     }
     inputController.Start(controlling);
 }
Exemplo n.º 9
0
    public virtual void UpdateCamera(MovingEntityBase me, bool mustUpdate)
    {
        if (mouseLookMode == ControlStyle.staticCamera && !mustUpdate)
        {
            return;
        }
        bool updatingWithMouseInput = (mouseLookMode == ControlStyle.freeRotate) ||
                                      (mouseLookMode == ControlStyle.rotateWithRMB && Input.GetMouseButton(1));

        // camera rotation
        if (updatingWithMouseInput)
        {
            // get the rotations that the user input is indicating
            UpdateCameraAngles(Input.GetAxis(controls.turnHorizontal) * horizontalSensitivity, Input.GetAxis(controls.turnVertical) * verticalSensitivity);
        }
        else if (mustUpdate)
        {
            UpdateCameraAngles(0, 0);
        }
        me.LookDirection = camHandle.forward;
        Vector3 eyeFocus = CameraCenter(me.transform);
        // move the camera to be looking at the player's eyes/head, ideally with no geometry in the way
        RaycastHit rh;
        float      calculatedDistForCamera = cameraDistance;

        if (cameraWontClip && Physics.SphereCast(eyeFocus, myCamera.nearClipPlane, -camHandle.forward, out rh, cameraDistance))
        {
            calculatedDistForCamera = rh.distance;
        }
        if (calculatedDistForCamera != 0)
        {
            cameraOffset = -myCamera.transform.forward * calculatedDistForCamera;
        }
        Vector3 nextLocation = eyeFocus + ((cameraDistance > 0) ? cameraOffset : Vector3.zero);

        camHandle.position = nextLocation;
    }
Exemplo n.º 10
0
    public virtual void LateUpdate(MovingEntityBase me)
    {
        bool mustUpdateCamera = ChangeCameraDistanceBasedOnScrollWheel();

        UpdateCamera(me, mustUpdateCamera);
    }
Exemplo n.º 11
0
 public virtual void Release(MovingEntityBase me)
 {
 }
Exemplo n.º 12
0
 public virtual void Start(MovingEntityBase p)
 {
     EnsureCamera(p);
     p.AutomaticallyTurnToFaceLookDirection = false;
 }
Exemplo n.º 13
0
	public void Copy(MovingEntityBase toCopy) {
		MoveSpeed = toCopy.MoveSpeed;
		TurnSpeed = toCopy.TurnSpeed;
		Acceleration = toCopy.Acceleration;
	}