Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REG-2194] Improved SDK UI on mobile #362

Merged
merged 6 commits into from
Dec 2, 2024
Merged

Conversation

addisonbgross
Copy link
Contributor

@addisonbgross addisonbgross commented Nov 26, 2024

In an effort to improve our demos to potential clients building mobile games, I've made the UI a bit larger when running on a mobile device. This is definitely not a comprehensive solution, but it is a small win.

What has been done

  • We can detect when a game is running on a mobile device, or in the Unity Device Simulator
  • When on mobile or using the Unity Device Simulator:
    • Scale everything in our UI to be larger
    • Disable the edit, copy, and delete actions for Sequences
    • Hide the 'create sequence button'. Creating or editing Sequences on mobile is too cramped
  • When the Unity viewport is in a portrait orientation:
    • Scale everything in our UI to be larger

Screenshots

These were taken on my old OnePlus 7. Tested with both our Match3Example game, and the Vampire Survivors Clone I was testing out recently

Screenshot_2024-11-25-16-19-09-95_433f1a8e1986f46fa5f9eab6651a65c2
Screenshot_2024-11-25-16-12-56-27_2c16d6eb5a2ead1fd6ae640023a34bb5
Screenshot_2024-11-25-16-21-17-14_433f1a8e1986f46fa5f9eab6651a65c2

Copy link
Collaborator

@vontell vontell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment/conversation on when this should be applied - TLDR I want to make sure that portrait mode in the editor is still usable?

// </summary>
public static bool IsMobile()
{
return Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind this, but this won't solve the problem for developers making mobile games in the editor. I suppose my biggest concern is more "portrait mode" than mobile specifically (i.e. just making sure our UI is usable for vertical devices)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to assume that they're using portrait mode on mobile, but many games work in landscape mode as well.

Let's evaluate how we trigger this functionality.

You can also use the 'simulator' function in the Unity IDE to test out various tablet/phones/etc and rotate them back and forth. There are APIs for detecting said rotations and positions available.

@@ -91,6 +94,11 @@ public void Awake()

public void Start()
{
if (RGUtils.IsMobile())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In relation to the comment I make at the end of this file, I suppose what I am thinking might be if (RGUtils.IsMobile() && is in portrait mode, i.e. screen height is larger than screen width)

// </summary>
public static bool IsMobile()
{
return Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to assume that they're using portrait mode on mobile, but many games work in landscape mode as well.

Let's evaluate how we trigger this functionality.

You can also use the 'simulator' function in the Unity IDE to test out various tablet/phones/etc and rotate them back and forth. There are APIs for detecting said rotations and positions available.

{
SetMobileView();
}
else if (RGUtils.IsPortraitView())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here @addisonbgross , I think this should be an if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped a comment below that will hopefully address this comment 🤞🏻

*/
public void SetMobileView()
{
GetComponent<CanvasScaler>().referenceResolution = new Vector2(800, 600);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mobile does not imply portrait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I'm reading, since our Canvas Scaler component has its match field set to 0.5, the scaling will be the same if the viewport is 800 x 600 or 600 x 800. In practice it seems to scale the same
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i still don't understand why mobile and portrait are being tied together, they aren't related

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity regarding clarity on portrait vs mobile concerns, and since the first operation of this function is identical to that of SetPortraitView, I wonder if it may be better to instead do the following:

  1. Rename SetPortraitView() to "UpscaleUI" or something just to represent the operation of making things better.
  2. Then in this SetMobileView() function, you deactivate things

Not something I'm too worried about so this is a nit, but it could make things more clear wrt to the comments that Zack had

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vontell good call on the function rename, done 👍🏻

@RG-nAmKcAz the portrait and mobile connection is that I'm making it so that the UI is scaled to be larger in both scenarios. When running a build on mobile, scale the UI up (and change a few other small things). When running a game in Unity + the viewport is in a portrait orientation, scale the UI up.

The overall goal is just to make the UI a bit larger in situations where it becomes harder to use (eg: on a small screen). Hopefully I've made some sense

@addisonbgross
Copy link
Contributor Author

@vontell @RG-nAmKcAz, I've made some changes. Please let me know if these 'rules' make sense:

When on mobile or using the Unity Device Simulator:

  • Scale everything in our UI to be larger
  • Disable the edit, copy, and delete actions for Sequences
  • Hide the 'create sequence button'. Creating or editing Sequences on mobile is too cramped

When the Unity viewport is in a portrait orientation:

  • Scale everything in our UI to be larger

I don't think we should disable anything if the game isn't running on mobile, but is in a portrait orientation. Curious to hear what you both think

*/
public void SetMobileView()
{
GetComponent<CanvasScaler>().referenceResolution = new Vector2(800, 600);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity regarding clarity on portrait vs mobile concerns, and since the first operation of this function is identical to that of SetPortraitView, I wonder if it may be better to instead do the following:

  1. Rename SetPortraitView() to "UpscaleUI" or something just to represent the operation of making things better.
  2. Then in this SetMobileView() function, you deactivate things

Not something I'm too worried about so this is a nit, but it could make things more clear wrt to the comments that Zack had

Copy link
Collaborator

@nAmKcAz nAmKcAz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't make sense, but just merge it

Mobile does not in any way imply that my screen is in portrait layout. So having code that says.. if mobile, scale UI in a way that implies portrait wouldn't work out well

If you want to 'upscale' the UI on mobile, the code should do so in a way that explicitly maintains the current aspect ratio of the mobile device, not sets a portrait aspect ratio.

If you want to 'upscale' only when the screen layout is portrait mode, then the code should do so only when the layout is portrait mode.

@addisonbgross
Copy link
Contributor Author

@RG-nAmKcAz I see your point. I've made the scaling code more explicit, and so that it doesn't imply an incorrect aspect ratio

@addisonbgross addisonbgross merged commit dae0311 into main Dec 2, 2024
2 checks passed
@addisonbgross addisonbgross deleted the addison/reg-2194 branch December 2, 2024 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants