Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[tvOS] How to micro-control the Slider UI using Apple Remote touch panel in Unity?

Discussion in 'UGUI & TextMesh Pro' started by NGC6543, Oct 12, 2016.

  1. NGC6543

    NGC6543

    Joined:
    Jun 3, 2015
    Posts:
    228
    Hi, I'm building some apps for tvOS and have some issues regarding to Slider UI.
    On standalone or iOS, you can slightly change the Slider value using a mouse or a finger.
    But on tvOS, this must be carried out by the Apple Remote.
    And when I do that, the slider 'step' is fixed to 1/10 of slider length.

    For example, if the slider value is between -20 ~ 20,
    I can only choose -20, -16, -12, ... 12, 16, 20.

    I tried 'UnityEngine.Apple.TV.Remote.reportAbsoluteDpadValues' set to 'True' and Slider's Navigation to 'Vertical', but nothing changed.

    I also tried to wrote a customized Slider script :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityStandardAssets.CrossPlatformInput;
    4. using System.Collections;
    5.  
    6. /// <summary>
    7. /// Continuous slider for AppleTV Remote on tvOS.
    8. /// Slider value can be modified by touchpad horizontal axis
    9. /// </summary>
    10. public class ContinuousSlider : Slider {
    11.     //[Space,Space]
    12.     [Header("Debug")]
    13.     public Text debugText;
    14.     public enum SliderAxis{Horizontal, Vertical}
    15.     public SliderAxis sliderAxis;
    16.  
    17.     public override void OnMove(UnityEngine.EventSystems.AxisEventData eventData){
    18.         float v = 0;
    19.         switch(eventData.moveDir){
    20.             case UnityEngine.EventSystems.MoveDirection.Left :
    21.                 //v = Input.GetAxisRaw("Horizontal");    // Not work
    22.                 //v = CrossPlatformInputManager.GetAxis("Horizontal"); // Not work
    23.                 //v = Input.touches[0].position.x;    // Not work
    24.                 value = minValue + (maxValue - minValue) * (v + 1f)/2f;
    25.                 break;
    26.             case UnityEngine.EventSystems.MoveDirection.Right :
    27.                 //v = Input.GetAxisRaw("Horizontal");
    28.                 //v = CrossPlatformInputManager.GetAxis("Horizontal");
    29.                 //v = Input.touches[0].position.x;
    30.                 value = minValue + (maxValue - minValue) * (v + 1f)/2f;
    31.                 break;
    32.             case UnityEngine.EventSystems.MoveDirection.Up :
    33.                 base.OnMove(eventData);
    34.                 return;
    35.             case UnityEngine.EventSystems.MoveDirection.Down :
    36.                 base.OnMove(eventData);
    37.                 return;
    38.             case UnityEngine.EventSystems.MoveDirection.None :
    39.                 base.OnMove(eventData);
    40.                 return;
    41.                 default :
    42.                 return;
    43.         }
    44.         eventData.Use();
    45.     }
    46.  
    47. }
    But none of them was effective. And weird thing is, the custom Slider component doesn't expose additional variables(Text debugText, SliderAxis slideAxis) to the Inspector window.

    If the touchpad can report absolute value(-1 ~ 1), then this can be internally mapped to the Slider value(minValue ~ maxValue) by Unity, can't it?

    Or is there a better way to do this(except the InputField UI)?
     
    Last edited: Oct 12, 2016