基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
178
Assets/Modern UI Pack/Scripts/Slider/RadialSlider.cs
Normal file
178
Assets/Modern UI Pack/Scripts/Slider/RadialSlider.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class RadialSlider : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
private const string PREFS_UI_SAVE_NAME = "Radial";
|
||||
|
||||
// Content
|
||||
public float currentValue = 50.0f;
|
||||
|
||||
// Resources
|
||||
public Image sliderImage;
|
||||
public Transform indicatorPivot;
|
||||
public TextMeshProUGUI valueText;
|
||||
|
||||
// Settings
|
||||
public float minValue = 0;
|
||||
public float maxValue = 100;
|
||||
[Range(0, 8)] public int decimals;
|
||||
public bool isPercent;
|
||||
public StartPoint startPoint = StartPoint.Left;
|
||||
|
||||
// Saving
|
||||
public bool rememberValue;
|
||||
public string sliderTag;
|
||||
|
||||
// Events
|
||||
[System.Serializable]
|
||||
public class SliderEvent : UnityEvent<float> { }
|
||||
[SerializeField]
|
||||
public SliderEvent onValueChanged = new SliderEvent();
|
||||
public UnityEvent onPointerEnter;
|
||||
public UnityEvent onPointerExit;
|
||||
|
||||
private GraphicRaycaster graphicRaycaster;
|
||||
private RectTransform hitRectTransform;
|
||||
private bool isPointerDown;
|
||||
private float currentAngle;
|
||||
private float currentAngleOnPointerDown;
|
||||
private float valueDisplayPrecision;
|
||||
|
||||
public enum StartPoint { Left, Right, Top, Down }
|
||||
|
||||
public float SliderAngle
|
||||
{
|
||||
get { return currentAngle; }
|
||||
set { currentAngle = Mathf.Clamp(value, 0.0f, 360.0f); }
|
||||
}
|
||||
|
||||
// Slider value with applied display precision, i.e. the number of decimals to show.
|
||||
public float SliderValue
|
||||
{
|
||||
get { return (long)(SliderValueRaw * valueDisplayPrecision) / valueDisplayPrecision; }
|
||||
set { SliderValueRaw = value; }
|
||||
}
|
||||
|
||||
// Raw slider value, i.e. without any display precision applied to its value.
|
||||
public float SliderValueRaw
|
||||
{
|
||||
get { return SliderAngle / 360.0f * maxValue; }
|
||||
set { SliderAngle = value * 360.0f / maxValue; }
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
graphicRaycaster = GetComponentInParent<GraphicRaycaster>();
|
||||
|
||||
if (graphicRaycaster == null)
|
||||
Debug.LogWarning("<b>[Radial Slider]</b> Could not find GraphicRaycaster component in parent.", this);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
valueDisplayPrecision = Mathf.Pow(10, decimals);
|
||||
|
||||
if (rememberValue == true) { LoadState(); }
|
||||
else { SliderAngle = currentValue * 3.6f; }
|
||||
|
||||
SliderValue = currentValue;
|
||||
onValueChanged.Invoke(SliderValueRaw);
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
hitRectTransform = eventData.pointerCurrentRaycast.gameObject.GetComponent<RectTransform>();
|
||||
isPointerDown = true;
|
||||
currentAngleOnPointerDown = SliderAngle;
|
||||
HandleSliderMouseInput(eventData, true);
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (HasValueChanged())
|
||||
SaveState();
|
||||
|
||||
hitRectTransform = null;
|
||||
isPointerDown = false;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (currentValue >= minValue) { HandleSliderMouseInput(eventData, false); }
|
||||
else if (currentValue <= minValue) { SliderValueRaw = minValue; }
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
onPointerEnter.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
onPointerExit.Invoke();
|
||||
}
|
||||
|
||||
public void LoadState()
|
||||
{
|
||||
currentAngle = PlayerPrefs.GetFloat(sliderTag + PREFS_UI_SAVE_NAME);
|
||||
}
|
||||
|
||||
public void SaveState()
|
||||
{
|
||||
if (!rememberValue)
|
||||
return;
|
||||
|
||||
PlayerPrefs.SetFloat(sliderTag + PREFS_UI_SAVE_NAME, currentAngle);
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (SliderValueRaw >= minValue)
|
||||
{
|
||||
float normalizedAngle = SliderAngle / 360.0f;
|
||||
indicatorPivot.transform.localEulerAngles = new Vector3(180.0f, 0.0f, SliderAngle);
|
||||
sliderImage.fillAmount = normalizedAngle;
|
||||
|
||||
valueText.text = string.Format("{0}{1}", SliderValue, isPercent ? "%" : "");
|
||||
currentValue = SliderValue;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasValueChanged()
|
||||
{
|
||||
return SliderAngle != currentAngleOnPointerDown;
|
||||
}
|
||||
|
||||
private void HandleSliderMouseInput(PointerEventData eventData, bool allowValueWrap)
|
||||
{
|
||||
if (!isPointerDown)
|
||||
return;
|
||||
|
||||
Vector2 localPos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(hitRectTransform, eventData.position, eventData.pressEventCamera, out localPos);
|
||||
float newAngle = Mathf.Atan2(-localPos.y, localPos.x) * Mathf.Rad2Deg + 180f;
|
||||
|
||||
if (!allowValueWrap)
|
||||
{
|
||||
currentAngle = SliderAngle;
|
||||
bool needsClamping = Mathf.Abs(newAngle - currentAngle) >= 180;
|
||||
|
||||
if (needsClamping)
|
||||
newAngle = currentAngle < newAngle ? 0.0f : 360.0f;
|
||||
}
|
||||
|
||||
SliderAngle = newAngle;
|
||||
UpdateUI();
|
||||
|
||||
if (HasValueChanged())
|
||||
onValueChanged.Invoke(SliderValueRaw);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Slider/RadialSlider.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Slider/RadialSlider.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 803cebee00d5c504e930205383017dc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b5c20faaa6c0f514092673e609258886, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/RadialSlider.cs
|
||||
uploadId: 628721
|
||||
142
Assets/Modern UI Pack/Scripts/Slider/RadialSliderEditor.cs
Normal file
142
Assets/Modern UI Pack/Scripts/Slider/RadialSliderEditor.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[CustomEditor(typeof(RadialSlider))]
|
||||
public class RadialSliderEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private RadialSlider rsTarget;
|
||||
private UIManagerSlider tempUIM;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
rsTarget = (RadialSlider)target;
|
||||
|
||||
try { tempUIM = rsTarget.GetComponent<UIManagerSlider>(); }
|
||||
catch { }
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
MUIPEditorHandler.DrawComponentHeader(customSkin, "Slider Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = MUIPEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var currentValue = serializedObject.FindProperty("currentValue");
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
var onPointerEnter = serializedObject.FindProperty("onPointerEnter");
|
||||
var onPointerExit = serializedObject.FindProperty("onPointerExit");
|
||||
var sliderImage = serializedObject.FindProperty("sliderImage");
|
||||
var indicatorPivot = serializedObject.FindProperty("indicatorPivot");
|
||||
var valueText = serializedObject.FindProperty("valueText");
|
||||
var rememberValue = serializedObject.FindProperty("rememberValue");
|
||||
var sliderTag = serializedObject.FindProperty("sliderTag");
|
||||
var minValue = serializedObject.FindProperty("minValue");
|
||||
var maxValue = serializedObject.FindProperty("maxValue");
|
||||
var isPercent = serializedObject.FindProperty("isPercent");
|
||||
var decimals = serializedObject.FindProperty("decimals");
|
||||
var contentTransform = serializedObject.FindProperty("contentTransform");
|
||||
var startPoint = serializedObject.FindProperty("startPoint");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Value"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
currentValue.floatValue = EditorGUILayout.Slider(currentValue.floatValue, rsTarget.minValue, rsTarget.maxValue);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"), true);
|
||||
EditorGUILayout.PropertyField(onPointerEnter, new GUIContent("On Pointer Enter"), true);
|
||||
EditorGUILayout.PropertyField(onPointerExit, new GUIContent("On Pointer Exit"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
MUIPEditorHandler.DrawProperty(sliderImage, customSkin, "Slider Image");
|
||||
MUIPEditorHandler.DrawProperty(indicatorPivot, customSkin, "Indicator Pivot");
|
||||
MUIPEditorHandler.DrawProperty(valueText, customSkin, "Indicator Text");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
MUIPEditorHandler.DrawProperty(minValue, customSkin, "Min Value");
|
||||
MUIPEditorHandler.DrawProperty(maxValue, customSkin, "Max Value");
|
||||
MUIPEditorHandler.DrawProperty(decimals, customSkin, "Decimals");
|
||||
isPercent.boolValue = MUIPEditorHandler.DrawToggle(isPercent.boolValue, customSkin, "Is Percent");
|
||||
rememberValue.boolValue = MUIPEditorHandler.DrawToggle(rememberValue.boolValue, customSkin, "Save Value");
|
||||
|
||||
if (rememberValue.boolValue == true)
|
||||
{
|
||||
EditorGUI.indentLevel = 2;
|
||||
MUIPEditorHandler.DrawPropertyPlainCW(sliderTag, customSkin, "Tag:", 40);
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.Space(2);
|
||||
EditorGUILayout.HelpBox("Each slider should has its own unique tag.", MessageType.Info);
|
||||
}
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "UIM Header", 10);
|
||||
|
||||
if (tempUIM != null)
|
||||
{
|
||||
MUIPEditorHandler.DrawUIManagerConnectedHeader();
|
||||
|
||||
if (GUILayout.Button("Open UI Manager", customSkin.button))
|
||||
EditorApplication.ExecuteMenuItem("Tools/Modern UI Pack/Show UI Manager");
|
||||
|
||||
if (GUILayout.Button("Disable UI Manager Connection", customSkin.button))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Modern UI Pack", "Are you sure you want to disable UI Manager connection with the object? " +
|
||||
"This operation cannot be undone.", "Yes", "Cancel"))
|
||||
{
|
||||
try { DestroyImmediate(tempUIM); }
|
||||
catch { Debug.LogError("<b>[Pie Chart]</b> Failed to delete UI Manager connection.", this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (rsTarget.sliderImage != null && rsTarget.indicatorPivot != null && rsTarget.valueText != null)
|
||||
{
|
||||
rsTarget.SliderValueRaw = currentValue.floatValue;
|
||||
float normalizedAngle = rsTarget.SliderAngle / 360.0f;
|
||||
rsTarget.indicatorPivot.transform.localEulerAngles = new Vector3(180.0f, 0.0f, rsTarget.SliderAngle);
|
||||
rsTarget.sliderImage.fillAmount = normalizedAngle;
|
||||
rsTarget.valueText.text = string.Format("{0}{1}", currentValue.floatValue, rsTarget.isPercent ? "%" : "");
|
||||
}
|
||||
|
||||
if (Application.isPlaying == false) { this.Repaint(); }
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b13417f09235b7c4f9e87f29093da488
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/RadialSliderEditor.cs
|
||||
uploadId: 628721
|
||||
53
Assets/Modern UI Pack/Scripts/Slider/RangeMaxSlider.cs
Normal file
53
Assets/Modern UI Pack/Scripts/Slider/RangeMaxSlider.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class RangeMaxSlider : Slider
|
||||
{
|
||||
public RangeMinSlider minSlider;
|
||||
public TextMeshProUGUI label;
|
||||
public string numberFormat;
|
||||
|
||||
public float realValue;
|
||||
private bool assignedRealValue = false;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
realValue = maxValue;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected override void Set(float input, bool sendCallback)
|
||||
{
|
||||
if (minSlider == null)
|
||||
minSlider = transform.parent.Find("Min Slider").GetComponent<RangeMinSlider>();
|
||||
|
||||
if (!assignedRealValue)
|
||||
{
|
||||
realValue = maxValue;
|
||||
assignedRealValue = true;
|
||||
}
|
||||
|
||||
else
|
||||
realValue = maxValue - input + minValue;
|
||||
|
||||
if (wholeNumbers == true)
|
||||
realValue = Mathf.Round(realValue);
|
||||
|
||||
if (realValue <= minSlider.value)
|
||||
return;
|
||||
|
||||
if (label != null)
|
||||
label.text = realValue.ToString(numberFormat);
|
||||
|
||||
base.Set(input, sendCallback);
|
||||
}
|
||||
|
||||
public void Refresh(float input)
|
||||
{
|
||||
Set(input, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Slider/RangeMaxSlider.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Slider/RangeMaxSlider.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 323287a52e0836642bb7e541f4ed6416
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b5c20faaa6c0f514092673e609258886, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/RangeMaxSlider.cs
|
||||
uploadId: 628721
|
||||
38
Assets/Modern UI Pack/Scripts/Slider/RangeMinSlider.cs
Normal file
38
Assets/Modern UI Pack/Scripts/Slider/RangeMinSlider.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class RangeMinSlider : Slider
|
||||
{
|
||||
[Header("RESOURCES")]
|
||||
public RangeMaxSlider maxSlider;
|
||||
public TextMeshProUGUI label;
|
||||
public string numberFormat;
|
||||
|
||||
protected override void Set(float input, bool sendCallback)
|
||||
{
|
||||
if (maxSlider == null)
|
||||
maxSlider = transform.parent.Find("Max Slider").GetComponent<RangeMaxSlider>();
|
||||
|
||||
float newValue = input;
|
||||
|
||||
if (wholeNumbers == true)
|
||||
newValue = Mathf.Round(newValue);
|
||||
|
||||
if (newValue >= maxSlider.realValue && maxSlider.realValue != maxSlider.minValue)
|
||||
return;
|
||||
|
||||
if (label != null)
|
||||
label.text = newValue.ToString(numberFormat);
|
||||
|
||||
base.Set(input, sendCallback);
|
||||
}
|
||||
|
||||
public void Refresh(float input)
|
||||
{
|
||||
Set(input, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Slider/RangeMinSlider.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Slider/RangeMinSlider.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bec9b7e800825ee4bb3c622d02a73364
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b5c20faaa6c0f514092673e609258886, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/RangeMinSlider.cs
|
||||
uploadId: 628721
|
||||
68
Assets/Modern UI Pack/Scripts/Slider/RangeSlider.cs
Normal file
68
Assets/Modern UI Pack/Scripts/Slider/RangeSlider.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class RangeSlider : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[Range(0,2)] public int decimalPlaces = 0;
|
||||
public float minValue = 0;
|
||||
public float maxValue = 1;
|
||||
public bool showLabels = true;
|
||||
public bool useWholeNumbers = true;
|
||||
|
||||
[Header("Min Slider")]
|
||||
public RangeMinSlider minSlider;
|
||||
public TextMeshProUGUI minSliderLabel;
|
||||
|
||||
[Header("Max Slider")]
|
||||
public RangeMaxSlider maxSlider;
|
||||
public TextMeshProUGUI maxSliderLabel;
|
||||
|
||||
public float CurrentLowerValue { get { return minSlider.value; } }
|
||||
public float CurrentUpperValue { get { return maxSlider.realValue; } }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (minSlider == null || maxSlider == null)
|
||||
return;
|
||||
|
||||
if (showLabels == true)
|
||||
{
|
||||
minSlider.label = minSliderLabel;
|
||||
minSlider.numberFormat = "n" + decimalPlaces;
|
||||
maxSlider.label = maxSliderLabel;
|
||||
maxSlider.numberFormat = "n" + decimalPlaces;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
minSliderLabel.gameObject.SetActive(false);
|
||||
maxSliderLabel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (useWholeNumbers == true)
|
||||
{
|
||||
minSlider.wholeNumbers = true;
|
||||
maxSlider.wholeNumbers = true;
|
||||
}
|
||||
|
||||
minSlider.minValue = minValue;
|
||||
minSlider.maxValue = maxValue;
|
||||
minSlider.onValueChanged.AddListener(CheckForMinState);
|
||||
|
||||
maxSlider.minValue = minValue;
|
||||
maxSlider.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public void CheckForMinState(float value)
|
||||
{
|
||||
if (minSlider.value >= maxSlider.realValue)
|
||||
{
|
||||
maxSlider.realValue = minSlider.value;
|
||||
minSlider.value = maxSlider.realValue - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Slider/RangeSlider.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Slider/RangeSlider.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09bc67870d6e747c79794142c4f06f22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b5c20faaa6c0f514092673e609258886, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/RangeSlider.cs
|
||||
uploadId: 628721
|
||||
59
Assets/Modern UI Pack/Scripts/Slider/SliderInput.cs
Normal file
59
Assets/Modern UI Pack/Scripts/Slider/SliderInput.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[RequireComponent(typeof(CustomInputField))]
|
||||
public class SliderInput : MonoBehaviour
|
||||
{
|
||||
[Header("Resources")]
|
||||
[SerializeField] private SliderManager sliderManager;
|
||||
private CustomInputField muipField;
|
||||
private TMP_InputField inputField;
|
||||
|
||||
[Header("Settings")]
|
||||
[Range(1, 10)] public int maxChar = 5;
|
||||
[Range(0, 4)] public int decimals = 1;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
muipField = GetComponent<CustomInputField>();
|
||||
inputField = muipField.inputText;
|
||||
|
||||
if (sliderManager == null)
|
||||
{
|
||||
Debug.LogWarning("'Slider Manager' is missing!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sliderManager.mainSlider.wholeNumbers == true) { inputField.contentType = TMP_InputField.ContentType.IntegerNumber; }
|
||||
else if (sliderManager.mainSlider.wholeNumbers == true) { inputField.contentType = TMP_InputField.ContentType.DecimalNumber; decimals = 0; }
|
||||
|
||||
inputField.characterLimit = maxChar;
|
||||
inputField.onDeselect.AddListener(delegate { SetText(sliderManager.mainSlider.value); });
|
||||
|
||||
muipField.processSubmit = true;
|
||||
muipField.clearOnSubmit = false;
|
||||
muipField.onSubmit.AddListener(SetValue);
|
||||
|
||||
sliderManager.mainSlider.onValueChanged.AddListener(SetText);
|
||||
sliderManager.mainSlider.onValueChanged.Invoke(sliderManager.mainSlider.value);
|
||||
}
|
||||
|
||||
void SetText(float value)
|
||||
{
|
||||
if (decimals == 0) { inputField.text = value.ToString("F0"); }
|
||||
else if (decimals == 1) { inputField.text = value.ToString("F1"); }
|
||||
else if (decimals == 2) { inputField.text = value.ToString("F2"); }
|
||||
else if (decimals == 3) { inputField.text = value.ToString("F3"); }
|
||||
else if(decimals == 4) { inputField.text = value.ToString("F4"); }
|
||||
}
|
||||
|
||||
void SetValue()
|
||||
{
|
||||
if (sliderManager.mainSlider.wholeNumbers == true) { sliderManager.mainSlider.value = int.Parse(inputField.text); }
|
||||
else { sliderManager.mainSlider.value = float.Parse(inputField.text); }
|
||||
if (float.Parse(inputField.text) > sliderManager.mainSlider.maxValue) { sliderManager.mainSlider.value = sliderManager.mainSlider.maxValue; }
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Slider/SliderInput.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Slider/SliderInput.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 092a466539ee62b49bab58774f2e4d46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/SliderInput.cs
|
||||
uploadId: 628721
|
||||
117
Assets/Modern UI Pack/Scripts/Slider/SliderManager.cs
Normal file
117
Assets/Modern UI Pack/Scripts/Slider/SliderManager.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[RequireComponent(typeof(Slider))]
|
||||
public class SliderManager : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
// Resources
|
||||
public Slider mainSlider;
|
||||
public TextMeshProUGUI valueText;
|
||||
public TextMeshProUGUI popupValueText;
|
||||
|
||||
// Saving
|
||||
public bool enableSaving = false;
|
||||
public bool invokeOnAwake = true;
|
||||
public string sliderTag = "My Slider";
|
||||
|
||||
// Settings
|
||||
public bool usePercent = false;
|
||||
public bool showValue = true;
|
||||
public bool showPopupValue = true;
|
||||
public bool useRoundValue = false;
|
||||
public float minValue;
|
||||
public float maxValue;
|
||||
|
||||
// Events
|
||||
[System.Serializable]
|
||||
public class SliderEvent : UnityEvent<float> { }
|
||||
[SerializeField]
|
||||
public SliderEvent onValueChanged = new SliderEvent();
|
||||
[Space(8)] public SliderEvent sliderEvent;
|
||||
|
||||
// Other Variables
|
||||
[HideInInspector] public Animator sliderAnimator;
|
||||
[HideInInspector] public float saveValue;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (enableSaving == true)
|
||||
{
|
||||
if (PlayerPrefs.HasKey(sliderTag + "MUIPSliderValue") == false) { saveValue = mainSlider.value; }
|
||||
else { saveValue = PlayerPrefs.GetFloat(sliderTag + "MUIPSliderValue"); }
|
||||
|
||||
mainSlider.value = saveValue;
|
||||
mainSlider.onValueChanged.AddListener(delegate
|
||||
{
|
||||
saveValue = mainSlider.value;
|
||||
PlayerPrefs.SetFloat(sliderTag + "MUIPSliderValue", saveValue);
|
||||
});
|
||||
}
|
||||
|
||||
mainSlider.onValueChanged.AddListener(delegate
|
||||
{
|
||||
sliderEvent.Invoke(mainSlider.value);
|
||||
UpdateUI();
|
||||
});
|
||||
|
||||
if (sliderAnimator == null && showPopupValue == true)
|
||||
{
|
||||
try { sliderAnimator = gameObject.GetComponent<Animator>(); }
|
||||
catch { showPopupValue = false; }
|
||||
}
|
||||
|
||||
if (invokeOnAwake == true) { sliderEvent.Invoke(mainSlider.value); }
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (useRoundValue == true)
|
||||
{
|
||||
if (usePercent == true)
|
||||
{
|
||||
if (valueText != null) { valueText.text = Mathf.Round(mainSlider.value * 1.0f).ToString() + "%"; }
|
||||
if (popupValueText != null) { popupValueText.text = Mathf.Round(mainSlider.value * 1.0f).ToString() + "%"; }
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (valueText != null) { valueText.text = Mathf.Round(mainSlider.value * 1.0f).ToString(); }
|
||||
if (popupValueText != null) { popupValueText.text = Mathf.Round(mainSlider.value * 1.0f).ToString(); }
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (usePercent == true)
|
||||
{
|
||||
if (valueText != null) { valueText.text = mainSlider.value.ToString("F1") + "%"; }
|
||||
if (popupValueText != null) { popupValueText.text = mainSlider.value.ToString("F1") + "%"; }
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (valueText != null) { valueText.text = mainSlider.value.ToString("F1"); }
|
||||
if (popupValueText != null) { popupValueText.text = mainSlider.value.ToString("F1"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (showPopupValue == true && sliderAnimator != null)
|
||||
sliderAnimator.Play("Value In");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (showPopupValue == true && sliderAnimator != null)
|
||||
sliderAnimator.Play("Value Out");
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Slider/SliderManager.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Slider/SliderManager.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ebbd33be3a73ca40aa6a4371ff9a6c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b5c20faaa6c0f514092673e609258886, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/SliderManager.cs
|
||||
uploadId: 628721
|
||||
166
Assets/Modern UI Pack/Scripts/Slider/SliderManagerEditor.cs
Normal file
166
Assets/Modern UI Pack/Scripts/Slider/SliderManagerEditor.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[CustomEditor(typeof(SliderManager))]
|
||||
public class SliderManagerEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private SliderManager sTarget;
|
||||
private UIManagerSlider tempUIM;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
sTarget = (SliderManager)target;
|
||||
|
||||
try { tempUIM = sTarget.GetComponent<UIManagerSlider>(); }
|
||||
catch { }
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
MUIPEditorHandler.DrawComponentHeader(customSkin, "Slider Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = MUIPEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var sliderEvent = serializedObject.FindProperty("sliderEvent");
|
||||
var sliderObject = serializedObject.FindProperty("mainSlider");
|
||||
var valueText = serializedObject.FindProperty("valueText");
|
||||
var popupValueText = serializedObject.FindProperty("popupValueText");
|
||||
var enableSaving = serializedObject.FindProperty("enableSaving");
|
||||
var sliderTag = serializedObject.FindProperty("sliderTag");
|
||||
var usePercent = serializedObject.FindProperty("usePercent");
|
||||
var useRoundValue = serializedObject.FindProperty("useRoundValue");
|
||||
var showValue = serializedObject.FindProperty("showValue");
|
||||
var showPopupValue = serializedObject.FindProperty("showPopupValue");
|
||||
var minValue = serializedObject.FindProperty("minValue");
|
||||
var maxValue = serializedObject.FindProperty("maxValue");
|
||||
var invokeOnAwake = serializedObject.FindProperty("invokeOnAwake");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (sTarget.mainSlider != null)
|
||||
{
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Value"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
sTarget.mainSlider.value = EditorGUILayout.Slider(sTarget.mainSlider.value, sTarget.mainSlider.minValue, sTarget.mainSlider.maxValue);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Min Value"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
|
||||
if (sTarget.mainSlider.wholeNumbers == false)
|
||||
sTarget.mainSlider.minValue = EditorGUILayout.FloatField(sTarget.mainSlider.minValue);
|
||||
else
|
||||
sTarget.mainSlider.minValue = EditorGUILayout.IntField((int)sTarget.mainSlider.minValue);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Max Value"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
|
||||
if (sTarget.mainSlider.wholeNumbers == false)
|
||||
sTarget.mainSlider.maxValue = EditorGUILayout.FloatField(sTarget.mainSlider.maxValue);
|
||||
else
|
||||
sTarget.mainSlider.maxValue = EditorGUILayout.IntField((int)sTarget.mainSlider.maxValue);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
sTarget.mainSlider.wholeNumbers = GUILayout.Toggle(sTarget.mainSlider.wholeNumbers, new GUIContent("Use Whole Numbers"), customSkin.FindStyle("Toggle"));
|
||||
sTarget.mainSlider.wholeNumbers = GUILayout.Toggle(sTarget.mainSlider.wholeNumbers, new GUIContent(""), customSkin.FindStyle("Toggle Helper"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
else
|
||||
EditorGUILayout.HelpBox("'Main Slider' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(sliderEvent, new GUIContent("On Value Changed"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
MUIPEditorHandler.DrawProperty(sliderObject, customSkin, "Slider Source");
|
||||
if (showValue.boolValue == true) { MUIPEditorHandler.DrawProperty(valueText, customSkin, "Label Text"); }
|
||||
if (showPopupValue.boolValue == true) { MUIPEditorHandler.DrawProperty(popupValueText, customSkin, "Popup Label Text"); }
|
||||
GUILayout.Space(4);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
usePercent.boolValue = MUIPEditorHandler.DrawToggle(usePercent.boolValue, customSkin, "Use Percent");
|
||||
showValue.boolValue = MUIPEditorHandler.DrawToggle(showValue.boolValue, customSkin, "Show Label");
|
||||
showPopupValue.boolValue = MUIPEditorHandler.DrawToggle(showPopupValue.boolValue, customSkin, "Show Popup Label");
|
||||
useRoundValue.boolValue = MUIPEditorHandler.DrawToggle(useRoundValue.boolValue, customSkin, "Use Round Value");
|
||||
invokeOnAwake.boolValue = MUIPEditorHandler.DrawToggle(invokeOnAwake.boolValue, customSkin, "Invoke On Awake");
|
||||
enableSaving.boolValue = MUIPEditorHandler.DrawToggle(enableSaving.boolValue, customSkin, "Save Value");
|
||||
|
||||
if (enableSaving.boolValue == true)
|
||||
{
|
||||
EditorGUI.indentLevel = 2;
|
||||
MUIPEditorHandler.DrawPropertyPlainCW(sliderTag, customSkin, "Tag:", 40);
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.Space(2);
|
||||
EditorGUILayout.HelpBox("Each slider should has its own unique tag.", MessageType.Info);
|
||||
}
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "UIM Header", 10);
|
||||
|
||||
if (tempUIM != null)
|
||||
{
|
||||
MUIPEditorHandler.DrawUIManagerConnectedHeader();
|
||||
tempUIM.overrideColors = MUIPEditorHandler.DrawToggle(tempUIM.overrideColors, customSkin, "Override Colors");
|
||||
tempUIM.overrideFonts = MUIPEditorHandler.DrawToggle(tempUIM.overrideFonts, customSkin, "Override Fonts");
|
||||
|
||||
if (GUILayout.Button("Open UI Manager", customSkin.button))
|
||||
EditorApplication.ExecuteMenuItem("Tools/Modern UI Pack/Show UI Manager");
|
||||
|
||||
if (GUILayout.Button("Disable UI Manager Connection", customSkin.button))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Modern UI Pack", "Are you sure you want to disable UI Manager connection with the object? " +
|
||||
"This operation cannot be undone.", "Yes", "Cancel"))
|
||||
{
|
||||
try { DestroyImmediate(tempUIM); }
|
||||
catch { Debug.LogError("<b>[Horizontal Selector]</b> Failed to delete UI Manager connection.", this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Application.isPlaying == false) { this.Repaint(); }
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70f5754df995225418ec38b440b4e75d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Slider/SliderManagerEditor.cs
|
||||
uploadId: 628721
|
||||
Reference in New Issue
Block a user