Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by originalNarf · Dec 04, 2012 at 02:56 AM · editorinputtouchplaymode

[Unity Editor] Emulate Touch Input - Still Asking 12/10

Edit: This question still has no answer as of 12/10 - the below response does not answer the question.

Hi, I need to create touch input(s) while in Editor to test everything before deploying to devices. Is there a way to create/emulate/spawn/* touch events using scripts?

getMouseButtonDown does not do what I want (afaik), I want to literally fake a touch input and have everything else run as normal. Ideally, I get to do this via a script, and then can use hard coded values or base it on the mouse location.

My intended purposes are in-editor testing+debugging, and automated testing.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Graham-Dunnett · Dec 04, 2012 at 02:45 PM

Here's what I'd do.

a) Write some code that runs on the device and captures all the real world touch inputs, and writes these to a file with a time stamp. Copy this file off the device and onto the host computer.

b) Wrap up the input processing logic in the game, so it knows if it is running in the editor or devices (either using Application.isEditor or platform defines (see http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html).

c) If running in the editor, read the file containing the touch inputs, and feed those into the game at the correct time.

Now you can play the game in the editor with faked, but real-world touch data.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image originalNarf · Dec 06, 2012 at 11:31 PM 0
Share

So, yes, there is a way, but you haven't told me what it is. How do I do step C? What's the code, man?

avatar image Statement · Dec 10, 2012 at 10:30 PM 2
Share

@Narfanator the solution that Graham describes here works by creating a layer around Input.touches that you would use rather than the real Input.touches. If your input code is in one place, then you can substitute your existing input code with one that is fed from file. If your Input code is scattered across a lot of places then you may want to consider refactoring that code so that you have a uniform, wrappable input class. You could also create a class that overrides the name of class Input that wraps the behaviour that you want.

This behaviour would not plug in that easily with existing Unity code that already uses the internal input system, like GUI.

avatar image originalNarf · Dec 10, 2012 at 11:46 PM 0
Share

So the answer is "No, you cannot emulate touch input, but you could try this work-around"...?

avatar image Bunny83 · Dec 11, 2012 at 12:13 AM 1
Share

Yes, that's the answer. The Input class just wraps native code from the engines core which just wraps the API of the target platform. Since a PC (usually) don't have a touch device and doesn't doesn't use the Adroid / iOS API you can't emulate touch input.

Like Statement said, create another layer of abstraction in between to wrap the touch input with your own class. There you're free to emulate what ever you want.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iPhone touch events slowdown fps?!? 2 Answers

Unity Editor Playmode Tint Change by Script 4 Answers

Detect if input is from editor or Unity remote 1 Answer

How to check if a key is down in editor script 2 Answers

Touch Input, user can touch across the screen, not wanted 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges