Search Unity

Camera Fit: Screen Handler

Discussion in 'Assets and Asset Store' started by DominoOne, Mar 22, 2016.

  1. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    I'm running current Unity, 2018.3.6 on Mac OS. I get the window stretching too but it wasn't being a problem. I'll see what I can do about the screen recording.
     
  2. mcolombo

    mcolombo

    Joined:
    Sep 27, 2017
    Posts:
    16
    Hi DominoOne,

    Sorry if you already answered this, but i got confused with all the questions.
    I THINK your plug in might be what i want, but i am not sure.

    I have a basic point and click game, with some UI elements on it. I use a 16:9 base ratio.
    My problem appears when i try, for example, a 21:9 ratio . The game stays centered, but the UI elements align to the screen new borders, where the extra black screen is.
    I attach an image, check the briefcase in the top right corner, or the text in the bottom left. Or even the clouds ar going through the black area.
    I would like to everything be located using the main game frame as reference.
    Does your plug in resolves that?

    Thanks!

    Screen-Shot-2019-03-12-at-3.48.55-PM.jpg
     
  3. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    What I'd suggest for you to do is this:
    1. Don't use screen space UI (neither overlay, nor camera based). Use a world space canvas, make an additional ortho camera that renders the UI and then use our script on that camera.
    2. Our script doesn't create the black area around the main view (because you might actually want the camera to see that area). Instead, you should create some black quads or something around the main area, so that when the camera uncovers those areas (either sides or top/bottom), you don't see the art there.

    Does that help?

    By the way, nice art! What's the game called? We're making a PnC adventure too, so it would be nice to follow yours :)
     
  4. mcolombo

    mcolombo

    Joined:
    Sep 27, 2017
    Posts:
    16
    Hey Domingo!

    Thanks for your reply. I don't think it will be useful for us than.

    The game is coming to Steam un July!
     
  5. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Could you specify why you think so, though? We're always willing to improve, so knowing what people actually need helps :)
     
  6. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    I was wondering, can this script also be applied to Canvas/UIs? Or is there something similar to this but for UIs? I'm looking for the dynamic option which I think is the best to use if I understood well what it does. (not a Unity user myself)

    Edit: like a modified Canvas Scaler script
     
    Last edited: Mar 15, 2019
  7. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    I had to do some experimenting to give you a full answer :) So, for UI there are a couple of options:

    1. Use the world space canvas, which is much more predictable than the screen spaces canvases. Then you can add an ortho camera, which uses the Camera Fit plugin with the Dynamic mode. Make the size of the Canvas equal to the size of the main area of the Camera Fit component (horiz and vert size multiplied by 2). If you need the elements to snap to the sides/corners of the screen, you'll need the size of the Canvas to adapt to the size of the camera view. So, whenever the aspect ratio in the game changes, dynamically set the size of the canvas equal to the camera horizontal/vertical size (just a super simple script will suffice). Something like this:
    Code (CSharp):
    1. uiCanvasRectTransform.sizeDelta = new Vector2(2f * uiCamera.orthographicSize * uiCamera.pixelWidth / (uiCanvasRectTransform.localScale.y * uiCamera.pixelHeight), 2f * uiCamera.orthographicSize / uiCanvasRectTransform.localScale.x);
    2. If you really need to use a screen space canvas, you can reproduce very similar behaviour without Camera Fit. On the Canvas Scaler, for UI Scale Mode choose "Scale with Screen Size". Then in the Reference Resolution field enter whatever you want your main area aspect ratio to be (if it's 16:9, you can enter 1600x900 or something like that). And then set the Screen Match Mode to "Expand". Don't ask me why, but this seems to do the trick :D I'm not completely sure if this could have any side effects, so I'd still highly recommend to use the world space canvas and the workflow described in 1.
     
  8. SuperMiro

    SuperMiro

    Joined:
    Nov 23, 2018
    Posts:
    53
  9. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi! Yep, so far it supports all new Unity versions :)
     
  10. URPian

    URPian

    Joined:
    Aug 13, 2012
    Posts:
    33
    @DominoOne, this plugin is a good effort to make development on unity towards being 'resolution independent'. Keep improving it as possible.

    I got the plugin yesterday and I implemented in my scene, I'm currently using Physical Camera component of the Camera system and CameraFit(CF) disables that on runtime.

    Is it possible to make CF run in collaboration with Physical Camera settings?
    As I have gotten used to the look of the physical camera and it would really help to get that look with CF's features.

    Please guide.
    thx
     
    Last edited: Jun 25, 2019
  11. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi and thanks for the good words! :) Do you mean you're using this setting: https://docs.unity3d.com/Manual/PhysicalCameras.html? If so, do you need Camera Fit at all? Wouldn't Gate Fit be enough?
     
  12. URPian

    URPian

    Joined:
    Aug 13, 2012
    Posts:
    33
    Yes. I tried with the resolution changes from iphone XR to SE and the menu disappeared below the playable area. Out of keeping the screen being in fail-safe mode, I thought to try CameraFit, ironically that is the first video result on searching for Gate Fit :)

    My concern with Gate Fit is, weather it will also take care of the UI ?
     
  13. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    I think if you use Gate Fit with the "Overscan" mode, it should be the same to our "Dynamic" safe-area mode. I don't think it will handle the UI, but neither will Camera Fit. UI is an independent system, which you should set up separately. Of course, you can use the parameters of the recalculated camera and apply them to the UI Canvas to make it "follow" the camera/screen changes (there are some posts of mine with code and/or UI setup settings in this thread), but it's not like it happens magically ;) It's just a line of code or a matter of a couple parameters on the Canvas (depending on which Canvas mode you're using), but it still needs to be done. It should work equally well with Camera Fit or Gate Fit. Since you already purchased our plugin, let me know if you need additional help with any of that :) Try scrolling through this thread and if you're still having trouble, I'm here to help you out.
     
    URPian likes this.
  14. URPian

    URPian

    Joined:
    Aug 13, 2012
    Posts:
    33
    I'm currently using UI Flexbox plugin and most elements are getting scaled properly, only some without it ,which has moving ainmations, aren't.

    I thought GateFit/CameraFit should handle that part, but I guess it will have to be hard-coded in. I saw the code you have written for it, I will try to implement it soon and see if this can still be used along with GateFit specially for UI.

    Thank you for your time.
     
    DominoOne likes this.
  15. Promyk

    Promyk

    Joined:
    Feb 15, 2017
    Posts:
    4
    Hello,

    I would like to have a specific area (main game area) always visible, and snap to the bottom of the screen for mobiles and resolutions from 1080 x 1920 to 1080 x 2520 or even for 9 : 21. The horizontal width should be 100 % visible, the height can be different and snap to the bottom (Bricks Breaker game type).

    When I switch the Unity Game tab view from: 1080 x 1920 to 1080 x 2520, the width is cut.

    Does your plugin solves this problem and is compatible with Unity 2019 ?
     
  16. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Yes, that's exactly what our plugin does! :) And it can be used for both, 2D and 3D cameras.
     
  17. deliquescator

    deliquescator

    Joined:
    Apr 30, 2016
    Posts:
    57
    I am really interested in buying your asset but I have a few questions.
    So, I have a 2D portrait down scrolling game with a Cinemachine follow camera.
    My UI is on a Screen Space canvas.
    Cinemachine only locks the Y axis so any new resolution just clips or extends the camera in the X axis which is not what I want, I would like to lock the width so that other resolutions display more or less of my game in the Y axis but show the same width of the game.
    So your asset looks like it could do it, but I am wondering if I need to change my UI to world space and whether it works with a Cinemachine camera?
    I'm running Unity 2018.3.4f

    Thanks
     
  18. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    I'm glad you're interested in our plugin! :) I think I tested it before with Cinemachine and it worked, but you'll need to change Update() to LateUpdate() in the CamerFit.cs and probably change the CameraFit script execution order to a higher value.

    If the screen space UI already works as you want it to, Camera Fit won't affect it in any way.
     
    deliquescator likes this.
  19. Promyk

    Promyk

    Joined:
    Feb 15, 2017
    Posts:
    4
    Hello,

    Thank You for your answer.

    I tried to purchase the plugin, but Asset Store displayed this:

    "Possible incompatibility with Unity 5


    This package was published using Unity 4 and contains asset types which may not upgrade cleanly to Unity 5:
    • Scripts
    While Unity will generally attempt to upgrade assets to work, problems may still occur. For more information about upgrading projects to Unity 5, please refer to the Unity 5.0 Upgrade Guide.
    For more information about the compatibility of this specific package, please contact the publisher directly."

    Could you please submit the package using at least 2019.1 Unity version ?

    Regards,
     
  20. deliquescator

    deliquescator

    Joined:
    Apr 30, 2016
    Posts:
    57
    Cool! I bought it, applied the script to my Cinemachine camera, selected the width and it worked straight away!

    Seriously, this is magic.

    Something I wanted to do since day one but with my so far limited coding abilities, haven't cracked yet. So thank you :D It literally took 30 seconds to apply and get to work.

    Hi Promyk,

    I too was thrown off by this disclaimer initially but not to worry!
    I am using Unity 2018.3.4f and it was operational after importing without an issue. No converting was required, so you should be all good!
     
  21. Promyk

    Promyk

    Joined:
    Feb 15, 2017
    Posts:
    4
    Hi,

    Thank you very much !
     
  22. Promyk

    Promyk

    Joined:
    Feb 15, 2017
    Posts:
    4
    Hi,

    Thank you for the information
     
  23. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    deliquescator, very glad to hear! :)

    Promyk, we submitted it with Unity 4 for maximum compatibility, and since the code still works with all later Unity versions, we didn't need to submit it with multiple ones. We might do so in the future, though, just for people to feel safer.
     
    deliquescator likes this.
  24. GS796

    GS796

    Joined:
    Dec 16, 2016
    Posts:
    24
    I am supporting both Landscape and Portrait on mobile. The asset works great in editor and seems to adjust live to all window stretching and switching aspect ratios as expected. But on device when switching between portrait and landscape the scene get squashed vertically when going from landscape to portrait. Is there some sort of update or refresh I need to send to the script to get it to refresh after a device orientation change?
    Thanks.
     
  25. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    That's a little strange. Can you tell me what Camera Fit settings you're using? Also, can you try making ChangeViewForCamera() public in the CameraFit script and then calling it somewhere outside of it when the orientation changes?
     
  26. jfinales90

    jfinales90

    Joined:
    Jun 15, 2018
    Posts:
    1
    Hi DominoOne,
    Can your plugin help me if I need to design my game for portrait and landscape orientations, but the screen area that I want to see are different in each orientation?
     
  27. wowcrazyguy

    wowcrazyguy

    Joined:
    Sep 24, 2018
    Posts:
    49
    Does it support the newest iPad.
     
  28. wowcrazyguy

    wowcrazyguy

    Joined:
    Sep 24, 2018
    Posts:
    49
    Also, can it adjust the UI too.
     
  29. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    If I understand correctly what your use case is, then yes, this plugin will solve it :) The usual use case is that you set a "main area" that you always want to see, no matter what the screen ratio is (wide, narrow, portrait, landscape, etc.). And then the plugin handles the camera, so that it adds visibility around that area, depending on the aspect ratio, but the "main area" is never cropped. However, if you need the "main area" to be a little different depending on the orientation, you can easily set/update it from your script whenever the orientation changes.
     
  30. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    It supports any device :) It's pretty basic, therefore, it doesn't depend on the platform. And it doesn't specifically do anything with the UI, but it's convenient to use a world space canvas and adjust it to the size of the camera, after it has been updated by Camera Fit. Or you can specifically set settings on the UI, so that it would independently adjust to the aspect ratio – there's a tip for that somewhere earlier on this thread :)
     
  31. JoseCuevasH

    JoseCuevasH

    Joined:
    Oct 2, 2017
    Posts:
    9
    Hi!

    I Recently bought your plugin but when i try to attach it to my camera object, it says that it needs to derive from Monbehaviour, can you help me? thanks! My game is a simle 2d game
     
  32. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Thanks for using it! :) Are you attaching it though "Add Component" on the Camera object?
     
  33. kosted

    kosted

    Joined:
    Mar 14, 2015
    Posts:
    104
    Hi,
    I just bought the plugin for my mobile 2D game, I use "Scale with screen size" and "Match width or Height" for my canvas.
    I added Camera Fit to my Main Camera, but when I tried to resize, nothing happened.
    How could I do please ? I want it to keep the height of my game
    How could we find a documentation ?
    One last question, instead of having black bottom like in your video, how could I replace it by image ?
    Thanks in advance.
     
    Last edited: Jul 12, 2020
  34. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    @DominoOne, I recently purchased your plugin and it is working out of the box.
    But the Vertical Snap-Top Mode doesn't work when I use it with another plugin called as Camera Perspective Editor for Tilt-Shifting the camera vertically.

    Basically the Camera Perpective Editor tool changes the tilt value in
    RenderPipelineManager.beginCameraRendering.

    Any workaround would be appreciated. Thanks.
     
  35. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    To make the Camera Fit component do anything else from Unity's default, you need to change the settings on the component itself. Either fit to width or dynamic sizing (the latter needs a resolution that will become the "main area", which is always visible). If that doesn't work, I'd love to see a video or what's happening for you in Unity :)
     
  36. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Try renaming the Update() method to LateUpdate(). If that doesn't help, you might need to put it into the script execution order list in Unity to be executed after anything else. I think one of those (or both of them) should help :)
     
  37. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Thanks. Will try that. For now, I just hacked the other plugin and passing on the result of the
    Camera.projectionMatrix into your plugin.
     
    DominoOne likes this.
  38. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Hi, So the Vertical Snap-Top Mode stops working if I add a Unity Post Processing Layer for AA on the camera. I tried your solutions regarding LateUpdate and script execution order list. But they don't seem to be helping here. Any suggestions regarding this?
     
  39. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196
    hello!
    i would like to buy your asset but i still wondering if i can put a custom picture instead the scene view outside the camera view rectangle, like cover the game scene outside with a custom graphics
     
  40. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,944
    Hi @DominoOne

    Can i use your plugin with a screen overlay + scale with screen size based ui and fit the game content between ugui header and footer?
    Capture.PNG
    Thanks
     
  41. hoyoyo80

    hoyoyo80

    Joined:
    Jan 31, 2018
    Posts:
    58
    interested to buy this. I want to force 16:9 and fixed resolution for my mobile games. Can the plugin help me on unity 2020 and cinemachine? How about the UI? Thanks

    EDIT: All is well when using ratio, but i use fixed resolution altho it is 16:9 but the game get stretch. Pls help
     
    Last edited: Oct 21, 2020
  42. sifrani

    sifrani

    Joined:
    Jun 19, 2021
    Posts:
    1
    How do i define uiCanvasRectTransform?
     
  43. tsunsun26

    tsunsun26

    Joined:
    Jun 28, 2020
    Posts:
    3
    can i ask some question u stil active answer ? @DominoOne
     
  44. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi! Yes, go ahead :)
     
  45. tsunsun26

    tsunsun26

    Joined:
    Jun 28, 2020
    Posts:
    3
    this asset work for
    this asset work with cinemachine ? and if it work how to setting
     
  46. carlo_orlito

    carlo_orlito

    Joined:
    Aug 31, 2021
    Posts:
    4
    Hi,

    @DominoOne one question.

    I wateched
    ,unfortunately in 360p because doesn't work in higher res and I didn't see clear.

    I have Unity 2020.3 15f2 and after import Camera Firt I don't have option Camera Fit in Component > Rendering.
    So I creted GameObject and Added script and disable Main Camera, and it works but I'm not sure Are all functionalities active.

    Thanks
    BR
     
  47. rahadinabak

    rahadinabak

    Joined:
    Nov 12, 2020
    Posts:
    3
    Hey,
    I am developing a 3d game for PC and building game with 2560x1440 resolution which is my native resolution.
    When I am playing with lower resolutions like 1024X768, ui elements shifting to right and not clickable when i am staying on them. Does Camera Fit asset handles this problem. can you guide me? İ am planning to buy this asset.
    thank you.
     
  48. MCorrales

    MCorrales

    Joined:
    Oct 1, 2021
    Posts:
    1
    Hi, just bought the asset after looking for an easy fix to this problem. I'm still having issues because I'm using 3 cinemachine virtual cameras that need to switch priority when an object passes through a trigger.

    When I attach the script to these cameras, they stop switching. I've tried changing the Update function to LateUpdate as suggested on another comment, but the issue persists.

    Any pointers that can help me?