Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

New Device Simulator (preview)

Discussion in '2019.3 Beta' started by JC-Cimetiere, Sep 26, 2019.

  1. paul_h

    paul_h

    Joined:
    Sep 13, 2014
    Posts:
    29
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Previously, the device simulator was a package, in newer versions, it's built-in. Not sure which devices are included, but in any case, you can add your own device.

    Also, the package is/was a preview package, so you might first need to enable to option to show preview packages in the editor. It was never published via the Asset Store.
     
  3. paul_h

    paul_h

    Joined:
    Sep 13, 2014
    Posts:
    29
    Yep, i tried in the asset store because I had no idea where to find it.
    Not speaking about the simulator itself but the "Device Simulator Devices 1.0.0". It appears to be a separate asset that contains additional devices for the device simulator.
     
  4. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Right I see, then I don't know, because when I try to add com.unity.device-simulator.devices to Unity 2021.2. it says "not compatible", but also, if I look over the list it seems like all of those devices should be installed by default, but yea iPhone 13 is missing. Sorry, can't help, but I'd be interested as well to have more devices!
     
  5. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hey I've been using the device simulator on the new 2021 LTS release and I noticed that whenever I trigger an input, a macOS system sound plays. It's super annoying, is anyone else getting this?
     
  6. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    How to use DeviceSimulatorCallbacks.OnDeviceChange? Can you give me an example? I am getting an error
    "The type or namespace name 'DeviceSimulator' does not exist in the namespace 'Unity' "
     
    ageana likes this.
  7. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Device Simulator always return 1 for tapCount ? It there a way to fix it?
    How to test iOS double tap feature with it ?
     
  8. Phil_Z

    Phil_Z

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    36
    We have not heard of this issue before, but if you can consistently reproduce it, please file a bug.
     
  9. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hey thanks! I haven’t been able to repro it. But it seems like it might actually be related to the shader graph windows. If it ever occurs now, I usually find one of them is open in the background. Closing them seems to fix the problem.
    Device simulator is awesome by the way :)
     
  10. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Hi @Phil_Z , I would like to create a plugin where I can simulate OnApplicationPause and OnApplicationFocus. Please share your thoughts about how we can implement it. Thanks
     
    Last edited: Aug 9, 2022
  11. RomanBanana

    RomanBanana

    Unity Technologies

    Joined:
    Jun 23, 2015
    Posts:
    51
    Device Simulator does not support simulating OnApplicationPause and OnApplicationFocus at the moment.

    If you need to simulate these events you could try to make a new event, so that you can manually trigger it. You can invoke your new event from OnApplicationPause and OnApplicationFocus so that it works in a build. Also you can invoke this new event manually in the editor/simulator, for testing.

    It's not a great way to do it, but I can't think of anything better at the moment.
     
  12. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Thanks. But if Unity can provide these simulator APIs in future updates it would be a time saver. Please consider this feature. If we write a custom event we have to make sure we listen to it in all the classes where OnApplicationPause is written.
     
  13. NeoKuro

    NeoKuro

    Joined:
    Jan 30, 2015
    Posts:
    20
    I've been scouring the packages etc for a while now trying to find the default devices added with the device simulator.

    Basically I have the OnePlus 10 Pro, and was hoping to copy the OnePlus 7T pro as a baseline and fill in the rest.

    But I can't find them anywhere. This makes the process of adding a new device incredibly tedious, or inaccurate.

    Would it be possible to just expose the built in devices publicly? Or even create an editor where you can pre-populate from existing devices?

    All the documentation I've seen says go to preferences etc or settings but there's no simulator settings.

    Alternatively would it not be possible to bring back those windows that displayed the device information in the control? panel?
     
  14. xLeo

    xLeo

    Joined:
    Sep 21, 2010
    Posts:
    194
    @JC-Cimetiere @ScottF Is it possible to change selected Device through code?
    I think it might be very useful for taking screenshots for the stores over multiple resolutions, aspect ratios and DPIs.
     
  15. Menyus777

    Menyus777

    Joined:
    Jun 11, 2017
    Posts:
    30
    Hi!

    We upgraded from 2019 LTS to 2021 LTS. Device simulator is now built-in super cool! However, where did the system spec went? Now our designers have to google the screen resolution every time they change a device... Moreover, the input processing is extremely slow. We have a double tap logic which basically starts a coroutine which lasts for 0.4s + end of frame on the first touch which looks for another touch close to the original one. However, if you double click rapidly on the device simulator the second touch never arrives. You have to wait like 0.2 seconds to reigster the second touch. This was not an issue in 2019.4 and also not an issue when we build the game.
     
  16. Phil_Z

    Phil_Z

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    36
    Hi! That does indeed sound like a bug, and a nasty one at that. Please file a bug with repro steps and we will get on it.

    Thanks for letting us know.
     
  17. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    @Phil_Z
    Hi, when setting the orientation by script the graphics is rotated but the device in the simulator stays in the old orientation, meaning I have to change the orientation manually every time.
    Could you fix that?
     
  18. Phil_Z

    Phil_Z

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    36
    I don't think that's by design and that does sound annoying. Please file a bug. Thanks for letting us know :)

    Edit: I was incorrect thinking that this was a bug, and it's actually by design to emphasize that you have a turned off autorotation.
     
    Last edited: Nov 7, 2022
    00christian00 likes this.
  19. RomanBanana

    RomanBanana

    Unity Technologies

    Joined:
    Jun 23, 2015
    Posts:
    51
    @Phil_Z going to contradict you here, this is by design. Rotating device in the simulator window is supposed to represent physically rotating a device. If you set orientation in code and physically rotate your device to a different orientation on a real device you will get same effect - graphics will be sideways.

    I recommend enabling auto rotation in player settings or in code and then rotating device in the simulator. In this case orientation will follow the device.
     
  20. RomanBanana

    RomanBanana

    Unity Technologies

    Joined:
    Jun 23, 2015
    Posts:
    51
    For versions 2019 and 2020, you can find device files inside the package in
    Editor\SimulatorResources\DeviceAssets
    folder.

    For version 2021, devices are not publicly available, however they are the same device files found in other device simulator versions.

    For 2022 onward you can find all the device files in the
    com.unity.device-simulator.devices
    package https://docs.unity3d.com/Packages/com.unity.device-simulator.devices@1.0/manual/index.html.
     
  21. RomanBanana

    RomanBanana

    Unity Technologies

    Joined:
    Jun 23, 2015
    Posts:
    51
    Hey, the input issue that you describe sounds like a bug, could you submit a bug report for it?
     
  22. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    I agree with you, but we are developer not end user. On a real device I can rotate my hand and with auto rotation the screen will follow, what is the equivalent on Unity code? I didn't find any.
    The only way simulate a rotation by code is changing the orientation, there aren't any other API.
    Clicking on the device rotation is inconvenient when testing several times, for example my game is landscape but I wrote the sign up for portrait because it can be quite hard to fit a sign up form in new narrow mobile devices, every time I test it I need to change the orientation manually back and forth.
    It may seem not much of an issue, but it gets annoying fast, there is a reason we use hotkeys instead of buttons to speed up workflow, same issue here.
     
  23. RomanBanana

    RomanBanana

    Unity Technologies

    Joined:
    Jun 23, 2015
    Posts:
    51
    @NeoKuro @Menyus777

    If you need to see device specification inside the simulator window you could use a simulator plugin for that.

    Here is an editor script that will show some device specs:

    Code (CSharp):
    1. public class DeviceInformationPanel : DeviceSimulatorPlugin
    2. {
    3.     public override string title => "Device Information";
    4.  
    5.     private VisualElement m_Content;
    6.    
    7.     public override void OnCreate()
    8.     {
    9.         EditorApplication.update += UpdateDeviceInformation;
    10.     }
    11.  
    12.     public override void OnDestroy()
    13.     {
    14.         EditorApplication.update -= UpdateDeviceInformation;
    15.     }
    16.  
    17.     public override VisualElement OnCreateUI()
    18.     {
    19.         m_Content = new VisualElement();
    20.         return m_Content;
    21.     }
    22.    
    23.     private void UpdateDeviceInformation()
    24.     {
    25.         m_Content.Clear();
    26.         m_Content.Add(new Label($"Current resolution: {UnityEngine.Device.Screen.width} x {UnityEngine.Device.Screen.height}"));
    27.         m_Content.Add(new Label($"Current orientation: {UnityEngine.Device.Screen.orientation}"));
    28.         m_Content.Add(new Label($"Operating system: {UnityEngine.Device.SystemInfo.operatingSystem}"));
    29.     }
    30. }
    This script creates UI inside the simulator window, in the Control Panel.
     
    Menyus777 likes this.
  24. Menyus777

    Menyus777

    Joined:
    Jun 11, 2017
    Posts:
    30
    @RomanBanana
    Hi!
    Thanks for the script will definitely start using it. However, still I would recommend putting it back by default.
    Related to the bug atm I'm quite busy with a feature and don't have time to create a report with a working project. But i promise I'll report it in the near future.
     
  25. Phil_Z

    Phil_Z

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    36
    Thanks for the correction. I'll edit my post :D
     
  26. YoungDeveloper

    YoungDeveloper

    Joined:
    Jun 28, 2013
    Posts:
    65
    There is no iPhone 13 (and now newest 14) options, from package manager shows last update Version 3.0.3-preview - November 12, 2021
     
  27. PrisedRabbit

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    63
    Here is my solution
    Code (CSharp):
    1. using System;
    2. using System.Linq;
    3. using System.Reflection;
    4. using System.Threading.Tasks;
    5. using UnityEditor;
    6. using UnityEditor.DeviceSimulation;
    7. using UnityEngine;
    8.  
    9. public class AutoRotateDeviceSimulator : DeviceSimulatorPlugin
    10. {
    11.     public override string title => "Auto Rotate Device Simulator";
    12.  
    13.     private ScreenOrientation screenOrientation;
    14.     private PropertyInfo rotatingProperty;
    15.     private object simulatorInterfaceController;
    16.  
    17.     public override async void OnCreate()
    18.     {
    19.         await Task.Delay( 200 );
    20.  
    21.         var assembly = Assembly.GetAssembly( typeof( DeviceSimulator ) );
    22.         var simulatorWindowType = assembly.GetTypes().First( t => t.FullName == "UnityEditor.DeviceSimulation.SimulatorWindow" );
    23.         var window = EditorWindow.GetWindow( simulatorWindowType );
    24.      
    25.         var simulatorMainWindow = simulatorWindowType.GetField("m_Main", BindingFlags.NonPublic | BindingFlags.Instance ).GetValue(window);
    26.         simulatorInterfaceController = simulatorMainWindow.GetType().GetField("m_UserInterface", BindingFlags.NonPublic | BindingFlags.Instance ).GetValue(simulatorMainWindow);
    27.         rotatingProperty = simulatorInterfaceController.GetType().GetProperty( "Rotation", BindingFlags.NonPublic | BindingFlags.Instance );
    28.  
    29.         screenOrientation = UnityEngine.Device.Screen.orientation;
    30.          
    31.         EditorApplication.update += ObserveOrientation;
    32.     }
    33.  
    34.     public override void OnDestroy()
    35.     {
    36.         EditorApplication.update -= ObserveOrientation;
    37.     }
    38.  
    39.     private void ObserveOrientation()
    40.     {
    41.         if ( screenOrientation != UnityEngine.Device.Screen.orientation )
    42.         {
    43.             screenOrientation = UnityEngine.Device.Screen.orientation;
    44.             switch ( screenOrientation )
    45.             {
    46.                 case ScreenOrientation.Unknown:
    47.                     break;
    48.                 case ScreenOrientation.LandscapeLeft:
    49.                     SetSimulatorDeviceRotation( -90 );
    50.                     break;
    51.                 case ScreenOrientation.LandscapeRight:
    52.                     SetSimulatorDeviceRotation( 90 );
    53.                     break;
    54.                 case ScreenOrientation.Portrait:
    55.                     SetSimulatorDeviceRotation( 0 );
    56.                     break;
    57.                 case ScreenOrientation.PortraitUpsideDown:
    58.                     SetSimulatorDeviceRotation( 180 );
    59.                     break;
    60.                 default:
    61.                     throw new ArgumentOutOfRangeException();
    62.             }
    63.         }
    64.     }
    65.  
    66.     private void SetSimulatorDeviceRotation(int angle)
    67.     {
    68.         rotatingProperty.SetValue( simulatorInterfaceController, angle );
    69.     }
    70. }
     
    Last edited: Dec 19, 2022
  28. YoungDeveloper

    YoungDeveloper

    Joined:
    Jun 28, 2013
    Posts:
    65
  29. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,794
  30. YoungDeveloper

    YoungDeveloper

    Joined:
    Jun 28, 2013
    Posts:
    65
  31. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,794
  32. spider853

    spider853

    Joined:
    Feb 16, 2018
    Posts:
    42
    Can we please have the mute button in Simulator window? Missing it so much, as turning volume off from Sound Mixer is pretty annoying.
    Thanks
     
    petey likes this.
  33. mcarriere

    mcarriere

    Joined:
    Sep 14, 2012
    Posts:
    106
    Unity folks; it's quite frustrating that the iPhone 14 has been out for almost 200 days now and these devices weren't updated; especially since they have a different safe area that we need to account for. There's an argument for the Android ecosystem given the vast amount of new phones released every year, but the same argument is hard to apply to Apple's devices.

    For those looking to fill the gap, I've put together the proper device definition and overlay files that enable this to work for both devices -- iPhone 14 Pro and iPhone 14 Pro Max: https://gist.github.com/mrcarriere/049596740fb52907edf68712d2818df0

    (Also worth noting, there is a bug where the simulator will indefinitely spew errors if you have orientations defined, but don't include one for the orientation your app is setup. For instance: only defining a portrait orientation but having an app that only allows landscape orientations.)
     
    konsnos and spider853 like this.
  34. spider853

    spider853

    Joined:
    Feb 16, 2018
    Posts:
    42
    Thank you!
     
  35. DwayneKing

    DwayneKing

    Joined:
    Aug 28, 2019
    Posts:
    1
    Hey, quick question, so I know the device simulator allows you to preview your game, but how do you make the corrections so that you can export to multiple screen sizes.
     
  36. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,794
    I mean, it takes them roughly six months just to add the new devices to their enums, so 200 days to do actual work on the simulator doesn't seem that bad in comparison.
     
  37. bullettea

    bullettea

    Joined:
    Oct 24, 2019
    Posts:
    29
    Is there anyway to simulate multiple finger touches in the device simulator? It seemed there wasn't so I was trying use the mouse scroll for zooming in and shift + mouse to pan as substitutes for two-finger touch (for testing purposes), but is this even possible? Thanks.
     
  38. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    That would be a GREAT feature
     
  39. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    You can sorta do that with Unity Remote, but it's not very reliable. Maybe check it out though.
     
  40. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Hey guys, it has been asked 2 years ago by multiple users, how hard can it be to allow keyboard input?!

    @PrisedRabbit
    Thanks a lot,I'm gonna try it.