Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //If player is not inside a zone, camera should follow him/her/zer/zim/zoom/zibitty bob hey kids mmmmmm jell-o
        if (insideZones.Count > 0)
        {
            CameraSettings blendedCameraSettings = CameraSettings.blendSettings(insideZones, player);
            targetCamPos  = new Vector2(blendedCameraSettings.x, blendedCameraSettings.y);
            targetCamSize = blendedCameraSettings.size;

            CameraZoneSettings blendedCameraZoneSettings = CameraZoneSettings.blendSettings(insideZones);
            blendedPlayerFocus = blendedCameraZoneSettings.playerFocus;
            blendedFollowSpeed = blendedCameraZoneSettings.followSpeed;
        }
        else
        {
            targetCamPos  = new Vector2(player.transform.position.x, player.transform.position.y);
            targetCamSize = defaultSize;

            blendedPlayerFocus = defaultPlayerFocus;
            blendedFollowSpeed = defaultFollowSpeed;
        }

        //position
        transform.position = vec2To3(lastCamPos + (targetCamPos - lastCamPos) * blendedFollowSpeed);
        lastCamPos         = new Vector2(transform.position.x, transform.position.y);
        //zoom
        cam.orthographicSize = (lastCamSize + (targetCamSize - lastCamSize) * blendedFollowSpeed / 10);
        lastCamSize          = cam.orthographicSize;
    }
    //Blends the a List of CameraZones' settings and returns the composite
    public static CameraZoneSettings blendSettings(List <CameraZone> list)
    {
        CameraZoneSettings camZoneSetSum = new CameraZoneSettings();

        foreach (CameraZone zone in list)
        {
            camZoneSetSum.addTo(extractSettings(zone));
        }
        return(camZoneSetSum.divBy(list.Count));
    }
 public CameraZoneSettings addTo(CameraZoneSettings otherCamZoneSet)
 {
     playerFocus += otherCamZoneSet.playerFocus;
     followSpeed += otherCamZoneSet.followSpeed;
     return(this);
 }