Search Unity

Accessing Aspect Ratio

Discussion in 'Cinemachine' started by Andrew-Carvalho, May 29, 2018.

  1. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    45
    I am currently migrating my old camera code to Cinemachine (I'd prefer to be using a single system and I like a lot of what Cinemachine offers). To accomplish this I am writing my own composers/transposers to handle some special cases.

    To run some logic (setting panning bounds based on frustum size) I need to know the aspect ratio of the camera. I haven't found a good way to access this, however.

    In the source for provided composers/transposer, the CameraState.Lens struct has an Aspect property which is used, but it is marked internal. With the new package manager/assembly definitions, Cinemachine compiles to it's own dll (which is great and I am a big fan of both of the mentioned new features) which means it isn't accessible.

    My current workaround has been to abandon the package manager, grab the npm cache in appdata, and copy it into the project. I then changed the property to the following.

    Code (CSharp):
    1. public float Aspect { get; internal set; }
    Is there a more appropriate way of getting the aspect ratio is a safe, agnostic way? I don't want to have to reference the UnityEngine.Camera object as I feel that defeats the point of the virtual camera system and am sure that in some uncommon use case, that is likely to break. If not, is there an appropriate place to request the Aspect property get be made public?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Yes it's a little frustrating that it's internal.
    Your request is noted.
    It's a slightly hairy point, because the aspect is not driven by the camera the way the other lens settings are.