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

Full Screen button alternative

Discussion in 'UGUI & TextMesh Pro' started by Voronoi, Oct 5, 2014.

  1. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    I am working on a mobile control rig and decided to start with the new 2D control rig in the Sample Assets. I like that the CrossPlatformInput control is configurable in the Editor and it just seems like a good way to organize various controllers.

    The mobile rig uses the new UI to create a Jump button. I would like to design my controller so that virtually any tap on the screen will cause a jump. So, I can simply scale the button to take up most of the screen, but now I am concerned that will create screen re-draw issues by covering the screen with a semi-transparent button image.

    I tried turning off the image, but the Event System seems to require the image, which makes sense because it is looking for Events such as 'Over' something, so it needs an image.

    My questions:

    1. Is this even a good idea? I could certainly detect any touch event using Input.GetTouches and have that cause a Jump. But, I plan to have pause/preference buttons and that can cause a conflict with simply detecting any touch
    2. Is there a way to have a Button respond outside of Input.GetTouches, so that the Jump is not triggered if the touch is over a Button? How would I approach that? Raycast, Masking?
    3. If it is a good idea to use a giant button, how can I detect an event over a large area without using an image to define the area? Or, how can I do this in a performative way that I don't run into screen re-draw issues?
     
    rakkarage likes this.
  2. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    There are several ways but the most effective would be to use a game object with a 2D collider and simply raycast to see if the touch occurred over the collider or not. that way you don't need any visible representation of the button. This should result in virtually no performance cost.
     
  3. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    Mycroft likes this.
  4. yakandco

    yakandco

    Joined:
    Dec 3, 2014
    Posts:
    90
    Hey guys, I've just been digging around and trying to learn the new event system, it does seem really great... but I've just hit this same issue that I just want to receive input events anywhere on the screen based on an arbitrary RectTransform that isn't tied to an image. The above 2d collider idea is a good hack, but it does just feel like a hack and I can see potential issues coming up like how to keep the collider always covering the screen particularly if the cameras FOV or the application window resizes.. at least using a transparent image would has a nicer ability to scale on each axis and snap to the screen dimensions.

    I was wondering if there was something like the Canvas Group or something that could allow the event system to generate events based on some kind of arbitrary RectTransform bounds or whether there's plans to add in a new component that would allow this?

    In the meantime can anyone suggest on a clean way to ensure that a 2d collider attached to a camera will always actually cover the entire screen? I guess you'd have to do something like read the cameras far frustum bounds and try and apply that to the collider?! I think I'll go with transparent image in the meantime.. but it's enough to make me think twice about using the entire system in favour of the older code driven system - but then I'm at the start of a project and worried about that being pulled within the next couple of years and having a huge transitioning task down the line. Not sure what to do.. thanks for reading!

    Jason
     
  5. yakandco

    yakandco

    Joined:
    Dec 3, 2014
    Posts:
    90
    So the fullscreen transparent image isn't working out. It's seems to be so buggy.. I'm using an 8x8 transparent image set to scale to the width and height of the canvas ie. the anchors are at each corner. I press the mouse repeatedly with and without moving the mouse and I get a bunch of events and then it just stops, after waiting a little bit it sometimes starts to work again. Very random. I don't have much in my scene or much code that would interfere. I think I might have to submit a bug report.. Im really stuck as to whats going on.

    Am I just trying to use this event system the wrong way? I'll try out the collider option next. But anyone figure out how to use it a nice way that allows for fullscreen input handling without having to resort to weird hacks? It would be nice to be able to use this system in a way that is decoupled from assets or colliders.

    Would it be possible by rolling my own input module?