Esempio n. 1
0
        private void Start()
        {
            _actorController = Utils.InterfaceHelper.GetInterfaceComponent <IActorController>(this);

            if (_actorController == null)
            {
                Debug.LogError("No IActorController found");
                gameObject.SetActive(false);
                return;
            }

            if (_actorController.isLocalPlayer)
            {
                OnEnable();
            }

            _camera = Utils.InterfaceHelper.FindObject <ICameraBehavior>();

            if (_camera == null)
            {
                Debug.LogError("No CameraBehavior found");
                return;
            }

            if (_actorController.isLocalPlayer)
            {
                _camera.SetTarget(this.transform);
            }

            OnStart();
        }
Esempio n. 2
0
    void Start()
    {
// TODO: parameterize zoom acceleration time for all cameras

        walkCamera = new WalkCamera(walkingAccelerationTime, walkingTurnSpeed,
                                    0f, 1f, defaultHeight);

        runCamera = new WalkCamera(runningAccelerationTime, runningTurnSpeed,
                                   0f, 1f, defaultHeight);

        glideCamera = new GlideCamera(glidingAccelerationTime,
                                      glidingTurnSpeed,
                                      0f, 1f, defaultHeight);

        cameraBehavior = walkCamera;
        Height         = defaultHeight;
    }
Esempio n. 3
0
    void Update()
    {
        float dtheta = Input.GetAxisRaw("Camera Horizontal");
        float dy     = Input.GetAxisRaw("Camera Vertical");

        if (Input.GetButton("Run"))
        {
            cameraBehavior = runCamera;

            // calculate the forward directions of the camera and what it's
            // following, projected onto the xz-plane

            var camForward = Vector3.ProjectOnPlane(
                transform.rotation * Vector3.forward, Vector3.up
                );
            var followForward = Vector3.ProjectOnPlane(
                following.rotation * Vector3.forward, Vector3.up
                );

            // calculate the angle between the two forward directions
            // in order to tell the camera how to rotate toward the direction
            // of the object it's following

            dtheta = Vector3.Angle(camForward, followForward) / 180f;
            var cross = Vector3.Cross(camForward, followForward);
            if (dtheta < 0.1f)
            {
                dtheta = 0f;
            }
            else if (Vector3.Dot(cross, Vector3.up) < 0f)
            {
                dtheta = -dtheta;
            }
        }
        else
        {
            cameraBehavior = walkCamera;
        }

        cameraBehavior.Update(this, dtheta, dy);
        transform.position = following.position + this.DifferenceFromTarget();
        transform.LookAt(following);
    }
Esempio n. 4
0
 public void SetFollowWithBoundaryBehavior(Rectangle boundary, IFollowingTarget target)
 {
     _cameraBehavior = new FollowBoundaryCameraBehavior(Game, boundary, target);
 }
Esempio n. 5
0
 public Camera(Game2D game) : base(game)
 {
     _cameraBehavior = new StaticCameraBehavior(game);
     _halfSize       = new Vector2(Game.ScreenWidth, Game.ScreenHeight) * 0.5f;
 }