Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to simulate finger touch control of mobile at game play mode?

Discussion in 'Scripting' started by leegod, Jun 30, 2023.

  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,321
    So I get some finger touch character movement UI control script for mobile phone from googling.

    How to test this code inside unity editor's play mode without porting or making mobile APK build file?

    Thanks.
     
  2. lonely2015

    lonely2015

    Joined:
    Aug 16, 2017
    Posts:
    17
    I go same problem.
    My solution is quit urgly that just sperate the finger logic and build apk.
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
  4. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,321
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    Bunny83 likes this.
  6. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,495
    Right. Actually doesn't the Unity Remote app still exist / work? The Unity remote is like the name suggests simply a remote control for the Unity editor. So you start the UnityRemote app on your phone, make it connect to the editor and the editor will simply stream (often a bad quality version) of your game output in the editor to your device. Inputs of the device are send to the editor. So that should enable you to use multi touch and accelerometer input inside the Unity editor. Though I barely ever used it and that was years ago. So I don't know the state of the app.

    Though for simple tests the simulator should be enough.

    Note: about 10 years ago when I worked for a games company we actually created a new apk and install it on the phone. However the usual build-and-run pipeline was way too slow as installing and uploading it through the ADB interface was way too slow. What we did instead:
    1. We build the game into a dropbox folder
    2. On the device back then I used the FileManagerHD on my tablet that had direct dropbox support.
    3. I had a shortcut (widget) to the dropbox folder on my homescreen for quick access
    4. Just tap the new apk, the filemanager downloads it over wlan in an instant and it installs within seconds
    It wasn't the perfect workflow, however certain minor changes could be tested in the editor just fine. However at some point you always have to test on your actual device, especially when we talk about testing and optimising performance. A lot has changed since then, especially the profiler got expanded quite a bit.

    So the short answer is that there's no one-size-fits-it-all solution. It depends on what you need to test. In most cases you can not simulate multi-touch input on a PC (unless that PC may have a touch screen?).
     
    spiney199 likes this.
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
  8. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,321
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Mine works... :) see above or get to debugging! The link you posted above is less than 20 SLOC but is highly dependent on UI setup... find out what's happening!

    The link above does have crazy ninja stuff like this though:

    Code (csharp):
    1. knob = transform.GetChild(0).GetComponent<Image>();
    Keep in mind that using GetComponent<T>() and its kin (in Children, in Parent, plural, etc) to try and tease out Components at runtime is definitely deep into super-duper-uber-crazy-Ninja advanced stuff.

    This sort of coding is to be avoided at all costs unless you know exactly what you are doing.

    If you run into an issue with any of these calls, start with the documentation to understand why.

    There is a clear set of extremely-well-defined conditions required for each of these calls to work, as well as definitions of what will and will not be returned.

    In the case of collections of Components, the order will NEVER be guaranteed, even if you happen to notice it is always in a particular order on your machine.

    It is ALWAYS better to go The Unity Way(tm) and make dedicated public fields and drag in the references you want.