Search Unity

Toggle button keep pressed state

Discussion in 'UGUI & TextMesh Pro' started by RIAwolf, Jul 3, 2017.

  1. RIAwolf

    RIAwolf

    Joined:
    Dec 22, 2016
    Posts:
    4
    Hello forum,

    I have a problem with toggle buttons where 8 buttons are in assigned to a toggle group
    Button transition is auto generated with animation controller
    once i press the toggle button, the animation plays normally and toglling between buttons turns one on while deselecting others visually.

    Problem comes when a toggle button is selected, and i press some other random button in the scene, the toggle button leaves Highlighted state, this should happen only when toggle button is deselected or another toggle button is pressed from the same group
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    The "Highlighted" state is controlled by the event system to note that a control is in focus. So it's not a permanent state because it's controlled by user actions, like clicking on another button or control.

    Is there any reason you need the "highlighted" state or view? The toggle should remain toggled until another toggle is clicked. If you are using the highlighted colour to further enhance the view on the toggle, then I'd recommend writing a script, linked to the toggle, so that when it is on it draws your highlighted overlay.

    If you want a script like that, then log an issue proposal on the Unity UI Extensions project (link in sig) and I should be able to include it in the next update.
     
  3. RIAwolf

    RIAwolf

    Joined:
    Dec 22, 2016
    Posts:
    4
    So basically you are telling me, that the state transitions that unity generated for toggle button do not take in to account that toggle button is selected?

    I need for the toggle button to remain in any single state whether "Highlighted", "Pressed" or something custom like "Selected" until the toggle group tells the button to become deselected
     
    Last edited: Jul 3, 2017
    abustosAshara likes this.
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Is there any reason you are bound to a specific animation state of the control, rather than it's internal state (isOn -> !isOn)
    Just not seen a use case to date, wherein you need to retain the "focus" state for a group of controls so far.

    Do you actually need the "Highlighted" animation state, or are you simply after highlighting the specific control in a group?
     
  5. RIAwolf

    RIAwolf

    Joined:
    Dec 22, 2016
    Posts:
    4
    I am after efficiency, just think how much time is wasted attaching scripts to every single component that should have this functionality out of the box. Unity created state animations, but only for a button, yet they provide this option for toggle buttons too.
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Can't speak to the "out of the box" comment. Unity simply built the state animation UI components around the EventSystem, not for individual controls as far as I can tell.

    As to multiple scripts, that's fairly easy to manage with [RequireComponent] tags on child scripts and then just add the child scripts. Or rewrite the control to meet your needs.

    One thing I have always noted, is that the "out of the box" UI controls are merely templates / examples of controls that can be built. They aren't meant to be a one stop shop as there are only so many use cases they can fit.

    This is what the UI Extensions project is all about, building robust implementations of controls for reuse
     
  7. RIAwolf

    RIAwolf

    Joined:
    Dec 22, 2016
    Posts:
    4
    ~10(min for fairly easy management) x ~3(per week) x 52 (weeks in a year) = 26h.
    These things do add up, and time is money
    I made a solution that worked for me
    1) Generate Animator and controllers with unity
    2) Set Transition to None
    3) Add script to observe isOn
    4) animator.SetTrigger("...") based on isOn