Search Unity

Resolved Poissible Bug, UI Slider radial option missing

Discussion in 'Editor & General Support' started by Ebonicus, Apr 11, 2023.

  1. Ebonicus

    Ebonicus

    Joined:
    Oct 31, 2016
    Posts:
    158
    I don't know if this is a bug or not, but I had a 2019 project with radial sliders working using the legacy UI slider, and there was an enum field to set it to radial CW or CCW.

    When imported to Unity 2020 LTS, the slider still functions as a radial slider, all perfectly, however, I cannot change it back to a horizontal/vertical bar slider. Only the enum field for direction is available.

    You can see in this screenshot that the slider is in fact a radial slider, however, there is no enum field in inspector to change it from bar to circular.

    upload_2023-4-11_8-1-44.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    I don't think the
    Slider
    ever had a radial function.

    Are you just thinking of the
    Image
    Component? It supports radial fill.

    Otherwise if you're sure you had a radial Slider, perhaps it was part of the unofficial Unity UI Extensions project?

    You can get the extensions here:

    https://github.com/Unity-UI-Extensions/com.unity.uiextensions
     
  3. Ebonicus

    Ebonicus

    Joined:
    Oct 31, 2016
    Posts:
    158
    Nope, you are correct, the radial fill is on the image and not the slider component. Thanks!
    I feel really dumb right now, it's been so long since I touched a radial slider I just completely forgot.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    You could probably look at the source for Slider and Image and roll your own pretty easily.

    https://github.com/Unity-Technologies/uGUI

    ACTUALLY... come to think about it, maybe it even exists here:

    https://github.com/Unity-UI-Extensions/com.unity.uiextensions

    If it isn't in there maybe you could use it as reference when making it yourself.

    I'll attach my "rotate Z via drag" package... GO! :)

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. // by @kurtdekker
    6. // simple example of rotating something like a dial on a safe
    7.  
    8. public class RotateZViaDrag : MonoBehaviour
    9. {
    10.     public bool RotateAroundAxis;
    11.  
    12.     Vector3 lastPosition;
    13.  
    14.     void OnMouseDown()
    15.     {
    16.         lastPosition = Input.mousePosition;
    17.     }
    18.  
    19.     void PerformLinearRotation()
    20.     {
    21.         Vector3 currPosition = Input.mousePosition;
    22.  
    23.         Vector3 difference = currPosition - lastPosition;
    24.  
    25.         lastPosition = currPosition;
    26.  
    27.         // now choose what axis to care about... this adds X and Y
    28.         float change = difference.x + difference.y;
    29.  
    30.         // and it rotates it around the Z (forward)
    31.         transform.Rotate(new Vector3(0, 0, change));
    32.     }
    33.  
    34.     void PerformCircularRotation()
    35.     {
    36.         // where is our center on screen?
    37.         Vector3 center = Camera.main.WorldToScreenPoint(transform.position);
    38.  
    39.         // angle to previous finger
    40.         float anglePrevious = Mathf.Atan2(center.x - lastPosition.x, lastPosition.y - center.y);
    41.  
    42.         Vector3 currPosition = Input.mousePosition;
    43.  
    44.         // angle to current finger
    45.         float angleNow = Mathf.Atan2(center.x - currPosition.x, currPosition.y - center.y);
    46.  
    47.         lastPosition = currPosition;
    48.  
    49.         // how different are those angles?
    50.         float angleDelta = angleNow - anglePrevious;
    51.  
    52.         // rotate by that much
    53.         transform.Rotate(new Vector3(0, 0, angleDelta * Mathf.Rad2Deg));
    54.     }
    55.  
    56.     void OnMouseDrag()
    57.     {
    58.         if (RotateAroundAxis)
    59.         {
    60.             PerformCircularRotation();
    61.         }
    62.         else
    63.         {
    64.             PerformLinearRotation();
    65.         }
    66.     }
    67. }
     

    Attached Files:

  5. Ebonicus

    Ebonicus

    Joined:
    Oct 31, 2016
    Posts:
    158
    I didn't need that. I just change the image slice option on fill bar to horizontal. But thanks.