Search Unity

[SOLVED} Multiple EventSystem

Discussion in 'Scripting' started by eron82, Jan 15, 2018.

  1. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
  2. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
    Create 2 empty objects and add this script and a Standalone Input Model on both:
    Code (csharp):
    1. using UnityEngine.EventSystems;
    2. using UnityEngine;
    3.  
    4. public class MyEventSystem : EventSystem
    5. {
    6.  
    7. protected override void OnEnable(){
    8.         base.OnEnable ();
    9. }
    10.  
    11. protected override void Update(){
    12.     EventSystem originalCurrent = EventSystem.current;
    13.     current = this;
    14.     base.Update();
    15.     current = originalCurrent;
    16. }
    17. }
    Then add these two scripts on each button selecting one event systems:
    Code (csharp):
    1. using UnityEngine.EventSystems;
    2. using UnityEngine.UI;
    3.  
    4. public class MyButton : Button
    5. {
    6.     public EventSystem eventSystem;
    7.  
    8.     protected override void Awake()
    9.     {
    10.         base.Awake ();
    11.         eventSystem = GetComponent<MyEventSystemProvider> ().eventSystem;
    12.     }
    13.  
    14.     public override void OnPointerDown(PointerEventData eventData)
    15.     {
    16.         if (eventData.button != PointerEventData.InputButton.Left)
    17.             return;
    18.  
    19.         // Selection tracking
    20.         if (IsInteractable() && navigation.mode != Navigation.Mode.None)
    21.             eventSystem.SetSelectedGameObject(gameObject, eventData);
    22.  
    23.         base.OnPointerDown(eventData);
    24.     }
    25.  
    26.     public override void Select()
    27.     {
    28.         if (eventSystem.alreadySelecting)
    29.             return;
    30.  
    31.         eventSystem.SetSelectedGameObject(gameObject);
    32.     }
    33. }
    Code (csharp):
    1. using UnityEngine.EventSystems;
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MyEventSystemProvider : MonoBehaviour
    6. {
    7.     public EventSystem eventSystem;
    8. }
     
    Last edited: Jan 15, 2018
    astracat111 and wuzibu like this.
  3. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    271
    Hi there !
    Have you managed to make it work ? :$

    In my selection screen I haven't, but the screen was a bit more complex, there are dropdown and other stuff...
    Also I'm using InControl as an Input Manager, any suggestion ?
    :)
     
  4. raiwin

    raiwin

    Joined:
    Jun 24, 2016
    Posts:
    7
    Hi,

    I know this is marked as [SOLVED] but I'm a little confused by the opening post:

    Did this work before version unity 2017.3 or is this a solution for multiple inputs in version 2017.3?

    I'm trying this out without success, so I'm not sure if it's on my end (like most of the time) or this just simply does not work anymore...
     
  5. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    271
    Didn't work for me in 2017.3
     
  6. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
    It works in 2017.3
     
  7. douglima

    douglima

    Joined:
    Apr 26, 2017
    Posts:
    7
    It works in 2018.1. Thanks!
     
  8. SAEM2710

    SAEM2710

    Joined:
    Sep 23, 2014
    Posts:
    1
    Up !

    First, thank you for this solution, it works pretty much fine with the Unity built-in input manager.

    But when both of the event systems are selecting the same button, and then selecting an other one, both of the buttons selected are still selected by the event systems but one of the two is not highlighted anymore.
    Does anyone experienced this issue ?
    I didn't add any other scripts, only the ones mentioned above with classic buttons parented to a panel which has an horizontal layout group.
     
  9. Harvizl

    Harvizl

    Joined:
    Oct 6, 2017
    Posts:
    2
    How do you stop it from overriding the colour when both objects overlap on one button?
     
  10. corgoz

    corgoz

    Joined:
    Jun 10, 2015
    Posts:
    1
    I'm having the same issue. Has anyone found a solution?
     
unityunity