基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
40
Assets/Modern UI Pack/Scripts/Progress Bar/PBFilled.cs
Normal file
40
Assets/Modern UI Pack/Scripts/Progress Bar/PBFilled.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class PBFilled : MonoBehaviour
|
||||
{
|
||||
[Header("Resources")]
|
||||
public TextMeshProUGUI minLabel;
|
||||
public TextMeshProUGUI maxLabel;
|
||||
|
||||
[Header("Settings")]
|
||||
[Range(0, 100)] public int transitionAfter = 50;
|
||||
public Color minColor = new Color(0, 0, 0, 255);
|
||||
public Color maxColor = new Color(255, 255, 255, 255);
|
||||
|
||||
ProgressBar progressBar;
|
||||
Animator barAnimatior;
|
||||
|
||||
void Start()
|
||||
{
|
||||
progressBar = gameObject.GetComponent<ProgressBar>();
|
||||
barAnimatior = gameObject.GetComponent<Animator>();
|
||||
|
||||
minLabel.color = minColor;
|
||||
maxLabel.color = maxColor;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (progressBar.currentPercent >= transitionAfter)
|
||||
barAnimatior.Play("Radial PB Filled");
|
||||
|
||||
if (progressBar.currentPercent <= transitionAfter)
|
||||
barAnimatior.Play("Radial PB Empty");
|
||||
|
||||
maxLabel.text = minLabel.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Progress Bar/PBFilled.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Progress Bar/PBFilled.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b3d601986abab74cb6b3901c4bb2508
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: be8d03bb95afe0641976d654781e9e44, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Progress Bar/PBFilled.cs
|
||||
uploadId: 628721
|
||||
109
Assets/Modern UI Pack/Scripts/Progress Bar/ProgressBar.cs
Normal file
109
Assets/Modern UI Pack/Scripts/Progress Bar/ProgressBar.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class ProgressBar : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public float currentPercent;
|
||||
[Range(0, 100)] public int speed;
|
||||
public float minValue = 0;
|
||||
public float maxValue = 100;
|
||||
public float valueLimit = 100;
|
||||
|
||||
// Resources
|
||||
public Image loadingBar;
|
||||
public TextMeshProUGUI textPercent;
|
||||
|
||||
// Settings
|
||||
public bool isOn;
|
||||
public bool restart;
|
||||
public bool invert;
|
||||
public bool addPrefix;
|
||||
public bool addSuffix = true;
|
||||
public string prefix = "";
|
||||
public string suffix = "%";
|
||||
public bool isLooped = false;
|
||||
[Range(0, 5)] public int decimals = 0;
|
||||
|
||||
// Events
|
||||
[System.Serializable]
|
||||
public class ProgressBarEvent : UnityEvent<float> { }
|
||||
public ProgressBarEvent onValueChanged;
|
||||
[HideInInspector] public Slider eventSource;
|
||||
|
||||
void Start()
|
||||
{
|
||||
UpdateUI();
|
||||
InitializeEvents();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isOn)
|
||||
return;
|
||||
|
||||
if (currentPercent <= maxValue && !invert) { currentPercent += speed * Time.unscaledDeltaTime; }
|
||||
else if (currentPercent >= minValue && invert) { currentPercent -= speed * Time.unscaledDeltaTime; }
|
||||
|
||||
if (currentPercent >= maxValue && speed != 0 && restart && !invert) { currentPercent = 0; }
|
||||
else if (currentPercent <= minValue && speed != 0 && restart && invert) { currentPercent = maxValue; }
|
||||
else if (currentPercent >= maxValue && speed != 0 && !restart && !invert) { currentPercent = maxValue; }
|
||||
else if (currentPercent <= minValue && speed != 0 && !restart && invert) { currentPercent = minValue; }
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
loadingBar.fillAmount = currentPercent / maxValue;
|
||||
|
||||
if (addSuffix) { textPercent.text = currentPercent.ToString("F" + decimals) + suffix; }
|
||||
else { textPercent.text = currentPercent.ToString("F" + decimals); }
|
||||
|
||||
if (addPrefix) { textPercent.text = prefix + textPercent.text; }
|
||||
if (eventSource != null) { eventSource.value = currentPercent; }
|
||||
}
|
||||
|
||||
public void InitializeEvents()
|
||||
{
|
||||
if (Application.isPlaying && onValueChanged.GetPersistentEventCount() != 0)
|
||||
{
|
||||
if (eventSource == null) { eventSource = gameObject.AddComponent(typeof(Slider)) as Slider; }
|
||||
eventSource.transition = Selectable.Transition.None;
|
||||
eventSource.minValue = minValue;
|
||||
eventSource.maxValue = maxValue;
|
||||
eventSource.onValueChanged.AddListener(onValueChanged.Invoke);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearEvents()
|
||||
{
|
||||
eventSource.onValueChanged.RemoveAllListeners();
|
||||
}
|
||||
|
||||
// Will be replaced in future versions
|
||||
public void ChangeValue(float newValue)
|
||||
{
|
||||
currentPercent = newValue;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void SetValue(float newValue)
|
||||
{
|
||||
currentPercent = newValue;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void SetValue(float newValue, string newPrefix = null, string newSuffix = null, bool updateUI = true)
|
||||
{
|
||||
currentPercent = newValue;
|
||||
prefix = newPrefix;
|
||||
suffix = newSuffix;
|
||||
if (updateUI) { UpdateUI(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20c6dbf0102c7bc468113ccdd97dad83
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: be8d03bb95afe0641976d654781e9e44, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Progress Bar/ProgressBar.cs
|
||||
uploadId: 628721
|
||||
204
Assets/Modern UI Pack/Scripts/Progress Bar/ProgressBarEditor.cs
Normal file
204
Assets/Modern UI Pack/Scripts/Progress Bar/ProgressBarEditor.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[CustomEditor(typeof(ProgressBar))]
|
||||
public class ProgressBarEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private ProgressBar pbTarget;
|
||||
private UIManagerProgressBar tempUIM;
|
||||
private UIManagerProgressBarLoop tempFilledUIM;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
pbTarget = (ProgressBar)target;
|
||||
|
||||
try
|
||||
{
|
||||
if (pbTarget.isLooped == false) { tempUIM = pbTarget.GetComponent<UIManagerProgressBar>(); }
|
||||
else { tempFilledUIM = pbTarget.GetComponent<UIManagerProgressBarLoop>(); }
|
||||
}
|
||||
|
||||
catch { }
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
MUIPEditorHandler.DrawComponentHeader(customSkin, "PB 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 currentPercent = serializedObject.FindProperty("currentPercent");
|
||||
var speed = serializedObject.FindProperty("speed");
|
||||
var minValue = serializedObject.FindProperty("minValue");
|
||||
var maxValue = serializedObject.FindProperty("maxValue");
|
||||
var valueLimit = serializedObject.FindProperty("valueLimit");
|
||||
var loadingBar = serializedObject.FindProperty("loadingBar");
|
||||
var textPercent = serializedObject.FindProperty("textPercent");
|
||||
var isOn = serializedObject.FindProperty("isOn");
|
||||
var restart = serializedObject.FindProperty("restart");
|
||||
var invert = serializedObject.FindProperty("invert");
|
||||
var addPrefix = serializedObject.FindProperty("addPrefix");
|
||||
var addSuffix = serializedObject.FindProperty("addSuffix");
|
||||
var prefix = serializedObject.FindProperty("prefix");
|
||||
var suffix = serializedObject.FindProperty("suffix");
|
||||
var decimals = serializedObject.FindProperty("decimals");
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Percent"), customSkin.FindStyle("Text"), GUILayout.Width(100));
|
||||
pbTarget.currentPercent = EditorGUILayout.Slider(pbTarget.currentPercent, minValue.floatValue, maxValue.floatValue);
|
||||
currentPercent.floatValue = pbTarget.currentPercent;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (pbTarget.loadingBar != null && pbTarget.textPercent != null) { pbTarget.UpdateUI(); }
|
||||
else
|
||||
{
|
||||
if (pbTarget.loadingBar == null || pbTarget.textPercent == null)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox("One or more resources needs to be assigned.", MessageType.Error);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Min / Max Value"), customSkin.FindStyle("Text"), GUILayout.Width(110));
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
minValue.floatValue = EditorGUILayout.Slider(minValue.floatValue, 0, maxValue.floatValue - 1);
|
||||
maxValue.floatValue = EditorGUILayout.Slider(maxValue.floatValue, minValue.floatValue + 1, valueLimit.floatValue);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
EditorGUILayout.HelpBox("You can increase the max value limit by changing 'Value Limit' in the settings tab.", MessageType.Info);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"));
|
||||
break;
|
||||
|
||||
case 1:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
MUIPEditorHandler.DrawProperty(loadingBar, customSkin, "Loading Bar");
|
||||
MUIPEditorHandler.DrawProperty(textPercent, customSkin, "Text Indicator");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
isOn.boolValue = MUIPEditorHandler.DrawToggle(isOn.boolValue, customSkin, "Is On");
|
||||
restart.boolValue = MUIPEditorHandler.DrawToggle(restart.boolValue, customSkin, "Restart / Loop");
|
||||
invert.boolValue = MUIPEditorHandler.DrawToggle(invert.boolValue, customSkin, "Invert");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
addPrefix.boolValue = MUIPEditorHandler.DrawTogglePlain(addPrefix.boolValue, customSkin, "Add Prefix");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (addPrefix.boolValue == true)
|
||||
MUIPEditorHandler.DrawPropertyPlainCW(prefix, customSkin, "Prefix:", 40);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
addSuffix.boolValue = MUIPEditorHandler.DrawTogglePlain(addSuffix.boolValue, customSkin, "Add Suffix");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (addSuffix.boolValue == true)
|
||||
MUIPEditorHandler.DrawPropertyPlainCW(suffix, customSkin, "Suffix:", 40);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Value Limit"), customSkin.FindStyle("Text"), GUILayout.Width(80));
|
||||
EditorGUILayout.PropertyField(valueLimit, new GUIContent(""));
|
||||
|
||||
if (valueLimit.floatValue <= minValue.floatValue) { valueLimit.floatValue = minValue.floatValue + 1; }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
MUIPEditorHandler.DrawPropertyCW(decimals, customSkin, "Decimals", 80);
|
||||
MUIPEditorHandler.DrawPropertyCW(speed, customSkin, "Speed", 80);
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "UIM Header", 10);
|
||||
|
||||
if (tempUIM != null && pbTarget.isLooped == false)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This object is connected with UI Manager. Some parameters (such as colors, " +
|
||||
"fonts or booleans) are managed by the manager.", MessageType.Info);
|
||||
|
||||
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>[Progress Bar]</b> Failed to delete UI Manager connection.", this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempFilledUIM != null && pbTarget.isLooped == true)
|
||||
{
|
||||
MUIPEditorHandler.DrawUIManagerConnectedHeader();
|
||||
|
||||
tempUIM.overrideColors = MUIPEditorHandler.DrawToggle(tempUIM.overrideColors, customSkin, "Override Colors");
|
||||
|
||||
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>[Progress Bar]</b> Failed to delete UI Manager connection.", this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempUIM == null && tempFilledUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Application.isPlaying == false) { this.Repaint(); }
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e24fda0b81feb8343abb048c3c912da3
|
||||
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/Progress Bar/ProgressBarEditor.cs
|
||||
uploadId: 628721
|
||||
Reference in New Issue
Block a user