Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 93feaebba6181044899d22b5e0f2047e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,457 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using TMPro;
using UnityEngine.EventSystems;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace Michsky.MUIP
{
[ExecuteInEditMode]
public class ButtonManager : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
{
// Content
public Sprite buttonIcon;
public string buttonText = "Button";
[Range(0.1f, 10)] public float iconScale = 1;
[Range(10, 200)] public float textSize = 24;
// Auto Size
public bool autoFitContent = true;
public Padding padding;
[Range(0, 100)] public int spacing = 15;
public HorizontalLayoutGroup disabledLayout;
public HorizontalLayoutGroup normalLayout;
public HorizontalLayoutGroup highlightedLayout;
public HorizontalLayoutGroup mainLayout;
public ContentSizeFitter mainFitter;
public ContentSizeFitter targetFitter;
public RectTransform targetRect;
// Resources
public CanvasGroup normalCG;
public CanvasGroup highlightCG;
public CanvasGroup disabledCG;
public TextMeshProUGUI normalText;
public TextMeshProUGUI highlightedText;
public TextMeshProUGUI disabledText;
public Image normalImage;
public Image highlightImage;
public Image disabledImage;
public AudioSource soundSource;
public GameObject rippleParent;
// Settings
public bool isInteractable = true;
public bool enableIcon = false;
public bool enableText = true;
public bool useCustomContent = false;
public bool useCustomIconSize = false;
public bool useCustomTextSize = false;
public bool checkForDoubleClick = true;
public bool enableButtonSounds = false;
public bool useHoverSound = true;
public bool useClickSound = true;
public AudioClip hoverSound;
public AudioClip clickSound;
public bool useUINavigation = false;
public Navigation.Mode navigationMode = Navigation.Mode.Automatic;
public GameObject selectOnUp;
public GameObject selectOnDown;
public GameObject selectOnLeft;
public GameObject selectOnRight;
public bool wrapAround = false;
public bool useRipple = true;
[Range(0.1f, 1)] public float doubleClickPeriod = 0.25f;
[Range(0.25f, 15)] public float fadingMultiplier = 8;
public AnimationSolution animationSolution = AnimationSolution.ScriptBased;
// Events
public UnityEvent onClick = new UnityEvent();
public UnityEvent onDoubleClick = new UnityEvent();
public UnityEvent onHover = new UnityEvent();
public UnityEvent onLeave = new UnityEvent();
// Ripple
public RippleUpdateMode rippleUpdateMode = RippleUpdateMode.UnscaledTime;
public Sprite rippleShape;
[Range(0.1f, 5)] public float speed = 1f;
[Range(0.5f, 25)] public float maxSize = 4f;
public Color startColor = new Color(1f, 1f, 1f, 0.2f);
public Color transitionColor = new Color(1f, 1f, 1f, 0f);
public bool renderOnTop = false;
public bool centered = false;
// Helpers
Button targetButton;
bool isPointerOn;
bool waitingForDoubleClickInput;
#if UNITY_EDITOR
public bool isPreset;
public int latestTabIndex = 0;
#endif
public enum AnimationSolution { Custom, ScriptBased }
public enum RippleUpdateMode { Normal, UnscaledTime }
[System.Serializable] public class Padding { public int left = 20; public int right = 20; public int top = 5; public int bottom = 5; }
void OnEnable()
{
UpdateUI();
}
void OnDisable()
{
if (isInteractable == false)
return;
if (disabledCG != null) { disabledCG.alpha = 0; }
if (normalCG != null) { normalCG.alpha = 1; }
if (highlightCG != null) { highlightCG.alpha = 0; }
}
void Awake()
{
#if UNITY_EDITOR
if (!Application.isPlaying) { return; }
#endif
if (animationSolution == AnimationSolution.ScriptBased)
{
Animator tempAnimator = GetComponent<Animator>();
if (tempAnimator != null) { Destroy(tempAnimator); }
}
if (gameObject.GetComponent<Image>() == null)
{
Image raycastImg = gameObject.AddComponent<Image>();
raycastImg.color = new Color(0, 0, 0, 0);
raycastImg.raycastTarget = true;
}
if (useUINavigation == true) { AddUINavigation(); }
if (normalCG == null) { normalCG = new GameObject().AddComponent<CanvasGroup>(); normalCG.gameObject.AddComponent<RectTransform>(); normalCG.transform.SetParent(transform); normalCG.gameObject.name = "Normal"; }
if (highlightCG == null) { highlightCG = new GameObject().AddComponent<CanvasGroup>(); highlightCG.gameObject.AddComponent<RectTransform>(); highlightCG.transform.SetParent(transform); highlightCG.gameObject.name = "Highlight"; }
if (disabledCG == null) { disabledCG = new GameObject().AddComponent<CanvasGroup>(); disabledCG.gameObject.AddComponent<RectTransform>(); disabledCG.transform.SetParent(transform); disabledCG.gameObject.name = "Disabled"; }
if (useRipple == true && rippleParent != null) { rippleParent.SetActive(false); }
else if (useRipple == false && rippleParent != null) { Destroy(rippleParent); }
StartCoroutine("LayoutFix");
}
public void UpdateUI()
{
if (autoFitContent == false)
{
if (mainFitter != null) { mainFitter.enabled = false; }
if (mainLayout != null) { mainLayout.enabled = false; }
if (targetFitter != null)
{
targetFitter.enabled = false;
if (targetRect != null)
{
targetRect.anchorMin = new Vector2(0, 0);
targetRect.anchorMax = new Vector2(1, 1);
targetRect.offsetMin = new Vector2(0, 0);
targetRect.offsetMax = new Vector2(0, 0);
}
}
}
else
{
if (mainFitter != null) { mainFitter.enabled = true; }
if (mainLayout != null) { mainLayout.enabled = true; }
if (targetFitter != null) { targetFitter.enabled = true; }
}
if (disabledLayout != null) { disabledLayout.padding = new RectOffset(padding.left, padding.right, padding.top, padding.bottom); disabledLayout.spacing = spacing; }
if (normalLayout != null) { normalLayout.padding = new RectOffset(padding.left, padding.right, padding.top, padding.bottom); normalLayout.spacing = spacing; }
if (highlightedLayout != null) { highlightedLayout.padding = new RectOffset(padding.left, padding.right, padding.top, padding.bottom); highlightedLayout.spacing = spacing; }
if (normalCG != null && isInteractable == true) { normalCG.alpha = 1; }
if (disabledCG != null && isInteractable == false) { disabledCG.alpha = 1; }
if (highlightCG != null) { highlightCG.alpha = 0; }
if (useCustomContent == false)
{
// Set Text
if (enableText == true)
{
if (normalText != null)
{
normalText.gameObject.SetActive(true);
normalText.text = buttonText;
if (useCustomTextSize == false) { normalText.fontSize = textSize; }
}
if (highlightedText != null)
{
highlightedText.gameObject.SetActive(true);
highlightedText.text = buttonText;
if (useCustomTextSize == false) { highlightedText.fontSize = textSize; }
}
if (disabledText != null)
{
disabledText.gameObject.SetActive(true);
disabledText.text = buttonText;
if (useCustomTextSize == false) { disabledText.fontSize = textSize; }
}
}
else if (enableText == false)
{
if (normalText != null) { normalText.gameObject.SetActive(false); }
if (highlightedText != null) { highlightedText.gameObject.SetActive(false); }
if (disabledText != null) { disabledText.gameObject.SetActive(false); }
}
// Set Icon
if (enableIcon == true)
{
Vector3 tempScale = new Vector3(iconScale, iconScale, iconScale);
if (normalImage != null) { normalImage.transform.parent.gameObject.SetActive(true); normalImage.sprite = buttonIcon; normalImage.transform.localScale = tempScale; }
if (highlightImage != null) { highlightImage.transform.parent.gameObject.SetActive(true); highlightImage.sprite = buttonIcon; ; highlightImage.transform.localScale = tempScale; }
if (disabledImage != null) { disabledImage.transform.parent.gameObject.SetActive(true); disabledImage.sprite = buttonIcon; ; disabledImage.transform.localScale = tempScale; }
}
else
{
if (normalImage != null) { normalImage.transform.parent.gameObject.SetActive(false); }
if (highlightImage != null) { highlightImage.transform.parent.gameObject.SetActive(false); }
if (disabledImage != null) { disabledImage.transform.parent.gameObject.SetActive(false); }
}
}
#if UNITY_EDITOR
if (Application.isPlaying == false && autoFitContent == true)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
if (disabledCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(disabledCG.GetComponent<RectTransform>()); }
if (normalCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(normalCG.GetComponent<RectTransform>()); }
if (highlightCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(highlightCG.GetComponent<RectTransform>()); }
}
#endif
if (Application.isPlaying == false || gameObject.activeInHierarchy == false) { return; }
if (isInteractable == false) { StartCoroutine("SetDisabled"); }
else if (isInteractable == true && disabledCG.alpha == 1) { StartCoroutine("SetNormal"); }
StartCoroutine("LayoutFix");
}
public void SetText(string text) { buttonText = text; UpdateUI(); }
public void SetIcon(Sprite icon) { buttonIcon = icon; UpdateUI(); }
public void Interactable(bool value)
{
isInteractable = value;
if (gameObject.activeInHierarchy == false) { return; }
if (isInteractable == false) { StartCoroutine("SetDisabled"); }
else if (isInteractable == true && disabledCG.alpha == 1) { StartCoroutine("SetNormal"); }
}
public void AddUINavigation()
{
targetButton = gameObject.AddComponent<Button>();
targetButton.transition = Selectable.Transition.None;
Navigation customNav = new Navigation();
customNav.mode = navigationMode;
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine("InitUINavigation", customNav); return; }
targetButton.navigation = customNav;
}
public void CreateRipple(Vector2 pos)
{
if (rippleParent != null)
{
GameObject rippleObj = new GameObject();
rippleObj.AddComponent<Image>();
rippleObj.GetComponent<Image>().sprite = rippleShape;
rippleObj.name = "Ripple";
rippleParent.SetActive(true);
rippleObj.transform.SetParent(rippleParent.transform);
if (renderOnTop == true) { rippleParent.transform.SetAsLastSibling(); }
else { rippleParent.transform.SetAsFirstSibling(); }
if (centered == true) { rippleObj.transform.localPosition = new Vector2(0f, 0f); }
else { rippleObj.transform.position = pos; }
rippleObj.AddComponent<Ripple>();
Ripple tempRipple = rippleObj.GetComponent<Ripple>();
tempRipple.speed = speed;
tempRipple.maxSize = maxSize;
tempRipple.startColor = startColor;
tempRipple.transitionColor = transitionColor;
if (rippleUpdateMode == RippleUpdateMode.Normal) { tempRipple.unscaledTime = false; }
else { tempRipple.unscaledTime = true; }
}
}
public void OnPointerClick(PointerEventData eventData)
{
if (isInteractable == false || eventData.button != PointerEventData.InputButton.Left) { return; }
if (enableButtonSounds == true && useClickSound == true && soundSource != null) { soundSource.PlayOneShot(clickSound); }
// Invoke click actions
onClick.Invoke();
// Check for double click
if (checkForDoubleClick == false) { return; }
if (waitingForDoubleClickInput == true)
{
onDoubleClick.Invoke();
waitingForDoubleClickInput = false;
return;
}
waitingForDoubleClickInput = true;
StopCoroutine("CheckForDoubleClick");
StartCoroutine("CheckForDoubleClick");
}
public void OnPointerDown(PointerEventData eventData)
{
if (isInteractable == false) { return; }
if (useRipple == true && isPointerOn == true)
#if ENABLE_LEGACY_INPUT_MANAGER
CreateRipple(Input.mousePosition);
#elif ENABLE_INPUT_SYSTEM
CreateRipple(Mouse.current.position.ReadValue());
#endif
}
public void OnPointerEnter(PointerEventData eventData)
{
if (isInteractable == false)
return;
if (enableButtonSounds == true && useHoverSound == true && soundSource != null) { soundSource.PlayOneShot(hoverSound); }
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine("SetHighlight"); }
isPointerOn = true;
onHover.Invoke();
}
public void OnPointerExit(PointerEventData eventData)
{
if (isInteractable == false) { return; }
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine("SetNormal"); }
isPointerOn = false;
onLeave.Invoke();
}
public void OnSelect(BaseEventData eventData)
{
if (isInteractable == false) { return; }
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine("SetHighlight"); }
}
public void OnDeselect(BaseEventData eventData)
{
if (isInteractable == false) { return; }
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine("SetNormal"); }
}
public void OnSubmit(BaseEventData eventData)
{
if (isInteractable == false) { return; }
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine("SetNormal"); }
onClick.Invoke();
}
IEnumerator LayoutFix()
{
yield return new WaitForSecondsRealtime(0.025f);
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
if (disabledCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(disabledCG.GetComponent<RectTransform>()); }
if (normalCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(normalCG.GetComponent<RectTransform>()); }
if (highlightCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(highlightCG.GetComponent<RectTransform>()); }
}
IEnumerator SetNormal()
{
StopCoroutine("SetHighlight");
StopCoroutine("SetDisabled");
while (normalCG.alpha < 0.99f)
{
normalCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
disabledCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
yield return null;
}
normalCG.alpha = 1;
highlightCG.alpha = 0;
disabledCG.alpha = 0;
}
IEnumerator SetHighlight()
{
StopCoroutine("SetNormal");
StopCoroutine("SetDisabled");
while (highlightCG.alpha < 0.99f)
{
normalCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
highlightCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
disabledCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
yield return null;
}
normalCG.alpha = 0;
highlightCG.alpha = 1;
disabledCG.alpha = 0;
}
IEnumerator SetDisabled()
{
StopCoroutine("SetNormal");
StopCoroutine("SetHighlight");
while (disabledCG.alpha < 0.99f)
{
normalCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
disabledCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
yield return null;
}
normalCG.alpha = 0;
highlightCG.alpha = 0;
disabledCG.alpha = 1;
}
IEnumerator CheckForDoubleClick()
{
yield return new WaitForSecondsRealtime(doubleClickPeriod);
waitingForDoubleClickInput = false;
}
IEnumerator InitUINavigation(Navigation nav)
{
yield return new WaitForSecondsRealtime(1);
if (selectOnUp != null) { nav.selectOnUp = selectOnUp.GetComponent<Selectable>(); }
if (selectOnDown != null) { nav.selectOnDown = selectOnDown.GetComponent<Selectable>(); }
if (selectOnLeft != null) { nav.selectOnLeft = selectOnLeft.GetComponent<Selectable>(); }
if (selectOnRight != null) { nav.selectOnRight = selectOnRight.GetComponent<Selectable>(); }
targetButton.navigation = nav;
}
}
}

View File

@@ -0,0 +1,26 @@
fileFormatVersion: 2
guid: 5d218e07e7315e243acdfcc700d01eb5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- buttonIcon: {instanceID: 0}
- hoverSound: {instanceID: 0}
- clickSound: {instanceID: 0}
- normalCG: {instanceID: 0}
- highlightCG: {instanceID: 0}
- disabledCG: {instanceID: 0}
- normalText: {instanceID: 0}
- highlightedText: {instanceID: 0}
- disabledText: {instanceID: 0}
- normalImage: {instanceID: 0}
- highlightImage: {instanceID: 0}
- disabledImage: {instanceID: 0}
- soundSource: {instanceID: 0}
- rippleParent: {instanceID: 0}
- rippleShape: {fileID: 21300000, guid: 100d5727b1babc14bac90fe9c56af800, type: 3}
executionOrder: 0
icon: {fileID: 2800000, guid: 98d001ce6b3b53242911dcc3d1415f59, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,363 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using static Michsky.MUIP.ButtonManager;
namespace Michsky.MUIP
{
[CanEditMultipleObjects]
[CustomEditor(typeof(ButtonManager))]
public class ButtonManagerEditor : Editor
{
private GUISkin customSkin;
private ButtonManager buttonTarget;
private UIManagerButton tempUIM;
private void OnEnable()
{
buttonTarget = (ButtonManager)target;
try { tempUIM = buttonTarget.GetComponent<UIManagerButton>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "Button Top Header");
GUIContent[] toolbarTabs = new GUIContent[3];
toolbarTabs[0] = new GUIContent("Content");
toolbarTabs[1] = new GUIContent("Resources");
toolbarTabs[2] = new GUIContent("Settings");
buttonTarget.latestTabIndex = MUIPEditorHandler.DrawTabs(buttonTarget.latestTabIndex, toolbarTabs, customSkin);
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
buttonTarget.latestTabIndex = 0;
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
buttonTarget.latestTabIndex = 1;
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
buttonTarget.latestTabIndex = 2;
GUILayout.EndHorizontal();
var normalCG = serializedObject.FindProperty("normalCG");
var highlightCG = serializedObject.FindProperty("highlightCG");
var disabledCG = serializedObject.FindProperty("disabledCG");
var normalText = serializedObject.FindProperty("normalText");
var highlightedText = serializedObject.FindProperty("highlightedText");
var disabledText = serializedObject.FindProperty("disabledText");
var normalImageObj = serializedObject.FindProperty("normalImage");
var highlightImageObj = serializedObject.FindProperty("highlightImage");
var disabledImageObj = serializedObject.FindProperty("disabledImage");
var rippleParent = serializedObject.FindProperty("rippleParent");
var soundSource = serializedObject.FindProperty("soundSource");
var buttonIcon = serializedObject.FindProperty("buttonIcon");
var buttonText = serializedObject.FindProperty("buttonText");
var iconScale = serializedObject.FindProperty("iconScale");
var textSize = serializedObject.FindProperty("textSize");
var hoverSound = serializedObject.FindProperty("hoverSound");
var clickSound = serializedObject.FindProperty("clickSound");
var autoFitContent = serializedObject.FindProperty("autoFitContent");
var padding = serializedObject.FindProperty("padding");
var spacing = serializedObject.FindProperty("spacing");
var disabledLayout = serializedObject.FindProperty("disabledLayout");
var normalLayout = serializedObject.FindProperty("normalLayout");
var highlightedLayout = serializedObject.FindProperty("highlightedLayout");
var mainLayout = serializedObject.FindProperty("mainLayout");
var mainFitter = serializedObject.FindProperty("mainFitter");
var targetFitter = serializedObject.FindProperty("targetFitter");
var targetRect = serializedObject.FindProperty("targetRect");
var isInteractable = serializedObject.FindProperty("isInteractable");
var enableIcon = serializedObject.FindProperty("enableIcon");
var enableText = serializedObject.FindProperty("enableText");
var useCustomIconSize = serializedObject.FindProperty("useCustomIconSize");
var useCustomTextSize = serializedObject.FindProperty("useCustomTextSize");
var useUINavigation = serializedObject.FindProperty("useUINavigation");
var navigationMode = serializedObject.FindProperty("navigationMode");
var wrapAround = serializedObject.FindProperty("wrapAround");
var selectOnUp = serializedObject.FindProperty("selectOnUp");
var selectOnDown = serializedObject.FindProperty("selectOnDown");
var selectOnLeft = serializedObject.FindProperty("selectOnLeft");
var selectOnRight = serializedObject.FindProperty("selectOnRight");
var checkForDoubleClick = serializedObject.FindProperty("checkForDoubleClick");
var enableButtonSounds = serializedObject.FindProperty("enableButtonSounds");
var useHoverSound = serializedObject.FindProperty("useHoverSound");
var useClickSound = serializedObject.FindProperty("useClickSound");
var useRipple = serializedObject.FindProperty("useRipple");
var fadingMultiplier = serializedObject.FindProperty("fadingMultiplier");
var doubleClickPeriod = serializedObject.FindProperty("doubleClickPeriod");
var animationSolution = serializedObject.FindProperty("animationSolution");
var useCustomContent = serializedObject.FindProperty("useCustomContent");
var renderOnTop = serializedObject.FindProperty("renderOnTop");
var centered = serializedObject.FindProperty("centered");
var rippleUpdateMode = serializedObject.FindProperty("rippleUpdateMode");
var rippleShape = serializedObject.FindProperty("rippleShape");
var speed = serializedObject.FindProperty("speed");
var maxSize = serializedObject.FindProperty("maxSize");
var startColor = serializedObject.FindProperty("startColor");
var transitionColor = serializedObject.FindProperty("transitionColor");
var onClick = serializedObject.FindProperty("onClick");
var onDoubleClick = serializedObject.FindProperty("onDoubleClick");
var onHover = serializedObject.FindProperty("onHover");
var onLeave = serializedObject.FindProperty("onLeave");
switch (buttonTarget.latestTabIndex)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
if (useCustomContent.boolValue == false)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
enableIcon.boolValue = MUIPEditorHandler.DrawTogglePlain(enableIcon.boolValue, customSkin, "Enable Icon");
GUILayout.Space(4);
if (enableIcon.boolValue == true)
{
MUIPEditorHandler.DrawPropertyCW(buttonIcon, customSkin, "Button Icon", 80);
if (useCustomIconSize.boolValue == false) { MUIPEditorHandler.DrawPropertyCW(iconScale, customSkin, "Icon Scale", 80); }
}
GUILayout.EndVertical();
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
enableText.boolValue = MUIPEditorHandler.DrawTogglePlain(enableText.boolValue, customSkin, "Enable Text");
GUILayout.Space(4);
if (enableText.boolValue == true)
{
MUIPEditorHandler.DrawPropertyCW(buttonText, customSkin, "Button Text", 80);
if (useCustomTextSize.boolValue == false) { MUIPEditorHandler.DrawPropertyCW(textSize, customSkin, "Text Size", 80); }
}
GUILayout.EndVertical();
buttonTarget.UpdateUI();
}
else { EditorGUILayout.HelpBox("'Use Custom Content' is enabled. Content is now managed manually.", MessageType.Info); }
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
autoFitContent.boolValue = MUIPEditorHandler.DrawTogglePlain(autoFitContent.boolValue, customSkin, "Auto-Fit Content");
GUILayout.Space(4);
if (autoFitContent.boolValue == true)
{
GUILayout.BeginHorizontal(EditorStyles.helpBox);
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(padding, new GUIContent(" Padding"), true);
EditorGUI.indentLevel = 0;
GUILayout.EndHorizontal();
MUIPEditorHandler.DrawProperty(spacing, customSkin, "Spacing");
}
GUILayout.EndVertical();
if (Application.isPlaying == true && GUILayout.Button("Refresh", customSkin.button)) { buttonTarget.UpdateUI(); }
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
EditorGUILayout.PropertyField(onClick, new GUIContent("On Click"), true);
EditorGUILayout.PropertyField(onDoubleClick, new GUIContent("On Double Click"), true);
EditorGUILayout.PropertyField(onHover, new GUIContent("On Hover"), true);
EditorGUILayout.PropertyField(onLeave, new GUIContent("On Leave"), true);
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(normalCG, customSkin, "Normal CG");
MUIPEditorHandler.DrawProperty(highlightCG, customSkin, "Highlight CG");
MUIPEditorHandler.DrawProperty(disabledCG, customSkin, "Disabled CG");
if (enableText.boolValue == true)
{
MUIPEditorHandler.DrawProperty(normalText, customSkin, "Normal Text");
MUIPEditorHandler.DrawProperty(highlightedText, customSkin, "Highlighted Text");
MUIPEditorHandler.DrawProperty(disabledText, customSkin, "Disabled Text");
}
if (enableIcon.boolValue == true)
{
MUIPEditorHandler.DrawProperty(normalImageObj, customSkin, "Normal Icon");
MUIPEditorHandler.DrawProperty(highlightImageObj, customSkin, "Highlight Icon");
MUIPEditorHandler.DrawProperty(disabledImageObj, customSkin, "Disabled Icon");
}
MUIPEditorHandler.DrawProperty(disabledLayout, customSkin, "Disabled Layout");
MUIPEditorHandler.DrawProperty(normalLayout, customSkin, "Normal Layout");
MUIPEditorHandler.DrawProperty(highlightedLayout, customSkin, "Highlighted Layout");
if (autoFitContent.boolValue == true)
{
MUIPEditorHandler.DrawProperty(mainLayout, customSkin, "Main Layout");
MUIPEditorHandler.DrawProperty(mainFitter, customSkin, "Main Fitter");
MUIPEditorHandler.DrawProperty(targetFitter, customSkin, "Target Fitter");
MUIPEditorHandler.DrawProperty(targetRect, customSkin, "Target Rect");
}
if (useRipple.boolValue == true) { MUIPEditorHandler.DrawProperty(rippleParent, customSkin, "Ripple Parent"); }
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
MUIPEditorHandler.DrawProperty(animationSolution, customSkin, "Animation Solution");
MUIPEditorHandler.DrawProperty(fadingMultiplier, customSkin, "Fading Multiplier");
MUIPEditorHandler.DrawProperty(doubleClickPeriod, customSkin, "Double Click Period");
isInteractable.boolValue = MUIPEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
if (useCustomContent.boolValue == true || enableText.boolValue == false) { GUI.enabled = false; }
useCustomTextSize.boolValue = MUIPEditorHandler.DrawToggle(useCustomTextSize.boolValue, customSkin, "Use Custom Text Size");
GUI.enabled = true;
useCustomContent.boolValue = MUIPEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content");
checkForDoubleClick.boolValue = MUIPEditorHandler.DrawToggle(checkForDoubleClick.boolValue, customSkin, "Check For Double Click");
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
useUINavigation.boolValue = MUIPEditorHandler.DrawTogglePlain(useUINavigation.boolValue, customSkin, "Use UI Navigation");
GUILayout.Space(4);
if (useUINavigation.boolValue == true)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
MUIPEditorHandler.DrawPropertyPlain(navigationMode, customSkin, "Navigation Mode");
if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Horizontal)
{
EditorGUI.indentLevel = 1;
// GUILayout.Space(-3);
wrapAround.boolValue = MUIPEditorHandler.DrawToggle(wrapAround.boolValue, customSkin, "Wrap Around");
// GUILayout.Space(4);
EditorGUI.indentLevel = 0;
}
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Vertical)
{
wrapAround.boolValue = MUIPEditorHandler.DrawTogglePlain(wrapAround.boolValue, customSkin, "Wrap Around");
}
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Explicit)
{
EditorGUI.indentLevel = 1;
MUIPEditorHandler.DrawPropertyPlain(selectOnUp, customSkin, "Select On Up");
MUIPEditorHandler.DrawPropertyPlain(selectOnDown, customSkin, "Select On Down");
MUIPEditorHandler.DrawPropertyPlain(selectOnLeft, customSkin, "Select On Left");
MUIPEditorHandler.DrawPropertyPlain(selectOnRight, customSkin, "Select On Right");
EditorGUI.indentLevel = 0;
}
GUILayout.EndVertical();
}
GUILayout.EndVertical();
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
enableButtonSounds.boolValue = MUIPEditorHandler.DrawTogglePlain(enableButtonSounds.boolValue, customSkin, "Enable Button Sounds");
GUILayout.Space(4);
if (enableButtonSounds.boolValue == true)
{
MUIPEditorHandler.DrawProperty(soundSource, customSkin, "Sound Source");
if (useHoverSound.boolValue == true) { MUIPEditorHandler.DrawProperty(hoverSound, customSkin, "Hover Sound"); }
if (useClickSound.boolValue == true) { MUIPEditorHandler.DrawProperty(clickSound, customSkin, "Click Sound"); }
useHoverSound.boolValue = MUIPEditorHandler.DrawToggle(useHoverSound.boolValue, customSkin, "Enable Hover Sound");
useClickSound.boolValue = MUIPEditorHandler.DrawToggle(useClickSound.boolValue, customSkin, "Enable Click Sound");
if (buttonTarget.soundSource == null) { EditorGUILayout.HelpBox("'Sound Source' is missing.", MessageType.Warning); }
}
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Customization Header", 10);
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-2);
useRipple.boolValue = MUIPEditorHandler.DrawTogglePlain(useRipple.boolValue, customSkin, "Use Ripple");
GUILayout.Space(4);
if (useRipple.boolValue == true)
{
renderOnTop.boolValue = MUIPEditorHandler.DrawToggle(renderOnTop.boolValue, customSkin, "Render On Top");
centered.boolValue = MUIPEditorHandler.DrawToggle(centered.boolValue, customSkin, "Centered");
MUIPEditorHandler.DrawProperty(rippleUpdateMode, customSkin, "Update Mode");
MUIPEditorHandler.DrawProperty(rippleShape, customSkin, "Shape");
MUIPEditorHandler.DrawProperty(speed, customSkin, "Speed");
MUIPEditorHandler.DrawProperty(maxSize, customSkin, "Max Size");
MUIPEditorHandler.DrawProperty(startColor, customSkin, "Start Color");
MUIPEditorHandler.DrawProperty(transitionColor, customSkin, "Transition Color");
}
GUILayout.EndVertical();
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)
{
if (buttonTarget.isPreset == true) { MUIPEditorHandler.DrawUIManagerPresetHeader(); }
else
{
MUIPEditorHandler.DrawUIManagerDisconnectedHeader();
if (GUILayout.Button("Restore UI Manager", customSkin.button))
{
UIManagerButton uimb = buttonTarget.gameObject.AddComponent<UIManagerButton>();
try
{
//
}
catch { DestroyImmediate(uimb); Debug.LogError("<b>[Modern UI Pack]</b> Cannot restore the UI Manager connection."); }
}
}
}
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4027e626241ca4140aa30808faae978a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e7e0b87066b687e449d3c6c7bef1a8fd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,195 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace Michsky.MUIP
{
public class PieChart : MaskableGraphic
{
// Chart Items
[SerializeField] public List<PieChartDataNode> chartData = new List<PieChartDataNode>();
// Settings
[Range(-75, 150)] public float borderThickness = 5;
[SerializeField] private Color borderColor = new Color32(255, 255, 255, 255);
public Transform indicatorParent;
public string valuePrefix = "(";
public string valueSuffix = ")";
public bool addValueToIndicator = true;
public bool enableBorderColor;
private float fillAmount = 1f;
private int segments = 720;
[System.Serializable]
public class PieChartDataNode
{
public string name = "Chart Item";
public float value = 10;
public Color32 color = new Color32(255, 255, 255, 255);
public Image indicatorImage;
public TextMeshProUGUI indicatorText;
}
protected override void Awake()
{
base.Awake();
UpdateIndicators();
}
void Update()
{
this.borderThickness = (float)Mathf.Clamp(this.borderThickness, -75, rectTransform.rect.width / 3.333f);
}
protected override void OnPopulateMesh(VertexHelper vh)
{
if (chartData.Count == 0)
return;
float outer = -rectTransform.pivot.x * rectTransform.rect.width;
float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.borderThickness;
var outer1 = -rectTransform.pivot.x * rectTransform.rect.width * 0.6f;
var inner1 = -rectTransform.pivot.x * rectTransform.rect.width * 0.6f + this.borderThickness;
vh.Clear();
Vector2 prevX = Vector2.zero;
Vector2 prevY = Vector2.zero;
Vector2 uv0 = new Vector2(0, 0);
Vector2 uv1 = new Vector2(0, 1);
Vector2 uv2 = new Vector2(1, 1);
Vector2 uv3 = new Vector2(1, 0);
Vector2 pos0;
Vector2 pos1;
Vector2 pos2;
Vector2 pos3;
float f = fillAmount;
float degrees = 360f / segments;
int fa = (int)((segments + 1) * f);
var dataIndex = 0;
var total = 0f;
var currentValue = chartData[0].value;
chartData.ForEach(s => total += s.value);
var fillColor = chartData[0].color;
for (int i = 0; i < fa; i++)
{
float rad = Mathf.Deg2Rad * (i * degrees);
float c = Mathf.Cos(rad);
float s = Mathf.Sin(rad);
uv0 = new Vector2(0, 1);
uv1 = new Vector2(1, 1);
uv2 = new Vector2(1, 0);
uv3 = new Vector2(0, 0);
pos0 = prevX;
pos1 = new Vector2(outer * c, outer * s);
pos2 = new Vector2(inner * c, inner * s);
pos3 = prevY;
if (i > currentValue / total * segments)
{
if (dataIndex < chartData.Count - 1)
{
dataIndex += 1;
currentValue += chartData[dataIndex].value;
fillColor = chartData[dataIndex].color;
}
}
vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2 * inner1 / inner, pos3 * inner1 / inner }, new[] { uv0, uv1, uv2, uv3 }, fillColor));
if (enableBorderColor == true)
{
vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }, borderColor));
vh.AddUIVertexQuad(SetVbo(new[] { pos0 * outer1 / outer, pos1 * outer1 / outer, pos2 * inner1 / inner, pos3 * inner1 / inner }, new[] { uv0, uv1, uv2, uv3 }, borderColor));
}
prevX = pos1;
prevY = pos2;
}
}
public void SetData(List<PieChartDataNode> data)
{
chartData = data;
SetVerticesDirty();
}
protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs, Color32 color)
{
UIVertex[] vbo = new UIVertex[4];
for (int i = 0; i < vertices.Length; i++)
{
var vert = UIVertex.simpleVert;
vert.color = color;
vert.position = vertices[i];
vert.uv0 = uvs[i];
vbo[i] = vert;
}
return vbo;
}
public void UpdateIndicators()
{
for (int i = 0; i < chartData.Count; ++i)
{
if (chartData[i].indicatorImage != null)
chartData[i].indicatorImage.color = chartData[i].color;
if (chartData[i].indicatorText != null && addValueToIndicator == true)
chartData[i].indicatorText.text = chartData[i].name + valuePrefix + chartData[i].value.ToString() + valueSuffix;
else if (chartData[i].indicatorText != null && addValueToIndicator == false)
chartData[i].indicatorText.text = chartData[i].name;
}
if (indicatorParent != null)
StartCoroutine("UpdateIndicatorLayout");
}
public void ChangeValue(int itemIndex, float itemValue)
{
chartData[itemIndex].value = itemValue;
this.enabled = false;
this.enabled = true;
}
public void AddNewItem()
{
PieChartDataNode item = new PieChartDataNode();
if (indicatorParent.childCount != 0)
{
int tempIndex = indicatorParent.childCount - 1;
GameObject tempIndicator = indicatorParent.GetChild(tempIndex).gameObject;
GameObject newIndicator = Instantiate(tempIndicator, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
newIndicator.transform.SetParent(indicatorParent, false);
newIndicator.gameObject.name = "Item " + tempIndex.ToString() + " Indicator";
item.indicatorImage = newIndicator.GetComponentInChildren<Image>();
item.indicatorText = newIndicator.GetComponentInChildren<TextMeshProUGUI>();
item.name = "Chart Item " + tempIndex.ToString();
}
chartData.Add(item);
}
IEnumerator UpdateIndicatorLayout()
{
yield return new WaitForSeconds(0.1f);
LayoutRebuilder.ForceRebuildLayoutImmediate(indicatorParent.GetComponentInParent<RectTransform>());
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5e4a4384d3c229846b0d84dc8ec948dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 3ae7671fb73a5df4ebec7a6b32ae8e8c, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,120 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(PieChart))]
public class PieChartEditor : Editor
{
private GUISkin customSkin;
private PieChart pieTarget;
private UIManagerPieChart tempUIM;
private int currentTab;
private void OnEnable()
{
pieTarget = (PieChart)target;
try { tempUIM = pieTarget.GetComponent<UIManagerPieChart>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "PC Top Header");
GUIContent[] toolbarTabs = new GUIContent[2];
toolbarTabs[0] = new GUIContent("Content");
toolbarTabs[1] = 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("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
currentTab = 1;
GUILayout.EndHorizontal();
var chartData = serializedObject.FindProperty("chartData");
var borderThickness = serializedObject.FindProperty("borderThickness");
var borderColor = serializedObject.FindProperty("borderColor");
var enableBorderColor = serializedObject.FindProperty("enableBorderColor");
var addValueToIndicator = serializedObject.FindProperty("addValueToIndicator");
var indicatorParent = serializedObject.FindProperty("indicatorParent");
var valuePrefix = serializedObject.FindProperty("valuePrefix");
var valueSuffix = serializedObject.FindProperty("valueSuffix");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
GUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(chartData, new GUIContent("Chart Items"));
chartData.isExpanded = true;
if (GUILayout.Button("+ Add a new item", customSkin.button))
pieTarget.AddNewItem();
EditorGUI.indentLevel = 0;
GUILayout.EndHorizontal();
if (pieTarget.gameObject.activeInHierarchy == true)
pieTarget.UpdateIndicators();
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Customization Header", 6);
MUIPEditorHandler.DrawProperty(indicatorParent, customSkin, "Indicator Parent");
MUIPEditorHandler.DrawProperty(borderThickness, customSkin, "Border Thickness");
addValueToIndicator.boolValue = MUIPEditorHandler.DrawToggle(addValueToIndicator.boolValue, customSkin, "Add Value To Indicator");
if (addValueToIndicator.boolValue == true)
{
MUIPEditorHandler.DrawPropertyCW(valuePrefix, customSkin, "Value Prefix:", 75);
MUIPEditorHandler.DrawPropertyCW(valueSuffix, customSkin, "Value Suffix:", 75);
}
enableBorderColor.boolValue = MUIPEditorHandler.DrawToggle(enableBorderColor.boolValue, customSkin, "Enable Border Color (Experimental)");
if (enableBorderColor.boolValue == true)
MUIPEditorHandler.DrawProperty(borderColor, customSkin, "Border Color");
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 (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e02c02515eb09c04caeb0ab2d66d83da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 24042a316d186e24cb8ff5555642e401
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,197 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using TMPro;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace Michsky.MUIP
{
[AddComponentMenu("Modern UI Pack/Context Menu/Context Menu Content")]
public class ContextMenuContent : MonoBehaviour, IPointerClickHandler
{
// Resources
public ContextMenuManager contextManager;
public Transform itemParent;
// Settings
public bool useIn3D = false;
// Items
public List<ContextItem> contexItems = new List<ContextItem>();
Animator contextAnimator;
GameObject selectedItem;
Image setItemImage;
TextMeshProUGUI setItemText;
Sprite imageHelper;
string textHelper;
[System.Serializable]
public class ContextItem
{
[Header("Information")]
[Space(-5)]
public string itemText = "Item Text";
public Sprite itemIcon;
public ContextItemType contextItemType;
[Header("Sub Menu")]
public List<SubMenuItem> subMenuItems = new List<SubMenuItem>();
[Header("Events")]
public UnityEvent onClick;
}
[System.Serializable]
public class SubMenuItem
{
public string itemText = "Item Text";
public Sprite itemIcon;
public ContextItemType contextItemType;
public UnityEvent onClick;
}
public enum ContextItemType { Button, Separator }
void Awake()
{
if (contextManager == null)
{
try
{
contextManager = (ContextMenuManager)GameObject.FindObjectsOfType(typeof(ContextMenuManager))[0];
itemParent = contextManager.transform.Find("Content/Item List").transform;
}
catch { Debug.LogError("<b>[Context Menu]</b> Context Manager is missing.", this); return; }
}
contextAnimator = contextManager.contextAnimator;
foreach (Transform child in itemParent)
Destroy(child.gameObject);
}
public void ProcessContent()
{
foreach (Transform child in itemParent) { Destroy(child.gameObject); }
for (int i = 0; i < contexItems.Count; ++i)
{
bool nulLVariable = false;
if (contexItems[i].contextItemType == ContextItemType.Button && contextManager.contextButton != null)
selectedItem = contextManager.contextButton;
else if (contexItems[i].contextItemType == ContextItemType.Separator && contextManager.contextSeparator != null)
selectedItem = contextManager.contextSeparator;
else
{
Debug.LogError("<b>[Context Menu]</b> At least one of the item presets is missing. " +
"You can assign a new variable in Resources (Context Menu) tab. All default presets can be found in " +
"<b>Modern UI Pack > Prefabs > Context Menu</b> folder.", this);
nulLVariable = true;
}
if (nulLVariable == false)
{
if (contexItems[i].subMenuItems.Count == 0)
{
GameObject go = Instantiate(selectedItem, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(itemParent, false);
if (contexItems[i].contextItemType == ContextItemType.Button)
{
setItemText = go.GetComponentInChildren<TextMeshProUGUI>();
textHelper = contexItems[i].itemText;
setItemText.text = textHelper;
Transform goImage = go.gameObject.transform.Find("Icon");
setItemImage = goImage.GetComponent<Image>();
imageHelper = contexItems[i].itemIcon;
setItemImage.sprite = imageHelper;
if (imageHelper == null)
setItemImage.color = new Color(0, 0, 0, 0);
Button itemButton = go.GetComponent<Button>();
itemButton.onClick.AddListener(contexItems[i].onClick.Invoke);
itemButton.onClick.AddListener(CloseOnClick);
}
}
else if (contextManager.contextSubMenu != null && contexItems[i].subMenuItems.Count != 0)
{
GameObject go = Instantiate(contextManager.contextSubMenu, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(itemParent, false);
ContextMenuSubMenu subMenu = go.GetComponent<ContextMenuSubMenu>();
subMenu.cmManager = contextManager;
subMenu.cmContent = this;
subMenu.subMenuIndex = i;
setItemText = go.GetComponentInChildren<TextMeshProUGUI>();
textHelper = contexItems[i].itemText;
setItemText.text = textHelper;
Transform goImage;
goImage = go.gameObject.transform.Find("Icon");
setItemImage = goImage.GetComponent<Image>();
imageHelper = contexItems[i].itemIcon;
setItemImage.sprite = imageHelper;
}
StopCoroutine("ExecuteAfterTime");
StartCoroutine("ExecuteAfterTime", 0.01f);
}
}
contextManager.SetContextMenuPosition();
contextAnimator.Play("Menu In");
contextManager.isOn = true;
contextManager.SetContextMenuPosition();
}
public void OnPointerClick(PointerEventData eventData)
{
if (contextManager.isOn == true) { contextAnimator.Play("Menu Out"); contextManager.isOn = false; }
else if (eventData.button == PointerEventData.InputButton.Right && contextManager.isOn == false) { ProcessContent(); }
}
IEnumerator ExecuteAfterTime(float time)
{
yield return new WaitForSecondsRealtime(time);
itemParent.gameObject.SetActive(false);
itemParent.gameObject.SetActive(true);
}
public void OnMouseOver()
{
#if ENABLE_LEGACY_INPUT_MANAGER
if (useIn3D == true && Input.GetMouseButtonDown(1))
#elif ENABLE_INPUT_SYSTEM
if (useIn3D == true && Mouse.current.rightButton.wasPressedThisFrame)
#endif
{
ProcessContent();
}
}
public void Close()
{
contextAnimator.Play("Menu Out");
contextManager.isOn = false;
}
public void CloseOnClick() { Close(); }
public void AddNewItem()
{
ContextItem item = new ContextItem();
contexItems.Add(item);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe4f202dc85015b48aa586eba6d38692
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: cceded5b1d0834e48849fb152ac8e53d, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,86 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(ContextMenuContent))]
public class ContextMenuContentEditor : Editor
{
private GUISkin customSkin;
private ContextMenuContent cmcTarget;
private int currentTab;
private void OnEnable()
{
cmcTarget = (ContextMenuContent)target;
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "CM 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 contextManager = serializedObject.FindProperty("contextManager");
var itemParent = serializedObject.FindProperty("itemParent");
var contexItems = serializedObject.FindProperty("contexItems");
var useIn3D = serializedObject.FindProperty("useIn3D");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
#if UNITY_2020_1_OR_NEWER
GUILayout.BeginVertical();
#else
GUILayout.BeginVertical(EditorStyles.helpBox);
#endif
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(contexItems, new GUIContent("Context Menu Items"), true);
contexItems.isExpanded = true;
EditorGUI.indentLevel = 0;
if (GUILayout.Button("+ Add a new item", customSkin.button))
cmcTarget.AddNewItem();
GUILayout.EndVertical();
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(contextManager, customSkin, "Context Manager");
MUIPEditorHandler.DrawProperty(itemParent, customSkin, "Item Parent");
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
useIn3D.boolValue = MUIPEditorHandler.DrawToggle(useIn3D.boolValue, customSkin, "Use In 3D");
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6027ca9dc17f95b4f8e126a1326329ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,159 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using TMPro;
namespace Michsky.MUIP
{
[AddComponentMenu("Modern UI Pack/Context Menu/Context Menu Content (Mobile)")]
public class ContextMenuContentMobile : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[Header("Resources")]
public ContextMenuManager contextManager;
public Transform itemParent;
[Header("Settings")]
[Range(0.1f, 6)] public float holdToOpen = 0.75f;
[Header("Items")]
public List<ContextItem> contexItems = new List<ContextItem>();
Animator contextAnimator;
GameObject selectedItem;
Image setItemImage;
TextMeshProUGUI setItemText;
Sprite imageHelper;
string textHelper;
float timer;
bool timerEnabled;
[System.Serializable]
public class ContextItem
{
public string itemText = "Item Text";
public Sprite itemIcon;
public ContextItemType contextItemType;
public UnityEvent onClick;
}
public enum ContextItemType
{
BUTTON
// SUB_MENU
}
void Start()
{
if (contextManager == null)
{
try
{
contextManager = GameObject.Find("Context Menu").GetComponent<ContextMenuManager>();
itemParent = contextManager.transform.Find("Content/Item List").transform;
}
catch { Debug.Log("<b>[Context Menu]</b> Context Manager is missing.", this); return; }
}
contextAnimator = contextManager.contextAnimator;
foreach (Transform child in itemParent)
Destroy(child.gameObject);
}
void Update()
{
if (timerEnabled == true)
{
timer += Time.deltaTime;
if (timer >= holdToOpen)
{
CheckForTimer();
timerEnabled = false;
timer = 0;
}
}
}
public void OnPointerDown(PointerEventData eventData)
{
timerEnabled = true;
}
public void OnPointerUp(PointerEventData eventData)
{
timerEnabled = false;
timer = 0;
}
public void CheckForTimer()
{
if (timer <= holdToOpen)
return;
if (contextManager.isOn == true)
{
contextAnimator.Play("Menu Out");
contextManager.isOn = false;
}
else if (contextManager.isOn == false)
{
foreach (Transform child in itemParent)
Destroy(child.gameObject);
for (int i = 0; i < contexItems.Count; ++i)
{
if (contexItems[i].contextItemType == ContextItemType.BUTTON)
selectedItem = contextManager.contextButton;
GameObject go = Instantiate(selectedItem, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(itemParent, false);
setItemText = go.GetComponentInChildren<TextMeshProUGUI>();
textHelper = contexItems[i].itemText;
setItemText.text = textHelper;
Transform goImage;
goImage = go.gameObject.transform.Find("Icon");
setItemImage = goImage.GetComponent<Image>();
imageHelper = contexItems[i].itemIcon;
setItemImage.sprite = imageHelper;
if (imageHelper == null)
setItemImage.color = new Color(0, 0, 0, 0);
Button itemButton;
itemButton = go.GetComponent<Button>();
itemButton.onClick.AddListener(contexItems[i].onClick.Invoke);
itemButton.onClick.AddListener(CloseOnClick);
StartCoroutine(ExecuteAfterTime(0.01f));
}
contextManager.SetContextMenuPosition();
contextAnimator.Play("Menu In");
contextManager.isOn = true;
contextManager.SetContextMenuPosition();
}
}
IEnumerator ExecuteAfterTime(float time)
{
yield return new WaitForSeconds(time);
itemParent.gameObject.SetActive(false);
itemParent.gameObject.SetActive(true);
StopCoroutine(ExecuteAfterTime(0.01f));
StopCoroutine("ExecuteAfterTime");
}
public void CloseOnClick()
{
contextAnimator.Play("Menu Out");
contextManager.isOn = false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f93b797e33a2590489a95b86d8490887
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: cceded5b1d0834e48849fb152ac8e53d, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,111 @@
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace Michsky.MUIP
{
[RequireComponent(typeof(Animator))]
public class ContextMenuManager : MonoBehaviour
{
// Resources
public Canvas mainCanvas;
public Camera targetCamera;
public GameObject contextContent;
public Animator contextAnimator;
public GameObject contextButton;
public GameObject contextSeparator;
public GameObject contextSubMenu;
// Settings
public bool autoSubMenuPosition = true;
public SubMenuBehaviour subMenuBehaviour;
public CameraSource cameraSource = CameraSource.Main;
// Bounds
[Range(-50, 50)] public int vBorderTop = -10;
[Range(-50, 50)] public int vBorderBottom = 10;
[Range(-50, 50)] public int hBorderLeft = 15;
[Range(-50, 50)] public int hBorderRight = -15;
Vector2 uiPos;
Vector3 cursorPos;
Vector3 contentPos = new Vector3(0, 0, 0);
Vector3 contextVelocity = Vector3.zero;
RectTransform contextRect;
RectTransform contentRect;
[HideInInspector] public bool isOn;
[HideInInspector] public bool bottomLeft;
[HideInInspector] public bool bottomRight;
[HideInInspector] public bool topLeft;
[HideInInspector] public bool topRight;
public enum CameraSource { Main, Custom }
public enum SubMenuBehaviour { Hover, Click }
void Awake()
{
if (mainCanvas == null) { mainCanvas = gameObject.GetComponentInParent<Canvas>(); }
if (contextAnimator == null) { contextAnimator = gameObject.GetComponent<Animator>(); }
if (cameraSource == CameraSource.Main) { targetCamera = Camera.main; }
contextRect = gameObject.GetComponent<RectTransform>();
contentRect = contextContent.GetComponent<RectTransform>();
contentPos = new Vector3(vBorderTop, hBorderLeft, 0);
gameObject.transform.SetAsLastSibling();
#if UNITY_2022_1_OR_NEWER
subMenuBehaviour = SubMenuBehaviour.Click;
#endif
}
public void CheckForBounds()
{
if (uiPos.x <= -100) { contentPos = new Vector3(hBorderLeft, contentPos.y, 0); contentRect.pivot = new Vector2(0f, contentRect.pivot.y); bottomLeft = true; }
else { bottomLeft = false; }
if (uiPos.x >= 100) { contentPos = new Vector3(hBorderRight, contentPos.y, 0); contentRect.pivot = new Vector2(1f, contentRect.pivot.y); bottomRight = true; }
else { bottomRight = false; }
if (uiPos.y <= -75) { contentPos = new Vector3(contentPos.x, vBorderBottom, 0); contentRect.pivot = new Vector2(contentRect.pivot.x, 0f); topLeft = true; }
else { topLeft = false; }
if (uiPos.y >= 75) { contentPos = new Vector3(contentPos.x, vBorderTop, 0); contentRect.pivot = new Vector2(contentRect.pivot.x, 1f); topRight = true; }
else { topRight = false; }
}
public void SetContextMenuPosition()
{
#if ENABLE_LEGACY_INPUT_MANAGER
cursorPos = Input.mousePosition;
#elif ENABLE_INPUT_SYSTEM
cursorPos = Mouse.current.position.ReadValue();
#endif
uiPos = contextRect.anchoredPosition;
CheckForBounds();
if (mainCanvas.renderMode == RenderMode.ScreenSpaceCamera || mainCanvas.renderMode == RenderMode.WorldSpace)
{
contextRect.position = targetCamera.ScreenToWorldPoint(cursorPos);
contextRect.localPosition = new Vector3(contextRect.localPosition.x, contextRect.localPosition.y, 0);
contextContent.transform.localPosition = Vector3.SmoothDamp(contextContent.transform.localPosition, contentPos, ref contextVelocity, 0);
}
else if (mainCanvas.renderMode == RenderMode.ScreenSpaceOverlay)
{
contextRect.position = cursorPos;
contextContent.transform.position = new Vector3(cursorPos.x + contentPos.x, cursorPos.y + contentPos.y, 0);
}
}
public void Open() { contextAnimator.Play("Menu In"); isOn = true; }
public void Close() { contextAnimator.Play("Menu Out"); isOn = false; }
// Obsolote
public void OpenContextMenu() { Open(); }
public void CloseOnClick() { Close(); }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9021c5c7bd04ec245bf10c985a37c848
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: cceded5b1d0834e48849fb152ac8e53d, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,121 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(ContextMenuManager))]
public class ContextMenuManagerEditor : Editor
{
private GUISkin customSkin;
private ContextMenuManager cmTarget;
private UIManagerContextMenu tempUIM;
private int currentTab;
private void OnEnable()
{
cmTarget = (ContextMenuManager)target;
try { tempUIM = cmTarget.GetComponent<UIManagerContextMenu>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "CM 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 contextContent = serializedObject.FindProperty("contextContent");
var contextAnimator = serializedObject.FindProperty("contextAnimator");
var contextButton = serializedObject.FindProperty("contextButton");
var contextSeparator = serializedObject.FindProperty("contextSeparator");
var contextSubMenu = serializedObject.FindProperty("contextSubMenu");
var autoSubMenuPosition = serializedObject.FindProperty("autoSubMenuPosition");
var subMenuBehaviour = serializedObject.FindProperty("subMenuBehaviour");
var vBorderTop = serializedObject.FindProperty("vBorderTop");
var vBorderBottom = serializedObject.FindProperty("vBorderBottom");
var hBorderLeft = serializedObject.FindProperty("hBorderLeft");
var hBorderRight = serializedObject.FindProperty("hBorderRight");
var cameraSource = serializedObject.FindProperty("cameraSource");
var targetCamera = serializedObject.FindProperty("targetCamera");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
MUIPEditorHandler.DrawProperty(vBorderTop, customSkin, "Vertical Top");
MUIPEditorHandler.DrawProperty(vBorderBottom, customSkin, "Vertical Bottom");
MUIPEditorHandler.DrawProperty(hBorderLeft, customSkin, "Horizontal Left");
MUIPEditorHandler.DrawProperty(hBorderRight, customSkin, "Horizontal Right");
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(contextContent, customSkin, "Context Content");
MUIPEditorHandler.DrawProperty(contextAnimator, customSkin, "Context Animator");
MUIPEditorHandler.DrawProperty(contextButton, customSkin, "Button Preset");
MUIPEditorHandler.DrawProperty(contextSeparator, customSkin, "Seperator Preset");
MUIPEditorHandler.DrawProperty(contextSubMenu, customSkin, "Sub Menu Preset");
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
autoSubMenuPosition.boolValue = MUIPEditorHandler.DrawToggle(autoSubMenuPosition.boolValue, customSkin, "Auto Sub Menu Position");
MUIPEditorHandler.DrawProperty(subMenuBehaviour, customSkin, "Sub Menu Behaviour");
#if UNITY_2022_1_OR_NEWER
EditorGUILayout.HelpBox("Due to an issue with the event system, the 'Hover' option will be temporarily disabled in Unity 2022.1.", MessageType.Info);
#endif
MUIPEditorHandler.DrawProperty(cameraSource, customSkin, "Camera Source");
if (cmTarget.cameraSource == ContextMenuManager.CameraSource.Custom)
MUIPEditorHandler.DrawProperty(targetCamera, customSkin, "Target Camera");
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>[Context Menu]</b> Failed to delete UI Manager connection.", this); }
}
}
}
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 527585204cee0694b9800f8f51baace0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,136 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using TMPro;
namespace Michsky.MUIP
{
public class ContextMenuSubMenu : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
public ContextMenuManager cmManager;
public ContextMenuContent cmContent;
public Animator subMenuAnimator;
public Transform itemParent;
public GameObject trigger;
[HideInInspector] public int subMenuIndex;
GameObject selectedItem;
Image setItemImage;
TextMeshProUGUI setItemText;
Sprite imageHelper;
string textHelper;
RectTransform listParent;
[HideInInspector] public bool enableFadeOut = true;
void OnEnable()
{
if (itemParent == null) { Debug.Log("<b>[Context Menu]</b> Item Parent is missing.", this); return; }
listParent = itemParent.parent.gameObject.GetComponent<RectTransform>();
}
public void OnPointerClick(PointerEventData eventData)
{
if (cmManager.subMenuBehaviour == ContextMenuManager.SubMenuBehaviour.Click)
{
if (subMenuAnimator.GetCurrentAnimatorStateInfo(0).IsName("Menu In"))
{
subMenuAnimator.Play("Menu Out");
if (trigger != null) { trigger.SetActive(false); }
}
else
{
subMenuAnimator.Play("Menu In");
if (trigger != null) { trigger.SetActive(true); }
}
}
}
public void OnPointerEnter(PointerEventData eventData)
{
foreach (Transform child in itemParent)
Destroy(child.gameObject);
for (int i = 0; i < cmContent.contexItems[subMenuIndex].subMenuItems.Count; ++i)
{
bool nulLVariable = false;
if (cmContent.contexItems[subMenuIndex].subMenuItems[i].contextItemType == ContextMenuContent.ContextItemType.Button && cmManager.contextButton != null)
selectedItem = cmManager.contextButton;
else if (cmContent.contexItems[subMenuIndex].subMenuItems[i].contextItemType == ContextMenuContent.ContextItemType.Separator && cmManager.contextSeparator != null)
selectedItem = cmManager.contextSeparator;
else
{
Debug.LogError("<b>[Context Menu]</b> At least one of the item presets is missing. " +
"You can assign a new variable in Resources (Context Menu) tab. All default presets can be found in " +
"<b>Modern UI Pack > Prefabs > Context Menu</b> folder.", this);
nulLVariable = true;
}
if (nulLVariable == false)
{
GameObject go = Instantiate(selectedItem, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(itemParent, false);
if (cmContent.contexItems[subMenuIndex].subMenuItems[i].contextItemType == ContextMenuContent.ContextItemType.Button)
{
setItemText = go.GetComponentInChildren<TextMeshProUGUI>();
textHelper = cmContent.contexItems[subMenuIndex].subMenuItems[i].itemText;
setItemText.text = textHelper;
Transform goImage = go.gameObject.transform.Find("Icon");
setItemImage = goImage.GetComponent<Image>();
imageHelper = cmContent.contexItems[subMenuIndex].subMenuItems[i].itemIcon;
setItemImage.sprite = imageHelper;
if (imageHelper == null)
setItemImage.color = new Color(0, 0, 0, 0);
Button itemButton = go.GetComponent<Button>();
itemButton.onClick.AddListener(cmContent.contexItems[subMenuIndex].subMenuItems[i].onClick.Invoke);
itemButton.onClick.AddListener(CloseOnClick);
StartCoroutine(ExecuteAfterTime(0.01f));
}
}
}
if (cmManager.autoSubMenuPosition == true)
{
if (cmManager.bottomLeft == true) { listParent.pivot = new Vector2(0f, listParent.pivot.y); }
if (cmManager.bottomRight == true) { listParent.pivot = new Vector2(1f, listParent.pivot.y); }
if (cmManager.topLeft == true) { listParent.pivot = new Vector2(listParent.pivot.x, 0f); }
if (cmManager.topRight == true) { listParent.pivot = new Vector2(listParent.pivot.x, 1f); }
}
if (cmManager.subMenuBehaviour == ContextMenuManager.SubMenuBehaviour.Hover)
subMenuAnimator.Play("Menu In");
}
public void OnPointerExit(PointerEventData eventData)
{
#if !UNITY_2022_1_OR_NEWER
if (cmManager.subMenuBehaviour == ContextMenuManager.SubMenuBehaviour.Hover && !subMenuAnimator.GetCurrentAnimatorStateInfo(0).IsName("Start"))
subMenuAnimator.Play("Menu Out");
#endif
}
IEnumerator ExecuteAfterTime(float time)
{
yield return new WaitForSecondsRealtime(time);
itemParent.gameObject.SetActive(false);
itemParent.gameObject.SetActive(true);
StopCoroutine(ExecuteAfterTime(0.01f));
StopCoroutine("ExecuteAfterTime");
}
public void CloseOnClick()
{
cmManager.contextAnimator.Play("Menu Out");
cmManager.isOn = false;
trigger.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d93fb32bb7e8384d863c98e08445c2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9fd2bd6ff4a0be1448b7c7b9db99c03e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,226 @@
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace Michsky.MUIP
{
public class DemoElementSway : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
[Header("Resources")]
[SerializeField] private DemoElementSwayParent swayParent;
[SerializeField] private Canvas mainCanvas;
[SerializeField] private RectTransform swayObject;
[SerializeField] private CanvasGroup normalCG;
[SerializeField] private CanvasGroup highlightedCG;
[SerializeField] private CanvasGroup selectedCG;
[Header("Settings")]
[SerializeField] private float smoothness = 10;
[SerializeField] private float transitionSpeed = 8;
[SerializeField] [Range(0, 1)] private float dissolveAlpha = 0.5f;
[Header("Events")]
[SerializeField] private UnityEvent onClick;
bool allowSway;
[HideInInspector] public bool wmSelected;
Vector3 cursorPos;
Vector2 defaultPos;
void Awake()
{
if (swayParent == null)
{
var tempSway = transform.parent.GetComponent<DemoElementSwayParent>();
if (tempSway == null) { transform.parent.gameObject.AddComponent<DemoElementSwayParent>(); }
swayParent = tempSway;
}
defaultPos = swayObject.anchoredPosition;
normalCG.alpha = 1;
highlightedCG.alpha = 0;
}
void Update()
{
#if ENABLE_LEGACY_INPUT_MANAGER
if (allowSway == true) { cursorPos = Input.mousePosition; }
#elif ENABLE_INPUT_SYSTEM
if (allowSway == true) { cursorPos = Mouse.current.position.ReadValue(); }
#endif
if (mainCanvas.renderMode == RenderMode.ScreenSpaceOverlay) { ProcessOverlay(); }
else if (mainCanvas.renderMode == RenderMode.ScreenSpaceCamera) { ProcessSSC(); }
else if (mainCanvas.renderMode == RenderMode.WorldSpace) { ProcessWorldSpace(); }
}
void ProcessOverlay()
{
if (allowSway == true) { swayObject.position = Vector2.Lerp(swayObject.position, cursorPos, Time.deltaTime * smoothness); }
else { swayObject.localPosition = Vector2.Lerp(swayObject.localPosition, defaultPos, Time.deltaTime * smoothness); }
}
void ProcessSSC()
{
if (allowSway == true) { swayObject.position = Vector2.Lerp(swayObject.position, Camera.main.ScreenToWorldPoint(cursorPos), Time.deltaTime * smoothness); }
else { swayObject.localPosition = Vector2.Lerp(swayObject.localPosition, defaultPos, Time.deltaTime * smoothness); }
}
void ProcessWorldSpace()
{
if (allowSway == true)
{
Vector3 clampedPos = new Vector3(cursorPos.x, cursorPos.y, (mainCanvas.transform.position.z / 6f));
swayObject.position = Vector3.Lerp(swayObject.position, Camera.main.ScreenToWorldPoint(clampedPos), Time.deltaTime * smoothness);
}
else { swayObject.localPosition = Vector3.Lerp(swayObject.localPosition, defaultPos, Time.deltaTime * smoothness); }
}
public void Dissolve()
{
if (wmSelected == true)
return;
StopCoroutine("DissolveHelper");
StopCoroutine("HighlightHelper");
StopCoroutine("ActiveHelper");
StartCoroutine("DissolveHelper");
}
public void Highlight()
{
if (wmSelected == true)
return;
StopCoroutine("DissolveHelper");
StopCoroutine("HighlightHelper");
StopCoroutine("ActiveHelper");
StartCoroutine("HighlightHelper");
}
public void Active()
{
if (wmSelected == true)
return;
StopCoroutine("DissolveHelper");
StopCoroutine("HighlightHelper");
StopCoroutine("HighlightHelper");
StartCoroutine("ActiveHelper");
}
public void WindowManagerSelect()
{
wmSelected = true;
StopCoroutine("ActiveHelper");
StopCoroutine("HighlightHelper");
StartCoroutine("WMSelectHelper");
}
public void WindowManagerDeselect()
{
wmSelected = false;
StartCoroutine("WMDeselectHelper");
StartCoroutine("DissolveHelper");
}
public void OnPointerEnter(PointerEventData data)
{
allowSway = true;
swayParent.DissolveAll(this);
}
public void OnPointerExit(PointerEventData data)
{
allowSway = false;
swayParent.HighlightAll();
}
public void OnPointerClick(PointerEventData data)
{
onClick.Invoke();
}
IEnumerator DissolveHelper()
{
while (normalCG.alpha > dissolveAlpha)
{
normalCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
highlightedCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
yield return null;
}
highlightedCG.alpha = 0;
normalCG.alpha = dissolveAlpha;
highlightedCG.gameObject.SetActive(false);
}
IEnumerator HighlightHelper()
{
while (normalCG.alpha < 1)
{
normalCG.alpha += Time.unscaledDeltaTime * transitionSpeed;
highlightedCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
yield return null;
}
normalCG.alpha = 1;
highlightedCG.alpha = 0;
highlightedCG.gameObject.SetActive(false);
}
IEnumerator ActiveHelper()
{
highlightedCG.gameObject.SetActive(true);
while (highlightedCG.alpha < 1)
{
normalCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
highlightedCG.alpha += Time.unscaledDeltaTime * transitionSpeed;
yield return null;
}
highlightedCG.alpha = 1;
normalCG.alpha = 0;
}
IEnumerator WMSelectHelper()
{
selectedCG.gameObject.SetActive(true);
while (selectedCG.alpha < 1)
{
normalCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
highlightedCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
selectedCG.alpha += Time.unscaledDeltaTime * transitionSpeed;
yield return null;
}
highlightedCG.alpha = 0;
normalCG.alpha = 0;
selectedCG.alpha = 1;
}
IEnumerator WMDeselectHelper()
{
while (selectedCG.alpha > 0)
{
selectedCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
yield return null;
}
selectedCG.alpha = 0;
selectedCG.gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7afc8c12ad2e104ebc86906fc37ec31
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
namespace Michsky.MUIP
{
public class DemoElementSwayParent : MonoBehaviour
{
[SerializeField] private Animator titleAnimator;
[SerializeField] private TextMeshProUGUI elementTitle;
[SerializeField] private TextMeshProUGUI elementTitleHelper;
private List<DemoElementSway> elements = new List<DemoElementSway>();
private int prevIndex;
void Awake()
{
foreach (Transform child in transform)
{
elements.Add(child.GetComponent<DemoElementSway>());
}
}
public void DissolveAll(DemoElementSway currentSway)
{
for (int i = 0; i < elements.Count; ++i)
{
if (elements[i] == currentSway)
{
elements[i].Active();
continue;
}
elements[i].Dissolve();
}
}
public void HighlightAll()
{
for (int i = 0; i < elements.Count; ++i)
{
elements[i].Highlight();
}
}
public void SetWindowManagerButton(int index)
{
if (elements.Count == 0)
{
StartCoroutine("SWMHelper", index);
return;
}
for (int i = 0; i < elements.Count; ++i)
{
if (i == index) { elements[i].WindowManagerSelect(); }
else
{
if (elements[i].wmSelected == false) { continue; }
elements[i].WindowManagerDeselect();
}
}
if (titleAnimator == null)
return;
elementTitleHelper.text = elements[prevIndex].gameObject.name;
elementTitle.text = elements[index].gameObject.name;
titleAnimator.Play("Idle");
titleAnimator.Play("Transition");
prevIndex = index;
}
IEnumerator SWMHelper(int index)
{
yield return new WaitForSeconds(0.1f);
SetWindowManagerButton(index);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5fa48de8543315549bf27cc38c7eceea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,135 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace Michsky.MUIP
{
public class DemoListShadow : MonoBehaviour, IBeginDragHandler
{
[Header("Resources")]
[SerializeField] private Scrollbar listScrollbar;
[SerializeField] private CanvasGroup leftCG;
[SerializeField] private CanvasGroup rightCG;
[Header("Settings")]
[SerializeField] private float scrollTime = 5;
[SerializeField] private float transitionSpeed = 4;
void Awake()
{
CheckForValue(0);
}
public void CheckForValue(float value)
{
if (value > 0.05)
{
StopCoroutine("LeftCGFadeOut");
StartCoroutine("LeftCGFadeIn");
}
else
{
StopCoroutine("LeftCGFadeIn");
StartCoroutine("LeftCGFadeOut");
}
if (value < 0.95)
{
StopCoroutine("RightCGFadeOut");
StartCoroutine("RightCGFadeIn");
}
else
{
StopCoroutine("RightCGFadeIn");
StartCoroutine("RightCGFadeOut");
}
}
public void ScrollUp() { StopCoroutine("ScrollDownHelper"); StartCoroutine("ScrollUpHelper"); }
public void ScrollDown() { StopCoroutine("ScrollUpHelper"); StartCoroutine("ScrollDownHelper"); }
public void OnBeginDrag(PointerEventData data) { StopCoroutine("ScrollUpHelper"); StopCoroutine("ScrollDownHelper"); }
IEnumerator ScrollUpHelper()
{
float elapsedTime = 0;
while (elapsedTime < scrollTime)
{
listScrollbar.value = Mathf.Lerp(listScrollbar.value, 0, elapsedTime / scrollTime);
elapsedTime += Time.unscaledDeltaTime;
yield return new WaitForEndOfFrame();
}
}
IEnumerator ScrollDownHelper()
{
float elapsedTime = 0;
while (elapsedTime < scrollTime)
{
listScrollbar.value = Mathf.Lerp(listScrollbar.value, 1, elapsedTime / scrollTime);
elapsedTime += Time.unscaledDeltaTime;
yield return new WaitForEndOfFrame();
}
}
IEnumerator LeftCGFadeIn()
{
leftCG.interactable = true;
leftCG.blocksRaycasts = true;
while (leftCG.alpha < 0.99f)
{
leftCG.alpha += Time.unscaledDeltaTime * transitionSpeed;
yield return new WaitForEndOfFrame();
}
leftCG.alpha = 1;
}
IEnumerator LeftCGFadeOut()
{
leftCG.interactable = false;
leftCG.blocksRaycasts = false;
while (leftCG.alpha > 0.01f)
{
leftCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
yield return new WaitForEndOfFrame();
}
leftCG.alpha = 0;
}
IEnumerator RightCGFadeIn()
{
rightCG.interactable = true;
rightCG.blocksRaycasts = true;
while (rightCG.alpha < 0.99f)
{
rightCG.alpha += Time.unscaledDeltaTime * transitionSpeed;
yield return new WaitForEndOfFrame();
}
rightCG.alpha = 1;
}
IEnumerator RightCGFadeOut()
{
rightCG.interactable = false;
rightCG.blocksRaycasts = false;
while (rightCG.alpha > 0.01f)
{
rightCG.alpha -= Time.unscaledDeltaTime * transitionSpeed;
yield return new WaitForEndOfFrame();
}
rightCG.alpha = 0;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e373f9a5f6c9bab449c78beab64a8d53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
using UnityEngine;
using UnityEngine.EventSystems;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.UI;
#endif
namespace Michsky.MUIP
{
public class InputSystemChecker : MonoBehaviour
{
void Awake()
{
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
InputSystemUIInputModule tempModule = gameObject.GetComponent<InputSystemUIInputModule>();
if (tempModule == null)
{
Debug.LogError("<b>[Modern UI Pack]</b> Input System is enabled, but <b>'Input System UI Input Module'</b> is missing. " +
"Select the event system object, and click the <b>'Replace'</b> button.");
}
#endif
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1dfe135108c08d54d8978d026b05b601
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
using UnityEngine;
namespace Michsky.MUIP
{
public class LaunchURL : MonoBehaviour
{
public void GoToURL(string URL)
{
Application.OpenURL(URL);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 731973609e4a7a94aa4d2f33c86dc13f
timeCreated: 1493639454
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f0673eef6087e6b41af2be453632efb5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,386 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using TMPro;
using System.Collections;
namespace Michsky.MUIP
{
public class CustomDropdown : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler, IPointerClickHandler, ISubmitHandler
{
// Resources
public Animator dropdownAnimator;
public GameObject triggerObject;
public TextMeshProUGUI selectedText;
public Image selectedImage;
public Transform itemParent;
public GameObject itemObject;
public GameObject scrollbar;
public VerticalLayoutGroup itemList;
public Transform listParent;
public AudioSource soundSource;
[HideInInspector] public Transform currentListParent;
public RectTransform listRect;
public CanvasGroup listCG;
public CanvasGroup contentCG;
// Settings
public bool isInteractable = true;
public bool enableIcon = true;
public bool enableTrigger = true;
public bool enableScrollbar = true;
public bool updateOnEnable = true;
public bool outOnPointerExit = false;
public bool setHighPriority = true;
public bool invokeAtStart = false;
public bool initAtStart = true;
public bool enableDropdownSounds = false;
public bool useHoverSound = true;
public bool useClickSound = true;
[Range(1, 50)] public int itemPaddingTop = 8;
[Range(1, 50)] public int itemPaddingBottom = 8;
[Range(1, 50)] public int itemPaddingLeft = 8;
[Range(1, 50)] public int itemPaddingRight = 25;
[Range(1, 50)] public int itemSpacing = 8;
public int selectedItemIndex = 0;
// Animation
public AnimationType animationType;
public PanelDirection panelDirection;
[Range(25, 1000)] public float panelSize = 200;
[Range(0.5f, 10)] public float curveSpeed = 3;
public AnimationCurve animationCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f));
// Saving
public bool saveSelected = false;
public string saveKey = "My Dropdown";
// Item list
[SerializeField]
public List<Item> items = new List<Item>();
// Events
[System.Serializable] public class DropdownEvent : UnityEvent<int> { }
public DropdownEvent onValueChanged;
[System.Serializable] public class ItemTextChangedEvent : UnityEvent<TMP_Text> { }
public ItemTextChangedEvent onItemTextChanged;
// Audio
public AudioClip hoverSound;
public AudioClip clickSound;
// Other variables
[HideInInspector] public bool isOn;
[HideInInspector] public int index = 0;
[HideInInspector] public int siblingIndex = 0;
[HideInInspector] public TextMeshProUGUI setItemText;
[HideInInspector] public Image setItemImage;
EventTrigger triggerEvent;
Sprite imageHelper;
string textHelper;
#if UNITY_EDITOR
public bool extendEvents = false;
#endif
public enum AnimationType { Modular, Custom }
public enum PanelDirection { Bottom, Top }
[System.Serializable]
public class Item
{
public string itemName = "Dropdown Item";
public Sprite itemIcon;
[HideInInspector] public int itemIndex;
public UnityEvent OnItemSelection = new UnityEvent();
}
void Awake()
{
if (enableTrigger == true && triggerObject != null)
{
// triggerButton = gameObject.GetComponent<Button>();
triggerEvent = triggerObject.AddComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerClick;
entry.callback.AddListener((eventData) => { Animate(); });
triggerEvent.GetComponent<EventTrigger>().triggers.Add(entry);
}
if (setHighPriority == true)
{
if (contentCG == null) { contentCG = transform.Find("Content/Item List").GetComponent<CanvasGroup>(); }
contentCG.alpha = 1;
Canvas tempCanvas = contentCG.gameObject.AddComponent<Canvas>();
tempCanvas.overrideSorting = true;
tempCanvas.sortingOrder = 30000;
contentCG.gameObject.AddComponent<GraphicRaycaster>();
}
if (initAtStart == true && items.Count != 0) { SetupDropdown(); }
}
void Start()
{
if (animationType == AnimationType.Custom) { return; }
else if (animationType == AnimationType.Modular && dropdownAnimator != null) { Destroy(dropdownAnimator); }
}
void OnEnable()
{
if (listCG == null) { listCG = gameObject.GetComponentInChildren<CanvasGroup>(); }
if (listRect == null) { listRect = listCG.GetComponent<RectTransform>(); }
if (updateOnEnable == true && index < items.Count) { SetDropdownIndex(selectedItemIndex); }
listCG.alpha = 0;
listCG.interactable = false;
listCG.blocksRaycasts = false;
listRect.sizeDelta = new Vector2(listRect.sizeDelta.x, 0);
}
public void SetupDropdown()
{
if (dropdownAnimator == null) { dropdownAnimator = gameObject.GetComponent<Animator>(); }
if (enableScrollbar == false && scrollbar != null) { Destroy(scrollbar); }
if (itemList == null) { itemList = itemParent.GetComponent<VerticalLayoutGroup>(); }
UpdateItemLayout();
index = 0;
foreach (Transform child in itemParent) { Destroy(child.gameObject); }
for (int i = 0; i < items.Count; ++i)
{
GameObject go = Instantiate(itemObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(itemParent, false);
go.name = items[i].itemName;
setItemText = go.GetComponentInChildren<TextMeshProUGUI>();
textHelper = items[i].itemName;
setItemText.text = textHelper;
onItemTextChanged?.Invoke(setItemText);
Transform goImage = go.gameObject.transform.Find("Icon");
setItemImage = goImage.GetComponent<Image>();
if (items[i].itemIcon == null) { setItemImage.gameObject.SetActive(false); }
else { imageHelper = items[i].itemIcon; setItemImage.sprite = imageHelper; }
items[i].itemIndex = i;
Item mainItem = items[i];
Button itemButton = go.GetComponent<Button>();
itemButton.onClick.AddListener(Animate);
itemButton.onClick.AddListener(items[i].OnItemSelection.Invoke);
itemButton.onClick.AddListener(delegate
{
SetDropdownIndex(index = mainItem.itemIndex);
onValueChanged.Invoke(index = mainItem.itemIndex);
if (saveSelected == true) { PlayerPrefs.SetInt("Dropdown_" + saveKey, mainItem.itemIndex); }
});
}
if (selectedImage != null && enableIcon == false) { selectedImage.gameObject.SetActive(false); }
else if (selectedImage != null) { selectedImage.sprite = items[selectedItemIndex].itemIcon; }
if (selectedText != null) { selectedText.text = items[selectedItemIndex].itemName; onItemTextChanged?.Invoke(selectedText); }
if (saveSelected == true)
{
if (invokeAtStart == true) { items[PlayerPrefs.GetInt("Dropdown_" + saveKey)].OnItemSelection.Invoke(); }
else { SetDropdownIndex(PlayerPrefs.GetInt("Dropdown_" + saveKey)); }
}
else if (invokeAtStart == true) { items[selectedItemIndex].OnItemSelection.Invoke(); }
currentListParent = transform.parent;
}
// Obsolete
public void ChangeDropdownInfo(int itemIndex) { SetDropdownIndex(itemIndex); }
public void SetDropdownIndex(int itemIndex)
{
if (selectedImage != null && enableIcon == true && items[itemIndex].itemIcon != null) { selectedImage.gameObject.SetActive(true); selectedImage.sprite = items[itemIndex].itemIcon; }
else if (selectedImage != null && enableIcon == true && items[itemIndex].itemIcon == null) { selectedImage.gameObject.SetActive(false); }
if (selectedText != null) { selectedText.text = items[itemIndex].itemName; onItemTextChanged?.Invoke(selectedText); }
if (enableDropdownSounds == true && useClickSound == true) { soundSource.PlayOneShot(clickSound); }
selectedItemIndex = itemIndex;
}
public void Animate()
{
if (isOn == false && animationType == AnimationType.Modular)
{
isOn = true;
listCG.blocksRaycasts = true;
listCG.interactable = true;
listCG.gameObject.SetActive(true);
StopCoroutine("StartMinimize");
StopCoroutine("StartExpand");
StartCoroutine("StartExpand");
}
else if (isOn == true && animationType == AnimationType.Modular)
{
isOn = false;
listCG.blocksRaycasts = false;
listCG.interactable = false;
StopCoroutine("StartMinimize");
StopCoroutine("StartExpand");
StartCoroutine("StartMinimize");
}
else if (isOn == false && animationType == AnimationType.Custom)
{
dropdownAnimator.Play("Stylish In");
isOn = true;
StopCoroutine("StartMinimize");
StopCoroutine("StartExpand");
StartCoroutine("StartMinimize");
}
else if (isOn == true && animationType == AnimationType.Custom)
{
dropdownAnimator.Play("Stylish Out");
isOn = false;
StopCoroutine("StartMinimize");
StopCoroutine("StartExpand");
StartCoroutine("StartMinimize");
}
if (enableTrigger == true && isOn == false) { triggerObject.SetActive(false); }
else if (enableTrigger == true && isOn == true) { triggerObject.SetActive(true); }
if (enableTrigger == true && outOnPointerExit == true) { triggerObject.SetActive(false); }
}
public void Interactable(bool value)
{
isInteractable = value;
}
public void CreateNewItem(string title, Sprite icon, bool notify)
{
Item item = new Item();
item.itemName = title;
item.itemIcon = icon;
items.Add(item);
if (notify == true) { SetupDropdown(); }
}
public void CreateNewItem(string title, bool notify)
{
Item item = new Item();
item.itemName = title;
items.Add(item);
if (notify == true) { SetupDropdown(); }
}
public void CreateNewItem(string title)
{
Item item = new Item();
item.itemName = title;
items.Add(item);
SetupDropdown();
}
public void RemoveItem(string itemTitle, bool notify)
{
var item = items.Find(x => x.itemName == itemTitle);
items.Remove(item);
if (notify == true) { SetupDropdown(); }
}
public void RemoveItem(string itemTitle)
{
var item = items.Find(x => x.itemName == itemTitle);
items.Remove(item);
SetupDropdown();
}
public void UpdateItemLayout()
{
if (itemList == null)
return;
itemList.spacing = itemSpacing;
itemList.padding.top = itemPaddingTop;
itemList.padding.bottom = itemPaddingBottom;
itemList.padding.left = itemPaddingLeft;
itemList.padding.right = itemPaddingRight;
}
public void OnPointerClick(PointerEventData eventData)
{
if (isInteractable == false) { return; }
if (enableDropdownSounds == true && useClickSound == true) { soundSource.PlayOneShot(clickSound); }
Animate();
}
public void OnPointerEnter(PointerEventData eventData)
{
if (isInteractable == false) { return; }
if (enableDropdownSounds == true && useHoverSound == true) { soundSource.PlayOneShot(hoverSound); }
}
public void OnPointerExit(PointerEventData eventData)
{
if (isInteractable == false) { return; }
if (outOnPointerExit == true && isOn == true) { Animate(); isOn = false; }
}
public void OnSubmit(BaseEventData eventData)
{
if (isInteractable == false) { return; }
if (enableDropdownSounds == true && useClickSound == true) { soundSource.PlayOneShot(clickSound); }
Animate();
}
IEnumerator StartExpand()
{
float elapsedTime = 0;
Vector2 startPos = listRect.sizeDelta;
Vector2 endPos = new Vector2(listRect.sizeDelta.x, panelSize);
while (listRect.sizeDelta.y <= panelSize - 0.1f)
{
elapsedTime += Time.unscaledDeltaTime;
listCG.alpha += Time.unscaledDeltaTime * (curveSpeed * 2);
listRect.sizeDelta = Vector2.Lerp(startPos, endPos, animationCurve.Evaluate(elapsedTime * curveSpeed));
yield return null;
}
listCG.alpha = 1;
listRect.sizeDelta = endPos;
}
IEnumerator StartMinimize()
{
float elapsedTime = 0;
Vector2 startPos = listRect.sizeDelta;
Vector2 endPos = new Vector2(listRect.sizeDelta.x, 0);
while (listRect.sizeDelta.y >= 0.1f)
{
elapsedTime += Time.unscaledDeltaTime;
listCG.alpha -= Time.unscaledDeltaTime * (curveSpeed * 2);
listRect.sizeDelta = Vector2.Lerp(startPos, endPos, animationCurve.Evaluate(elapsedTime * curveSpeed));
yield return null;
}
listCG.alpha = 0;
listRect.sizeDelta = endPos;
listCG.gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3c6e5718ae5e9246af72590402986a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 0a39a4452fd810640afd1be6e700edee, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,321 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(CustomDropdown))]
public class CustomDropdownEditor : Editor
{
private GUISkin customSkin;
private CustomDropdown dTarget;
private UIManagerDropdown tempUIM;
private int currentTab;
private void OnEnable()
{
dTarget = (CustomDropdown)target;
try { tempUIM = dTarget.GetComponent<UIManagerDropdown>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
if (dTarget.selectedItemIndex > dTarget.items.Count - 1) { dTarget.selectedItemIndex = 0; }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "Dropdown 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 items = serializedObject.FindProperty("items");
var onValueChanged = serializedObject.FindProperty("onValueChanged");
var onItemTextChanged = serializedObject.FindProperty("onItemTextChanged");
var triggerObject = serializedObject.FindProperty("triggerObject");
var selectedText = serializedObject.FindProperty("selectedText");
var selectedImage = serializedObject.FindProperty("selectedImage");
var itemParent = serializedObject.FindProperty("itemParent");
var itemObject = serializedObject.FindProperty("itemObject");
var scrollbar = serializedObject.FindProperty("scrollbar");
var listParent = serializedObject.FindProperty("listParent");
var listRect = serializedObject.FindProperty("listRect");
var listCG = serializedObject.FindProperty("listCG");
var animationType = serializedObject.FindProperty("animationType");
var panelDirection = serializedObject.FindProperty("panelDirection");
var panelSize = serializedObject.FindProperty("panelSize");
var curveSpeed = serializedObject.FindProperty("curveSpeed");
var animationCurve = serializedObject.FindProperty("animationCurve");
var saveSelected = serializedObject.FindProperty("saveSelected");
var saveKey = serializedObject.FindProperty("saveKey");
var enableIcon = serializedObject.FindProperty("enableIcon");
var enableTrigger = serializedObject.FindProperty("enableTrigger");
var enableScrollbar = serializedObject.FindProperty("enableScrollbar");
var outOnPointerExit = serializedObject.FindProperty("outOnPointerExit");
var setHighPriority = serializedObject.FindProperty("setHighPriority");
var invokeAtStart = serializedObject.FindProperty("invokeAtStart");
var initAtStart = serializedObject.FindProperty("initAtStart");
var selectedItemIndex = serializedObject.FindProperty("selectedItemIndex");
var enableDropdownSounds = serializedObject.FindProperty("enableDropdownSounds");
var useHoverSound = serializedObject.FindProperty("useHoverSound");
var useClickSound = serializedObject.FindProperty("useClickSound");
var hoverSound = serializedObject.FindProperty("hoverSound");
var clickSound = serializedObject.FindProperty("clickSound");
var soundSource = serializedObject.FindProperty("soundSource");
var itemSpacing = serializedObject.FindProperty("itemSpacing");
var itemPaddingLeft = serializedObject.FindProperty("itemPaddingLeft");
var itemPaddingRight = serializedObject.FindProperty("itemPaddingRight");
var itemPaddingTop = serializedObject.FindProperty("itemPaddingTop");
var itemPaddingBottom = serializedObject.FindProperty("itemPaddingBottom");
var extendEvents = serializedObject.FindProperty("extendEvents");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
if (Application.isPlaying == false && dTarget.items.Count != 0)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
GUI.enabled = false;
EditorGUILayout.LabelField(new GUIContent("Selected Item:"), customSkin.FindStyle("Text"), GUILayout.Width(78));
GUI.enabled = true;
EditorGUILayout.LabelField(new GUIContent(dTarget.items[selectedItemIndex.intValue].itemName), customSkin.FindStyle("Text"));
GUILayout.EndHorizontal();
GUILayout.Space(2);
selectedItemIndex.intValue = EditorGUILayout.IntSlider(selectedItemIndex.intValue, 0, dTarget.items.Count - 1);
GUILayout.EndVertical();
}
else if (Application.isPlaying == true && dTarget.items.Count != 0)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
GUI.enabled = false;
EditorGUILayout.LabelField(new GUIContent("Current Item:"), customSkin.FindStyle("Text"), GUILayout.Width(74));
EditorGUILayout.LabelField(new GUIContent(dTarget.items[dTarget.selectedItemIndex].itemName), customSkin.FindStyle("Text"));
GUILayout.EndHorizontal();
GUILayout.Space(2);
EditorGUILayout.IntSlider(dTarget.index, 0, dTarget.items.Count - 1);
GUI.enabled = true;
GUILayout.EndVertical();
}
else { EditorGUILayout.HelpBox("There is no item in the list.", MessageType.Warning); }
GUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(items, new GUIContent("Dropdown Items"), true);
EditorGUI.indentLevel = 0;
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"), true);
if (extendEvents.boolValue == true)
{
EditorGUILayout.PropertyField(onItemTextChanged, new GUIContent("On Item Text Changed"), true);
}
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(triggerObject, customSkin, "Trigger Object");
MUIPEditorHandler.DrawProperty(selectedText, customSkin, "Selected Text");
MUIPEditorHandler.DrawProperty(selectedImage, customSkin, "Selected Image");
MUIPEditorHandler.DrawProperty(itemObject, customSkin, "Item Prefab");
MUIPEditorHandler.DrawProperty(itemParent, customSkin, "Item Parent");
MUIPEditorHandler.DrawProperty(scrollbar, customSkin, "Scrollbar");
if (dTarget.animationType == CustomDropdown.AnimationType.Modular)
{
MUIPEditorHandler.DrawProperty(listRect, customSkin, "List Rect");
MUIPEditorHandler.DrawProperty(listCG, customSkin, "List Canvas Group");
}
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Customization Header", 6);
enableIcon.boolValue = MUIPEditorHandler.DrawToggle(enableIcon.boolValue, customSkin, "Enable Header Icon");
enableScrollbar.boolValue = MUIPEditorHandler.DrawToggle(enableScrollbar.boolValue, customSkin, "Enable Scrollbar");
extendEvents.boolValue = MUIPEditorHandler.DrawToggle(extendEvents.boolValue, customSkin, "Extend Events");
MUIPEditorHandler.DrawPropertyCW(itemSpacing, customSkin, "Item Spacing", 90);
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Item Padding"), customSkin.FindStyle("Text"), GUILayout.Width(90));
GUILayout.EndHorizontal();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(itemPaddingTop, new GUIContent("Top"));
EditorGUILayout.PropertyField(itemPaddingBottom, new GUIContent("Bottom"));
EditorGUILayout.PropertyField(itemPaddingLeft, new GUIContent("Left"));
EditorGUILayout.PropertyField(itemPaddingRight, new GUIContent("Right"));
EditorGUI.indentLevel = 0;
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Animation Header", 10);
MUIPEditorHandler.DrawProperty(animationType, customSkin, "Animation Type");
if (dTarget.animationType == CustomDropdown.AnimationType.Modular)
{
// MUIPEditorHandler.DrawProperty(panelDirection, customSkin, "Panel Direction");
MUIPEditorHandler.DrawProperty(panelSize, customSkin, "Panel Size");
MUIPEditorHandler.DrawProperty(curveSpeed, customSkin, "Curve Speed");
MUIPEditorHandler.DrawProperty(animationCurve, customSkin, "Animation Curve");
}
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 10);
initAtStart.boolValue = MUIPEditorHandler.DrawToggle(initAtStart.boolValue, customSkin, "Initialize At Start");
invokeAtStart.boolValue = MUIPEditorHandler.DrawToggle(invokeAtStart.boolValue, customSkin, "Invoke At Start");
if (dTarget.selectedImage != null)
{
if (enableIcon.boolValue == true) { dTarget.selectedImage.enabled = true; }
else { dTarget.selectedImage.enabled = false; }
}
else
{
if (enableIcon.boolValue == true)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Selected Image' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
}
enableTrigger.boolValue = MUIPEditorHandler.DrawToggle(enableTrigger.boolValue, customSkin, "Enable Trigger");
if (enableTrigger.boolValue == true && dTarget.triggerObject == null) { EditorGUILayout.HelpBox("'Trigger Object' is missing from the resources.", MessageType.Warning); }
setHighPriority.boolValue = MUIPEditorHandler.DrawToggle(setHighPriority.boolValue, customSkin, "Set High Priority");
if (setHighPriority.boolValue == true) { EditorGUILayout.HelpBox("Set High Priority; renders the content above all objects when the dropdown is open.", MessageType.Info); }
outOnPointerExit.boolValue = MUIPEditorHandler.DrawToggle(outOnPointerExit.boolValue, customSkin, "Out On Pointer Exit");
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
enableDropdownSounds.boolValue = MUIPEditorHandler.DrawTogglePlain(enableDropdownSounds.boolValue, customSkin, "Enable Dropdown Sounds");
GUILayout.Space(3);
if (enableDropdownSounds.boolValue == true)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
useHoverSound.boolValue = MUIPEditorHandler.DrawTogglePlain(useHoverSound.boolValue, customSkin, "Enable Hover Sound");
GUILayout.Space(3);
if (useHoverSound.boolValue == true)
MUIPEditorHandler.DrawProperty(hoverSound, customSkin, "Hover Sound");
GUILayout.EndVertical();
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
useClickSound.boolValue = MUIPEditorHandler.DrawTogglePlain(useClickSound.boolValue, customSkin, "Enable Click Sound");
GUILayout.Space(3);
if (useClickSound.boolValue == true)
MUIPEditorHandler.DrawProperty(clickSound, customSkin, "Click Sound");
GUILayout.EndVertical();
MUIPEditorHandler.DrawProperty(soundSource, customSkin, "Sound Source");
if (dTarget.soundSource == null)
{
EditorGUILayout.HelpBox("'Sound Source' is not assigned. Go to Resources tab or click the button to create a new audio source.", MessageType.Warning);
if (GUILayout.Button("+ Create a new one", customSkin.button))
{
dTarget.soundSource = dTarget.gameObject.AddComponent(typeof(AudioSource)) as AudioSource;
currentTab = 2;
}
}
}
GUILayout.EndVertical();
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
saveSelected.boolValue = MUIPEditorHandler.DrawTogglePlain(saveSelected.boolValue, customSkin, "Save Selected");
GUILayout.Space(3);
if (saveSelected.boolValue == true)
{
MUIPEditorHandler.DrawPropertyPlainCW(saveKey, customSkin, "Save Key:", 90);
EditorGUILayout.HelpBox("Each dropdown should has its own save key.", MessageType.Info);
}
GUILayout.EndVertical();
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>[Dropdown]</b> Failed to delete UI Manager connection.", this); }
}
}
}
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 227402b59bd462249a7f83d4fee619fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,310 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using TMPro;
namespace Michsky.MUIP
{
public class DropdownMultiSelect : MonoBehaviour, IPointerExitHandler, IPointerClickHandler
{
// Resources
public GameObject triggerObject;
public Transform itemParent;
public GameObject itemObject;
public GameObject scrollbar;
private VerticalLayoutGroup itemList;
private Transform currentListParent;
public Transform listParent;
private Animator dropdownAnimator;
public TextMeshProUGUI setItemText;
// Settings
public bool isInteractable = true;
public bool initAtStart = true;
public bool enableIcon = true;
public bool enableTrigger = true;
public bool enableScrollbar = true;
public bool setHighPriorty = true;
public bool outOnPointerExit = false;
public bool isListItem = false;
public bool invokeAtStart = false;
[Range(1, 50)] public int itemPaddingTop = 8;
[Range(1, 50)] public int itemPaddingBottom = 8;
[Range(1, 50)] public int itemPaddingLeft = 8;
[Range(1, 50)] public int itemPaddingRight = 25;
[Range(1, 50)] public int itemSpacing = 8;
// Animation
public AnimationType animationType;
[Range(1, 25)] public float transitionSmoothness = 10;
[Range(1, 25)] public float sizeSmoothness = 15;
public float panelSize = 200;
public RectTransform listRect;
public CanvasGroup listCG;
bool isInTransition = false;
float closeOn;
// Items
[SerializeField]
public List<Item> items = new List<Item>();
// Other variables
int currentIndex;
Toggle currentToggle;
string textHelper;
bool isOn;
public int siblingIndex = 0;
EventTrigger triggerEvent;
[System.Serializable]
public class ToggleEvent : UnityEvent<bool> { }
public enum AnimationType { Modular, Stylish }
[System.Serializable]
public class Item
{
public string itemName = "Dropdown Item";
public bool isOn;
[HideInInspector] public int itemIndex;
[SerializeField] public ToggleEvent onValueChanged = new ToggleEvent();
}
void OnEnable()
{
if (animationType == AnimationType.Stylish) { return; }
else if (animationType == AnimationType.Modular && dropdownAnimator != null) { Destroy(dropdownAnimator); }
if (listCG == null) { listCG = gameObject.GetComponentInChildren<CanvasGroup>(); }
listCG.alpha = 0;
listCG.interactable = false;
listCG.blocksRaycasts = false;
if (listRect == null) { listRect = listCG.GetComponent<RectTransform>(); }
closeOn = gameObject.GetComponent<RectTransform>().sizeDelta.y;
listRect.sizeDelta = new Vector2(listRect.sizeDelta.x, closeOn);
}
void Awake()
{
if (initAtStart == true) { SetupDropdown(); }
currentListParent = transform.parent;
if (enableTrigger == true && triggerObject != null)
{
// triggerButton = gameObject.GetComponent<Button>();
triggerEvent = triggerObject.AddComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerClick;
entry.callback.AddListener((eventData) => { Animate(); });
triggerEvent.GetComponent<EventTrigger>().triggers.Add(entry);
}
}
void Update()
{
if (isInTransition == false)
return;
ProcessModularAnimation();
}
void ProcessModularAnimation()
{
if (isOn == true)
{
listCG.alpha += Time.unscaledDeltaTime * transitionSmoothness;
listRect.sizeDelta = Vector2.Lerp(listRect.sizeDelta, new Vector2(listRect.sizeDelta.x, panelSize), Time.unscaledDeltaTime * sizeSmoothness);
if (listRect.sizeDelta.y >= panelSize - 0.1f && listCG.alpha >= 1) { isInTransition = false; }
}
else
{
listCG.alpha -= Time.unscaledDeltaTime * transitionSmoothness;
listRect.sizeDelta = Vector2.Lerp(listRect.sizeDelta, new Vector2(listRect.sizeDelta.x, closeOn), Time.unscaledDeltaTime * sizeSmoothness);
if (listRect.sizeDelta.y <= closeOn + 0.1f && listCG.alpha <= 0) { isInTransition = false; this.enabled = false; }
}
}
public void SetupDropdown()
{
if (dropdownAnimator == null) { dropdownAnimator = gameObject.GetComponent<Animator>(); }
if (enableScrollbar == false && scrollbar != null) { Destroy(scrollbar); }
if (setHighPriorty == true) { transform.SetAsLastSibling(); }
if (itemList == null) { itemList = itemParent.GetComponent<VerticalLayoutGroup>(); }
UpdateItemLayout();
foreach (Transform child in itemParent) { Destroy(child.gameObject); }
for (int i = 0; i < items.Count; ++i)
{
GameObject go = Instantiate(itemObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(itemParent, false);
setItemText = go.GetComponentInChildren<TextMeshProUGUI>();
textHelper = items[i].itemName;
setItemText.text = textHelper;
items[i].itemIndex = i;
DropdownMultiSelect.Item mainItem = items[i];
Toggle itemToggle = go.GetComponent<Toggle>();
itemToggle.onValueChanged.AddListener(delegate { UpdateToggleData(mainItem.itemIndex); });
itemToggle.onValueChanged.AddListener(UpdateToggle);
itemToggle.onValueChanged.AddListener(items[i].onValueChanged.Invoke);
if (items[i].isOn == true) { itemToggle.isOn = true; }
else { itemToggle.isOn = false; }
if (invokeAtStart == true)
{
if (items[i].isOn == true) { items[i].onValueChanged.Invoke(true); }
else { items[i].onValueChanged.Invoke(false); }
}
}
currentListParent = transform.parent;
}
void UpdateToggle(bool value)
{
if (value == true) { currentToggle.isOn = true; items[currentIndex].isOn = true; }
else { currentToggle.isOn = false; items[currentIndex].isOn = false; }
}
void UpdateToggleData(int itemIndex)
{
currentIndex = itemIndex;
currentToggle = itemParent.GetChild(currentIndex).GetComponent<Toggle>();
}
public void Animate()
{
if (isOn == false && animationType == AnimationType.Modular)
{
isOn = true;
isInTransition = true;
this.enabled = true;
listCG.blocksRaycasts = true;
listCG.interactable = true;
if (isListItem == true)
{
siblingIndex = transform.GetSiblingIndex();
gameObject.transform.SetParent(listParent, true);
}
}
else if (isOn == true && animationType == AnimationType.Modular)
{
isOn = false;
isInTransition = true;
this.enabled = true;
listCG.blocksRaycasts = false;
listCG.interactable = false;
if (isListItem == true)
{
gameObject.transform.SetParent(currentListParent, true);
gameObject.transform.SetSiblingIndex(siblingIndex);
}
}
else if (isOn == false && animationType == AnimationType.Stylish)
{
dropdownAnimator.Play("Stylish In");
isOn = true;
if (isListItem == true)
{
siblingIndex = transform.GetSiblingIndex();
gameObject.transform.SetParent(listParent, true);
}
}
else if (isOn == true && animationType == AnimationType.Stylish)
{
dropdownAnimator.Play("Stylish Out");
isOn = false;
if (isListItem == true)
{
gameObject.transform.SetParent(currentListParent, true);
gameObject.transform.SetSiblingIndex(siblingIndex);
}
}
if (enableTrigger == true && isOn == false) { triggerObject.SetActive(false); }
else if (enableTrigger == true && isOn == true) { triggerObject.SetActive(true); }
if (enableTrigger == true && outOnPointerExit == true) { triggerObject.SetActive(false); }
if (setHighPriorty == true) { transform.SetAsLastSibling(); }
}
public void CreateNewItem(string title, bool value, bool notify)
{
Item item = new Item();
item.itemName = title;
item.isOn = value;
items.Add(item);
if (notify == true) { SetupDropdown(); }
}
public void CreateNewItem(string title, bool value)
{
Item item = new Item();
item.itemName = title;
item.isOn = value;
items.Add(item);
SetupDropdown();
}
public void CreateNewItem(string title)
{
Item item = new Item();
item.itemName = title;
items.Add(item);
}
public void RemoveItem(string itemTitle)
{
var item = items.Find(x => x.itemName == itemTitle);
items.Remove(item);
SetupDropdown();
}
public void UpdateItemLayout()
{
if (itemList != null)
{
itemList.spacing = itemSpacing;
itemList.padding.top = itemPaddingTop;
itemList.padding.bottom = itemPaddingBottom;
itemList.padding.left = itemPaddingLeft;
itemList.padding.right = itemPaddingRight;
}
}
public void OnPointerClick(PointerEventData eventData)
{
if (isInteractable == false) { return; }
Animate();
}
public void OnPointerExit(PointerEventData eventData)
{
if (outOnPointerExit == true && isOn == true)
{
Animate();
isOn = false;
if (isListItem == true) { gameObject.transform.SetParent(currentListParent, true); }
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9142f1b2d4f467c49af32a1445cf9117
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 0a39a4452fd810640afd1be6e700edee, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,199 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(DropdownMultiSelect))]
public class DropdownMultiSelectEditor : Editor
{
private GUISkin customSkin;
private DropdownMultiSelect dTarget;
private UIManagerDropdown tempUIM;
private int currentTab;
private void OnEnable()
{
dTarget = (DropdownMultiSelect)target;
try { tempUIM = dTarget.GetComponent<UIManagerDropdown>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "Dropdown 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 items = serializedObject.FindProperty("items");
var triggerObject = serializedObject.FindProperty("triggerObject");
var itemParent = serializedObject.FindProperty("itemParent");
var itemObject = serializedObject.FindProperty("itemObject");
var scrollbar = serializedObject.FindProperty("scrollbar");
var listParent = serializedObject.FindProperty("listParent");
var enableIcon = serializedObject.FindProperty("enableIcon");
var enableTrigger = serializedObject.FindProperty("enableTrigger");
var enableScrollbar = serializedObject.FindProperty("enableScrollbar");
var setHighPriorty = serializedObject.FindProperty("setHighPriorty");
var outOnPointerExit = serializedObject.FindProperty("outOnPointerExit");
var isListItem = serializedObject.FindProperty("isListItem");
var invokeAtStart = serializedObject.FindProperty("invokeAtStart");
var animationType = serializedObject.FindProperty("animationType");
var itemSpacing = serializedObject.FindProperty("itemSpacing");
var itemPaddingLeft = serializedObject.FindProperty("itemPaddingLeft");
var itemPaddingRight = serializedObject.FindProperty("itemPaddingRight");
var itemPaddingTop = serializedObject.FindProperty("itemPaddingTop");
var itemPaddingBottom = serializedObject.FindProperty("itemPaddingBottom");
var initAtStart = serializedObject.FindProperty("initAtStart");
var transitionSmoothness = serializedObject.FindProperty("transitionSmoothness");
var sizeSmoothness = serializedObject.FindProperty("sizeSmoothness");
var panelSize = serializedObject.FindProperty("panelSize");
var listRect = serializedObject.FindProperty("listRect");
var listCG = serializedObject.FindProperty("listCG");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
GUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(items, new GUIContent("Dropdown Items"), true);
EditorGUI.indentLevel = 0;
GUILayout.EndVertical();
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(triggerObject, customSkin, "Trigger Object");
MUIPEditorHandler.DrawProperty(itemObject, customSkin, "Item Prefab");
MUIPEditorHandler.DrawProperty(itemParent, customSkin, "Item Parent");
MUIPEditorHandler.DrawProperty(scrollbar, customSkin, "Scrollbar");
MUIPEditorHandler.DrawProperty(listParent, customSkin, "List Parent");
if (dTarget.animationType == DropdownMultiSelect.AnimationType.Modular)
{
MUIPEditorHandler.DrawProperty(listRect, customSkin, "List Rect");
MUIPEditorHandler.DrawProperty(listCG, customSkin, "List Canvas Group");
}
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Customization Header", 6);
enableIcon.boolValue = MUIPEditorHandler.DrawToggle(enableIcon.boolValue, customSkin, "Enable Header Icon");
enableScrollbar.boolValue = MUIPEditorHandler.DrawToggle(enableScrollbar.boolValue, customSkin, "Enable Scrollbar");
MUIPEditorHandler.DrawPropertyCW(itemSpacing, customSkin, "Item Spacing", 90);
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Item Padding"), customSkin.FindStyle("Text"), GUILayout.Width(90));
GUILayout.EndHorizontal();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(itemPaddingTop, new GUIContent("Top"));
EditorGUILayout.PropertyField(itemPaddingBottom, new GUIContent("Bottom"));
EditorGUILayout.PropertyField(itemPaddingLeft, new GUIContent("Left"));
EditorGUILayout.PropertyField(itemPaddingRight, new GUIContent("Right"));
EditorGUI.indentLevel = 0;
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Animation Header", 10);
MUIPEditorHandler.DrawProperty(animationType, customSkin, "Animation Type");
if (dTarget.animationType == DropdownMultiSelect.AnimationType.Modular)
{
MUIPEditorHandler.DrawProperty(transitionSmoothness, customSkin, "Transition Speed");
MUIPEditorHandler.DrawProperty(sizeSmoothness, customSkin, "Size Smoothness");
MUIPEditorHandler.DrawProperty(panelSize, customSkin, "Panel Size");
}
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 10);
initAtStart.boolValue = MUIPEditorHandler.DrawToggle(initAtStart.boolValue, customSkin, "Initialize At Start");
invokeAtStart.boolValue = MUIPEditorHandler.DrawToggle(invokeAtStart.boolValue, customSkin, "Invoke At Start");
enableTrigger.boolValue = MUIPEditorHandler.DrawToggle(enableTrigger.boolValue, customSkin, "Enable Trigger");
if (enableTrigger.boolValue == true && dTarget.triggerObject == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Trigger Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
setHighPriorty.boolValue = MUIPEditorHandler.DrawToggle(setHighPriorty.boolValue, customSkin, "Set High Priorty");
outOnPointerExit.boolValue = MUIPEditorHandler.DrawToggle(outOnPointerExit.boolValue, customSkin, "Out On Pointer Exit");
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
isListItem.boolValue = MUIPEditorHandler.DrawTogglePlain(isListItem.boolValue, customSkin, "Is List Item");
GUILayout.Space(3);
if (isListItem.boolValue == true)
{
MUIPEditorHandler.DrawPropertyPlain(listParent, customSkin, "List Parent");
if (dTarget.listParent == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'List Parent' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
}
GUILayout.EndVertical();
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>[Dropdown]</b> Failed to delete UI Manager connection.", this); }
}
}
}
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11fa941289c070249b66bfda86e99c36
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5de90d83aba420940bf5dab364e530ca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,132 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
public class MUIPEditorHandler : Editor
{
public static GUISkin GetDarkEditor(GUISkin tempSkin)
{
tempSkin = (GUISkin)Resources.Load("MUIP-EditorDark");
if (tempSkin == null) { tempSkin = (GUISkin)Resources.Load("MUI Skin Dark"); }
return tempSkin;
}
public static GUISkin GetLightEditor(GUISkin tempSkin)
{
tempSkin = (GUISkin)Resources.Load("MUIP-EditorLight");
if (tempSkin == null) { tempSkin = (GUISkin)Resources.Load("MUI Skin Light"); }
return tempSkin;
}
public static void DrawProperty(SerializedProperty property, GUISkin skin, string content)
{
GUILayout.BeginHorizontal(EditorStyles.helpBox);
EditorGUILayout.LabelField(new GUIContent(content), skin.FindStyle("Text"), GUILayout.Width(120));
EditorGUILayout.PropertyField(property, new GUIContent(""));
GUILayout.EndHorizontal();
}
public static void DrawPropertyPlain(SerializedProperty property, GUISkin skin, string content)
{
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent(content), skin.FindStyle("Text"), GUILayout.Width(120));
EditorGUILayout.PropertyField(property, new GUIContent(""));
GUILayout.EndHorizontal();
}
public static void DrawPropertyCW(SerializedProperty property, GUISkin skin, string content, float width)
{
GUILayout.BeginHorizontal(EditorStyles.helpBox);
EditorGUILayout.LabelField(new GUIContent(content), skin.FindStyle("Text"), GUILayout.Width(width));
EditorGUILayout.PropertyField(property, new GUIContent(""));
GUILayout.EndHorizontal();
}
public static void DrawPropertyPlainCW(SerializedProperty property, GUISkin skin, string content, float width)
{
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent(content), skin.FindStyle("Text"), GUILayout.Width(width));
EditorGUILayout.PropertyField(property, new GUIContent(""));
GUILayout.EndHorizontal();
}
public static int DrawTabs(int tabIndex, GUIContent[] tabs, GUISkin skin)
{
GUILayout.BeginHorizontal();
GUILayout.Space(17);
tabIndex = GUILayout.Toolbar(tabIndex, tabs, skin.FindStyle("Tab Indicator"));
GUILayout.EndHorizontal();
GUILayout.Space(-40);
GUILayout.BeginHorizontal();
GUILayout.Space(17);
return tabIndex;
}
public static void DrawComponentHeader(GUISkin skin, string content)
{
GUILayout.BeginHorizontal();
GUILayout.Box(new GUIContent(""), skin.FindStyle(content));
GUILayout.EndHorizontal();
GUILayout.Space(-42);
}
public static void DrawHeader(GUISkin skin, string content, int space)
{
GUILayout.Space(space);
GUILayout.Box(new GUIContent(""), skin.FindStyle(content));
}
public static bool DrawToggle(bool value, GUISkin skin, string content)
{
GUILayout.BeginHorizontal(EditorStyles.helpBox);
value = GUILayout.Toggle(value, new GUIContent(content), skin.FindStyle("Toggle"));
value = GUILayout.Toggle(value, new GUIContent(""), skin.FindStyle("Toggle Helper"));
GUILayout.EndHorizontal();
return value;
}
public static bool DrawTogglePlain(bool value, GUISkin skin, string content)
{
GUILayout.BeginHorizontal();
value = GUILayout.Toggle(value, new GUIContent(content), skin.FindStyle("Toggle"));
value = GUILayout.Toggle(value, new GUIContent(""), skin.FindStyle("Toggle Helper"));
GUILayout.EndHorizontal();
return value;
}
public static void DrawUIManagerConnectedHeader()
{
EditorGUILayout.HelpBox("This object is connected with the UI Manager. Some parameters (such as colors, " +
"fonts or booleans) are managed by the manager.", MessageType.Info);
}
public static void DrawUIManagerPresetHeader()
{
EditorGUILayout.HelpBox("This object is subject to a custom preset and cannot be used with the UI Manager. " +
"You can use the standard preset for UI Manager connection.", MessageType.Info);
}
public static void DrawUIManagerDisconnectedHeader()
{
EditorGUILayout.HelpBox("This object does not have any connection with the UI Manager.", MessageType.Info);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0b3d37a8c2278a54380cde1dbb7524d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e80c1147aaddb0842b5ed350af305d52
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,339 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using TMPro;
namespace Michsky.MUIP
{
[RequireComponent(typeof(Animator))]
public class HorizontalSelector : MonoBehaviour
{
// Resources
public TextMeshProUGUI label;
public TextMeshProUGUI labelHelper;
public Image labelIcon;
public Image labelIconHelper;
public Transform indicatorParent;
public GameObject indicatorObject;
public Animator selectorAnimator;
public HorizontalLayoutGroup contentLayout;
public HorizontalLayoutGroup contentLayoutHelper;
private string newItemTitle;
// Saving
public bool enableIcon = true;
public bool saveSelected = false;
public string saveKey = "My Selector";
// Settings
public bool enableIndicators = true;
public bool invokeAtStart;
public bool invertAnimation;
public bool loopSelection;
[Range(0.25f, 2.5f)] public float iconScale = 1;
[Range(1, 50)] public int contentSpacing = 15;
public int defaultIndex = 0;
[HideInInspector] public int index = 0;
// Items
public List<Item> items = new List<Item>();
// Events
[System.Serializable] public class SelectorEvent : UnityEvent<int> { }
public SelectorEvent onValueChanged;
[System.Serializable] public class ItemTextChangedEvent : UnityEvent<TMP_Text> { }
public ItemTextChangedEvent onItemTextChanged;
[System.Serializable]
public class Item
{
public string itemTitle = "Item Title";
public Sprite itemIcon;
public UnityEvent onItemSelect = new UnityEvent();
}
void Awake()
{
if (selectorAnimator == null) { selectorAnimator = gameObject.GetComponent<Animator>(); }
if (label == null || labelHelper == null)
{
Debug.LogError("<b>[Horizontal Selector]</b> Cannot initalize the object due to missing resources.", this);
return;
}
SetupSelector();
UpdateContentLayout();
if (invokeAtStart == true)
{
items[index].onItemSelect.Invoke();
onValueChanged.Invoke(index);
}
}
void OnEnable()
{
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
}
public void SetupSelector()
{
if (items.Count == 0)
return;
if (saveSelected == true)
{
if (PlayerPrefs.HasKey("HorizontalSelector_" + saveKey) == true) { defaultIndex = PlayerPrefs.GetInt("HorizontalSelector_" + saveKey); }
else { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, defaultIndex); }
}
label.text = items[defaultIndex].itemTitle;
labelHelper.text = label.text;
onItemTextChanged?.Invoke(label);
if (labelIcon != null && enableIcon == true)
{
labelIcon.sprite = items[defaultIndex].itemIcon;
labelIconHelper.sprite = labelIcon.sprite;
}
else if (enableIcon == false)
{
if (labelIcon != null) { labelIcon.gameObject.SetActive(false); }
if (labelIconHelper != null) { labelIconHelper.gameObject.SetActive(false); }
}
index = defaultIndex;
if (enableIndicators == true) { UpdateIndicators(); }
else { Destroy(indicatorParent.gameObject); }
}
public void PreviousItem()
{
if (items.Count == 0)
return;
StopCoroutine("DisableAnimator");
selectorAnimator.enabled = true;
if (loopSelection == false)
{
if (index != 0)
{
labelHelper.text = label.text;
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
if (index == 0) { index = items.Count - 1; }
else { index--; }
label.text = items[index].itemTitle;
onItemTextChanged?.Invoke(label);
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
items[index].onItemSelect.Invoke();
onValueChanged.Invoke(index);
selectorAnimator.Play(null);
selectorAnimator.StopPlayback();
if (invertAnimation == true) { selectorAnimator.Play("Forward"); }
else { selectorAnimator.Play("Previous"); }
}
}
else
{
labelHelper.text = label.text;
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
if (index == 0) { index = items.Count - 1; }
else { index--; }
label.text = items[index].itemTitle;
onItemTextChanged?.Invoke(label);
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
items[index].onItemSelect.Invoke();
onValueChanged.Invoke(index);
selectorAnimator.Play(null);
selectorAnimator.StopPlayback();
if (invertAnimation == true) { selectorAnimator.Play("Forward"); }
else { selectorAnimator.Play("Previous"); }
}
if (saveSelected == true) { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, index); }
if (enableIndicators == true)
{
for (int i = 0; i < items.Count; ++i)
{
GameObject go = indicatorParent.GetChild(i).gameObject;
Transform onObj = go.transform.Find("On");
Transform offObj = go.transform.Find("Off");
if (i == index) { onObj.gameObject.SetActive(true); offObj.gameObject.SetActive(false); }
else { onObj.gameObject.SetActive(false); offObj.gameObject.SetActive(true); }
}
}
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
}
public void NextItem()
{
if (items.Count == 0)
return;
StopCoroutine("DisableAnimator");
selectorAnimator.enabled = true;
if (loopSelection == false)
{
if (index != items.Count - 1)
{
labelHelper.text = label.text;
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
if ((index + 1) >= items.Count) { index = 0; }
else { index++; }
label.text = items[index].itemTitle;
onItemTextChanged?.Invoke(label);
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
items[index].onItemSelect.Invoke();
onValueChanged.Invoke(index);
selectorAnimator.Play(null);
selectorAnimator.StopPlayback();
if (invertAnimation == true) { selectorAnimator.Play("Previous"); }
else { selectorAnimator.Play("Forward"); }
}
}
else
{
labelHelper.text = label.text;
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
if ((index + 1) >= items.Count) { index = 0; }
else { index++; }
label.text = items[index].itemTitle;
onItemTextChanged?.Invoke(label);
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
items[index].onItemSelect.Invoke();
onValueChanged.Invoke(index);
selectorAnimator.Play(null);
selectorAnimator.StopPlayback();
if (invertAnimation == true) { selectorAnimator.Play("Previous"); }
else { selectorAnimator.Play("Forward"); }
}
if (saveSelected == true) { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, index); }
if (enableIndicators == true)
{
for (int i = 0; i < items.Count; ++i)
{
GameObject go = indicatorParent.GetChild(i).gameObject;
Transform onObj = go.transform.Find("On"); ;
Transform offObj = go.transform.Find("Off");
if (i == index) { onObj.gameObject.SetActive(true); offObj.gameObject.SetActive(false); }
else { onObj.gameObject.SetActive(false); offObj.gameObject.SetActive(true); }
}
}
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
}
// Obsolete
public void PreviousClick() { PreviousItem(); }
public void ForwardClick() { NextItem(); }
public void CreateNewItem(string title)
{
Item item = new Item();
newItemTitle = title;
item.itemTitle = newItemTitle;
items.Add(item);
}
public void CreateNewItem(string title, Sprite icon)
{
Item item = new Item();
newItemTitle = title;
item.itemTitle = newItemTitle;
item.itemIcon = icon;
items.Add(item);
}
public void RemoveItem(string itemTitle)
{
var item = items.Find(x => x.itemTitle == itemTitle);
items.Remove(item);
SetupSelector();
}
public void UpdateUI()
{
selectorAnimator.enabled = true;
label.text = items[index].itemTitle;
onItemTextChanged?.Invoke(label);
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
UpdateContentLayout();
UpdateIndicators();
StartCoroutine("DisableAnimator");
}
public void UpdateIndicators()
{
if (enableIndicators == false)
return;
foreach (Transform child in indicatorParent) { Destroy(child.gameObject); }
for (int i = 0; i < items.Count; ++i)
{
GameObject go = Instantiate(indicatorObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(indicatorParent, false);
go.name = items[i].itemTitle;
Transform onObj = go.transform.Find("On");
Transform offObj = go.transform.Find("Off");
if (i == index) { onObj.gameObject.SetActive(true); offObj.gameObject.SetActive(false); }
else { onObj.gameObject.SetActive(false); offObj.gameObject.SetActive(true); }
}
}
public void UpdateContentLayout()
{
if (contentLayout != null) { contentLayout.spacing = contentSpacing; }
if (contentLayoutHelper != null) { contentLayoutHelper.spacing = contentSpacing; }
if (labelIcon != null)
{
labelIcon.transform.localScale = new Vector3(iconScale, iconScale, iconScale);
labelIconHelper.transform.localScale = new Vector3(iconScale, iconScale, iconScale);
}
LayoutRebuilder.ForceRebuildLayoutImmediate(label.transform.GetComponent<RectTransform>());
LayoutRebuilder.ForceRebuildLayoutImmediate(label.transform.parent.GetComponent<RectTransform>());
}
IEnumerator DisableAnimator()
{
yield return new WaitForSeconds(0.5f);
selectorAnimator.enabled = false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 125c77e2c7bf16f4792824151a1d9249
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 7a33180745301ca4b903e0c6e51cfeb6, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,217 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(HorizontalSelector))]
public class HorizontalSelectorEditor : Editor
{
private GUISkin customSkin;
private HorizontalSelector hsTarget;
private UIManagerHSelector tempUIM;
private int currentTab;
private void OnEnable()
{
hsTarget = (HorizontalSelector)target;
try { tempUIM = hsTarget.GetComponent<UIManagerHSelector>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
if (hsTarget.defaultIndex > hsTarget.items.Count - 1) { hsTarget.defaultIndex = 0; }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "HS 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 items = serializedObject.FindProperty("items");
var onValueChanged = serializedObject.FindProperty("onValueChanged");
var label = serializedObject.FindProperty("label");
var selectorAnimator = serializedObject.FindProperty("selectorAnimator");
var labelHelper = serializedObject.FindProperty("labelHelper");
var labelIcon = serializedObject.FindProperty("labelIcon");
var labelIconHelper = serializedObject.FindProperty("labelIconHelper");
var indicatorParent = serializedObject.FindProperty("indicatorParent");
var indicatorObject = serializedObject.FindProperty("indicatorObject");
var enableIcon = serializedObject.FindProperty("enableIcon");
var saveSelected = serializedObject.FindProperty("saveSelected");
var saveKey = serializedObject.FindProperty("saveKey");
var enableIndicators = serializedObject.FindProperty("enableIndicators");
var invokeAtStart = serializedObject.FindProperty("invokeAtStart");
var invertAnimation = serializedObject.FindProperty("invertAnimation");
var loopSelection = serializedObject.FindProperty("loopSelection");
var defaultIndex = serializedObject.FindProperty("defaultIndex");
var iconScale = serializedObject.FindProperty("iconScale");
var contentSpacing = serializedObject.FindProperty("contentSpacing");
var contentLayout = serializedObject.FindProperty("contentLayout");
var contentLayoutHelper = serializedObject.FindProperty("contentLayoutHelper");
var enableUIManager = serializedObject.FindProperty("enableUIManager");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
if (Application.isPlaying == false && hsTarget.items.Count != 0)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
GUI.enabled = false;
EditorGUILayout.LabelField(new GUIContent("Selected Item:"), customSkin.FindStyle("Text"), GUILayout.Width(78));
GUI.enabled = true;
EditorGUILayout.LabelField(new GUIContent(hsTarget.items[defaultIndex.intValue].itemTitle), customSkin.FindStyle("Text"));
GUILayout.EndHorizontal();
GUILayout.Space(2);
defaultIndex.intValue = EditorGUILayout.IntSlider(defaultIndex.intValue, 0, hsTarget.items.Count - 1);
GUILayout.EndVertical();
}
else if (Application.isPlaying == true && hsTarget.items.Count != 0)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
GUI.enabled = false;
EditorGUILayout.LabelField(new GUIContent("Current Item:"), customSkin.FindStyle("Text"), GUILayout.Width(74));
EditorGUILayout.LabelField(new GUIContent(hsTarget.items[hsTarget.index].itemTitle), customSkin.FindStyle("Text"));
GUILayout.EndHorizontal();
GUILayout.Space(2);
EditorGUILayout.IntSlider(hsTarget.index, 0, hsTarget.items.Count - 1);
GUI.enabled = true;
GUILayout.EndVertical();
}
else { EditorGUILayout.HelpBox("There is no item in the list.", MessageType.Warning); }
GUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(items, new GUIContent("Selector Items"), true);
EditorGUI.indentLevel = 1;
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"), true);
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(selectorAnimator, customSkin, "Animator");
MUIPEditorHandler.DrawProperty(label, customSkin, "Label");
MUIPEditorHandler.DrawProperty(labelHelper, customSkin, "Label Helper");
MUIPEditorHandler.DrawProperty(labelIcon, customSkin, "Label Icon");
MUIPEditorHandler.DrawProperty(labelIconHelper, customSkin, "Label Icon Helper");
MUIPEditorHandler.DrawProperty(indicatorParent, customSkin, "Indicator Parent");
MUIPEditorHandler.DrawProperty(indicatorObject, customSkin, "Indicator Object");
MUIPEditorHandler.DrawProperty(contentLayout, customSkin, "Content Layout");
MUIPEditorHandler.DrawProperty(contentLayoutHelper, customSkin, "Content Layout Helper");
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Customization Header", 6);
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
enableIcon.boolValue = MUIPEditorHandler.DrawTogglePlain(enableIcon.boolValue, customSkin, "Enable Icon");
GUILayout.Space(3);
if (enableIcon.boolValue == true && hsTarget.labelIcon == null) { EditorGUILayout.HelpBox("'Enable Icon' is enabled but 'Label Icon' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error); }
else if (enableIcon.boolValue == true && hsTarget.labelIcon != null) { hsTarget.labelIcon.gameObject.SetActive(true); }
else if (enableIcon.boolValue == false && hsTarget.labelIcon != null) { hsTarget.labelIcon.gameObject.SetActive(false); }
GUILayout.EndVertical();
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
enableIndicators.boolValue = MUIPEditorHandler.DrawTogglePlain(enableIndicators.boolValue, customSkin, "Enable Indicators");
GUILayout.Space(3);
GUILayout.BeginHorizontal();
if (enableIndicators.boolValue == true)
{
if (hsTarget.indicatorObject == null) { EditorGUILayout.HelpBox("'Enable Indicators' is enabled but 'Indicator Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error); }
if (hsTarget.indicatorParent == null) { EditorGUILayout.HelpBox("'Enable Indicators' is enabled but 'Indicator Parent' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error); }
else { hsTarget.indicatorParent.gameObject.SetActive(true); }
}
else if (enableIndicators.boolValue == false && hsTarget.indicatorParent != null) { hsTarget.indicatorParent.gameObject.SetActive(false); }
GUILayout.EndHorizontal();
GUILayout.EndVertical();
MUIPEditorHandler.DrawProperty(iconScale, customSkin, "Icon Scale");
MUIPEditorHandler.DrawProperty(contentSpacing, customSkin, "Content Spacing");
hsTarget.UpdateContentLayout();
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 10);
invokeAtStart.boolValue = MUIPEditorHandler.DrawToggle(invokeAtStart.boolValue, customSkin, "Invoke At Start");
invertAnimation.boolValue = MUIPEditorHandler.DrawToggle(invertAnimation.boolValue, customSkin, "Invert Animation");
loopSelection.boolValue = MUIPEditorHandler.DrawToggle(loopSelection.boolValue, customSkin, "Loop Selection");
GUI.enabled = true;
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(-3);
saveSelected.boolValue = MUIPEditorHandler.DrawTogglePlain(saveSelected.boolValue, customSkin, "Save Selected");
GUILayout.Space(3);
if (saveSelected.boolValue == true)
{
MUIPEditorHandler.DrawPropertyCW(saveKey, customSkin, "Save Key:", 90);
EditorGUILayout.HelpBox("Each selector should has its own unique save key.", MessageType.Info);
}
GUILayout.EndVertical();
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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4dc4a3eba298e1c4b851efe79a336cb5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e158faa1d0027ba4ea870c2750e8d40e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Michsky.MUIP
{
[RequireComponent(typeof(Animator))]
public class AnimatedIconHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
[Header("Settings")]
public PlayType playType;
public Animator iconAnimator;
bool isClicked;
public enum PlayType
{
Click,
Hover,
None
}
void Start()
{
if (iconAnimator == null)
iconAnimator = gameObject.GetComponent<Animator>();
}
public void PlayIn() { iconAnimator.Play("In"); }
public void PlayOut() { iconAnimator.Play("Out"); }
public void ClickEvent()
{
if (isClicked == true) { PlayOut(); isClicked = false; }
else { PlayIn(); isClicked = true; }
}
public void OnPointerClick(PointerEventData eventData)
{
if (playType == PlayType.Click)
ClickEvent();
}
public void OnPointerEnter(PointerEventData eventData)
{
if (playType == PlayType.Hover)
iconAnimator.Play("In");
}
public void OnPointerExit(PointerEventData eventData)
{
if (playType == PlayType.Hover)
iconAnimator.Play("Out");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 86b8e0ba11d23674b90c578d7eec2d09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 3ed3bfb48269e2646b4dc2130299c956, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using UnityEngine;
namespace Michsky.MUIP
{
[CreateAssetMenu(fileName = "New Icon Library", menuName = "Modern UI Pack/New Icon Library")]
public class IconLibrary : ScriptableObject
{
// Settings
public bool alwaysUpdate = false;
public bool optimizeUpdates = true;
// Editor Only
public Texture2D searchIcon;
// Library
public List<IconItem> icons = new List<IconItem>();
[System.Serializable]
public class IconItem
{
public string iconTitle = "Icon";
public Texture2D iconPreview;
public Sprite iconSprite32;
public Sprite iconSprite64;
public Sprite iconSprite128;
public Sprite iconSprite256;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0a014fb26f42dfc46937c175544fe894
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- searchIcon: {fileID: 2800000, guid: fb98fbe62e3a3304584516ade7506fce, type: 3}
executionOrder: 0
icon: {fileID: 2800000, guid: 3ed3bfb48269e2646b4dc2130299c956, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(IconLibrary))]
public class IconLibraryEditor : Editor
{
private GUISkin customSkin;
void OnEnable()
{
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
// Settings
var alwaysUpdate = serializedObject.FindProperty("alwaysUpdate");
var optimizeUpdates = serializedObject.FindProperty("optimizeUpdates");
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 8);
alwaysUpdate.boolValue = MUIPEditorHandler.DrawToggle(alwaysUpdate.boolValue, customSkin, "Always Update");
optimizeUpdates.boolValue = MUIPEditorHandler.DrawToggle(optimizeUpdates.boolValue, customSkin, "Optimize Update");
// Content
var icons = serializedObject.FindProperty("icons");
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 8);
GUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(icons, new GUIContent("Icon List"), true);
EditorGUI.indentLevel = 0;
if (GUILayout.Button("+ Add a new icon", customSkin.button))
icons.arraySize += 1;
GUILayout.EndVertical();
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1161e041bde9c9f4f9d1118349cd5968
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,96 @@
using UnityEngine;
using UnityEngine.UI;
namespace Michsky.MUIP
{
[ExecuteInEditMode]
[DisallowMultipleComponent]
[AddComponentMenu("Modern UI Pack/Image/Icon Manager")]
[RequireComponent(typeof(Image))]
public class IconManager : MonoBehaviour
{
// Resources
public IconLibrary iconLibrary;
// Info
public string selectedIconID;
public int selectedIconIndex;
[Range(0, 3)] public int spriteSize;
Image imageObject;
[HideInInspector] public string currentSize;
[HideInInspector] public bool size32;
[HideInInspector] public bool size64;
[HideInInspector] public bool size128;
[HideInInspector] public bool size256;
void Awake()
{
try
{
if (iconLibrary == null) { iconLibrary = Resources.Load<IconLibrary>("Icon Library"); }
if (imageObject == null) { imageObject = gameObject.GetComponent<Image>(); }
this.enabled = true;
UpdateElement();
}
catch { Debug.LogWarning("<b>Icon Library</b> is missing, but it should be assigned.", this); }
}
void Update()
{
if (iconLibrary.alwaysUpdate == true) { UpdateElement(); }
if (Application.isPlaying == true && iconLibrary.optimizeUpdates == true) { this.enabled = false; }
}
public void UpdateElement()
{
if (iconLibrary == null)
{
this.enabled = false;
return;
}
for (int i = 0; i < iconLibrary.icons.Count; i++)
{
if (selectedIconID == iconLibrary.icons[i].iconTitle && gameObject.activeInHierarchy == true)
{
if (spriteSize == 0) { imageObject.sprite = iconLibrary.icons[i].iconSprite32; }
else if (spriteSize == 1) { imageObject.sprite = iconLibrary.icons[i].iconSprite64; }
else if (spriteSize == 2) { imageObject.sprite = iconLibrary.icons[i].iconSprite128; }
else if (spriteSize == 3) { imageObject.sprite = iconLibrary.icons[i].iconSprite256; }
break;
}
}
if (iconLibrary.alwaysUpdate == false)
this.enabled = false;
}
public void UpdateSpriteSize(int spriteIndex, int newSize)
{
if (newSize == 0) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite32; }
else if (newSize == 1) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite64; }
else if (newSize == 2) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite128; }
else if (newSize == 3) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite256; }
}
public void ChangeIcon(string newSprite, int preferredSize)
{
int selectedSpriteIndex = -1;
for (int i = 0; i < iconLibrary.icons.Count; i++)
{
if (newSprite == iconLibrary.icons[i].iconTitle)
{
selectedSpriteIndex = i;
break;
}
}
if (selectedSpriteIndex != -1) { UpdateSpriteSize(selectedSpriteIndex, preferredSize); }
else { Debug.Log("<b>[Icon Manager]</b> Cannot find an icon named '" + newSprite + "'"); }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 603d9687b95941549aee6d293dae7de4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 3ed3bfb48269e2646b4dc2130299c956, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,292 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
namespace Michsky.MUIP
{
[CustomEditor(typeof(IconManager))]
public class IconManagerEditor : Editor
{
GUISkin customSkin;
private IconManager imTarget;
private int currentTab;
private int tempSizeIndex;
private string tempSizeID;
private string searchText;
private string defaultSize = "128x";
protected GUIStyle panelStyle;
protected GUIStyle lipStyle;
protected GUIStyle lipAltStyle;
Vector2 scrollPosition = Vector2.zero;
List<string> sizeList = new List<string>();
private void OnEnable()
{
imTarget = (IconManager)target;
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
sizeList.Clear();
if (imTarget.size32 == true) { sizeList.Add("32x"); }
if (imTarget.size64 == true) { sizeList.Add("64x"); }
if (imTarget.size128 == true) { sizeList.Add("128x"); }
if (imTarget.size256 == true) { sizeList.Add("256x"); }
for (int i = 0; i < sizeList.Count; i++)
{
if (sizeList[i].ToString() == imTarget.currentSize)
tempSizeIndex = i;
}
}
void UpdateIconProperties()
{
sizeList.Clear();
if (imTarget.size32 == true) { sizeList.Add("32x"); }
if (imTarget.size64 == true) { sizeList.Add("64x"); }
if (imTarget.size128 == true) { sizeList.Add("128x"); }
if (imTarget.size256 == true) { sizeList.Add("256x"); }
for (int i = 0; i < sizeList.Count; i++)
{
if (sizeList[i].ToString() == imTarget.currentSize)
tempSizeIndex = i;
}
ConvertIDtoIndex();
imTarget.enabled = false;
imTarget.enabled = true;
imTarget.UpdateElement();
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
void ConvertIDtoIndex()
{
if (tempSizeID == "32x") { imTarget.spriteSize = 0; }
else if (tempSizeID == "64x") { imTarget.spriteSize = 1; }
else if (tempSizeID == "128x") { imTarget.spriteSize = 2; }
else if (tempSizeID == "256x") { imTarget.spriteSize = 3; }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "IM Top Header");
Color defaultColor = GUI.color;
GUIContent[] toolbarTabs = new GUIContent[2];
toolbarTabs[0] = new GUIContent("Content");
toolbarTabs[1] = 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("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
currentTab = 1;
GUILayout.EndHorizontal();
var selectedIconID = serializedObject.FindProperty("selectedIconID");
var currentSize = serializedObject.FindProperty("currentSize");
var iconLibrary = serializedObject.FindProperty("iconLibrary");
// Custom panel
panelStyle = new GUIStyle(GUI.skin.box);
panelStyle.normal.textColor = GUI.skin.label.normal.textColor;
panelStyle.margin = new RectOffset(0, 0, 0, 0);
panelStyle.padding = new RectOffset(3, 4, 3, 4);
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(iconLibrary, customSkin, "Icon Library");
if (imTarget.iconLibrary == null)
{
serializedObject.ApplyModifiedProperties();
return;
}
if (imTarget.iconLibrary.icons.Count == 0)
{
EditorGUILayout.HelpBox("There are no items in the selected icon library.", MessageType.Info);
return;
}
if (selectedIconID.stringValue == "")
EditorGUILayout.HelpBox("No icon selected.", MessageType.Info);
else
{
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
GUILayout.Box(imTarget.iconLibrary.icons[imTarget.selectedIconIndex].iconPreview, customSkin.FindStyle("Icon Manager Preview"));
GUILayout.BeginVertical();
GUILayout.Space(1);
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Selected Icon"), customSkin.FindStyle("Text"), GUILayout.Width(80));
GUI.enabled = false;
EditorGUILayout.PropertyField(selectedIconID, new GUIContent(""));
GUI.enabled = true;
GUILayout.EndHorizontal();
GUILayout.Space(1);
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Sprite Size"), customSkin.FindStyle("Text"), GUILayout.Width(80));
tempSizeIndex = EditorGUILayout.Popup(tempSizeIndex, sizeList.ToArray());
try { tempSizeID = sizeList[tempSizeIndex].ToString(); currentSize.stringValue = tempSizeID; }
catch { tempSizeID = defaultSize; currentSize.stringValue = tempSizeID; tempSizeIndex = 2; }
ConvertIDtoIndex();
if (GUILayout.Button("Refresh", GUILayout.Width(56)))
UpdateIconProperties();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
GUILayout.Space(10);
GUILayout.Box(new GUIContent(""), customSkin.FindStyle("Customization Header"));
// Search field
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.BeginHorizontal();
GUILayout.Box(imTarget.iconLibrary.searchIcon, customSkin.FindStyle("Icon Manager Search"));
// EditorGUILayout.LabelField(new GUIContent("Search:"), customSkin.FindStyle("Text"), GUILayout.Width(50), GUILayout.Height(20));
searchText = EditorGUILayout.TextField(searchText, GUILayout.Height(20));
if (searchText != null && GUILayout.Button("", GUILayout.Width(19))) { searchText = null; }
GUILayout.Space(1);
GUILayout.EndHorizontal();
GUILayout.Space(2);
GUILayout.EndVertical();
GUILayout.Space(2);
// Scroll panel
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Height(250));
GUILayout.BeginVertical(panelStyle);
if (searchText == null || searchText == "")
{
for (int i = 0; i < imTarget.iconLibrary.icons.Count; i++)
{
GUILayout.BeginHorizontal(GUILayout.Height(32));
GUILayout.Box(imTarget.iconLibrary.icons[i].iconPreview, customSkin.FindStyle("Icon Manager Item"));
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
if (GUILayout.Button(imTarget.iconLibrary.icons[i].iconTitle, GUILayout.Height(32)))
{
sizeList.Clear();
if (imTarget.iconLibrary.icons[i].iconSprite32 != null) { imTarget.size32 = true; sizeList.Add("32x"); }
else { imTarget.size32 = false; imTarget.spriteSize = 1; }
if (imTarget.iconLibrary.icons[i].iconSprite64 != null) { imTarget.size64 = true; sizeList.Add("64x"); }
else { imTarget.size64 = false; imTarget.spriteSize = 2; }
if (imTarget.iconLibrary.icons[i].iconSprite128 != null) { imTarget.size128 = true; sizeList.Add("128x"); }
else { imTarget.size128 = false; imTarget.spriteSize = 3; }
if (imTarget.iconLibrary.icons[i].iconSprite256 != null) { imTarget.size256 = true; sizeList.Add("256x"); }
else { imTarget.size256 = false; }
imTarget.selectedIconIndex = i;
imTarget.selectedIconID = imTarget.iconLibrary.icons[i].iconTitle;
UpdateIconProperties();
}
GUILayout.EndHorizontal();
GUILayout.Space(2);
}
}
else
{
for (int i = 0; i < imTarget.iconLibrary.icons.Count; i++)
{
if (imTarget.iconLibrary.icons[i].iconTitle.ToLower().Contains(searchText))
{
GUILayout.BeginHorizontal(GUILayout.Height(32));
GUILayout.Box(imTarget.iconLibrary.icons[i].iconPreview, customSkin.FindStyle("Icon Manager Item"));
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
if (GUILayout.Button(imTarget.iconLibrary.icons[i].iconTitle, GUILayout.Height(32)))
{
sizeList.Clear();
if (imTarget.iconLibrary.icons[i].iconSprite32 != null) { imTarget.size32 = true; sizeList.Add("32x"); }
else { imTarget.size32 = false; imTarget.spriteSize = 1; }
if (imTarget.iconLibrary.icons[i].iconSprite64 != null) { imTarget.size64 = true; sizeList.Add("64x"); }
else { imTarget.size64 = false; imTarget.spriteSize = 2; }
if (imTarget.iconLibrary.icons[i].iconSprite128 != null) { imTarget.size128 = true; sizeList.Add("128x"); }
else { imTarget.size128 = false; imTarget.spriteSize = 3; }
if (imTarget.iconLibrary.icons[i].iconSprite256 != null) { imTarget.size256 = true; sizeList.Add("256x"); }
else { imTarget.size256 = false; }
imTarget.selectedIconIndex = i;
imTarget.selectedIconID = imTarget.iconLibrary.icons[i].iconTitle;
UpdateIconProperties();
}
GUILayout.EndHorizontal();
GUILayout.Space(2);
}
}
}
// Scroll Panel End
GUILayout.EndVertical();
GUILayout.EndScrollView();
if (GUI.enabled == true) { Repaint(); }
break;
case 1:
GUILayout.Space(6);
GUILayout.Box(new GUIContent(""), customSkin.FindStyle("Options Header"));
if (imTarget.iconLibrary == null) { GUI.enabled = false; }
else { GUI.enabled = true; }
if (GUILayout.Button("Sort Library By Name (A to Z)")) { imTarget.iconLibrary.icons.Sort(SortByNameAtoZ); }
if (GUILayout.Button("Sort Library By Name (Z to A)")) { imTarget.iconLibrary.icons.Sort(SortByNameZtoA); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
private static int SortByNameAtoZ(IconLibrary.IconItem o1, IconLibrary.IconItem o2)
{
// Compare the names and sort by A to Z
return o1.iconTitle.CompareTo(o2.iconTitle);
}
private static int SortByNameZtoA(IconLibrary.IconItem o1, IconLibrary.IconItem o2)
{
// Compare the names and sort by Z to A
return o2.iconTitle.CompareTo(o1.iconTitle);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc8d4f7f18559ed43b3f3074a40553e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ca95fe39461d3be48b5e7c489913b16f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,108 @@
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using TMPro;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace Michsky.MUIP
{
[RequireComponent(typeof(TMP_InputField))]
[RequireComponent(typeof(Animator))]
public class CustomInputField : MonoBehaviour
{
[Header("Resources")]
public TMP_InputField inputText;
public Animator inputFieldAnimator;
[Header("Settings")]
public bool processSubmit = false;
public bool clearOnSubmit = true;
[Header("Events")]
public UnityEvent onSubmit;
// Hidden variables
private string inAnim = "In";
private string outAnim = "Out";
private string instaInAnim = "Instant In";
private string instaOutAnim = "Instant Out";
void Awake()
{
if (inputText == null) { inputText = gameObject.GetComponent<TMP_InputField>(); }
if (inputFieldAnimator == null) { inputFieldAnimator = gameObject.GetComponent<Animator>(); }
inputText.onSelect.AddListener(delegate { AnimateIn(); });
inputText.onEndEdit.AddListener(delegate { AnimateOut(); });
UpdateStateInstant();
}
void OnEnable()
{
if (inputText == null)
return;
inputText.ForceLabelUpdate();
UpdateStateInstant();
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
}
void Update()
{
if (processSubmit == false ||
string.IsNullOrEmpty(inputText.text) == true ||
EventSystem.current.currentSelectedGameObject != inputText.gameObject)
{ return; }
#if ENABLE_LEGACY_INPUT_MANAGER
if (Input.GetKeyDown(KeyCode.Return)) { onSubmit.Invoke(); if (clearOnSubmit == true) { inputText.text = ""; } }
#elif ENABLE_INPUT_SYSTEM
if (Keyboard.current.enterKey.wasPressedThisFrame) { onSubmit.Invoke(); if (clearOnSubmit == true) { inputText.text = ""; } }
#endif
}
public void AnimateIn()
{
StopCoroutine("DisableAnimator");
if (inputFieldAnimator.gameObject.activeInHierarchy == true && inputText.text.Length == 0)
{
inputFieldAnimator.enabled = true;
inputFieldAnimator.Play(inAnim);
StartCoroutine("DisableAnimator");
}
}
public void AnimateOut()
{
if (inputFieldAnimator.gameObject.activeInHierarchy == true)
{
inputFieldAnimator.enabled = true;
if (inputText.text.Length == 0) { inputFieldAnimator.Play(outAnim); }
StartCoroutine("DisableAnimator");
}
}
public void UpdateState()
{
if (inputText.text.Length == 0) { AnimateOut(); }
else { AnimateIn(); }
}
public void UpdateStateInstant()
{
if (inputText.text.Length == 0) { inputFieldAnimator.Play(instaOutAnim); }
else { inputFieldAnimator.Play(instaInAnim); }
}
IEnumerator DisableAnimator()
{
yield return new WaitForSeconds(1);
inputFieldAnimator.enabled = false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c65c7917835d8a04b94c8b906234b09e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: e956b4f7a85075c43a444a9f05cc765a, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d0d8ff45d6ce1ff479a6b3796e115826
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace Michsky.MUIP
{
[ExecuteInEditMode]
[DisallowMultipleComponent]
[AddComponentMenu("Modern UI Pack/Layout/Layout Group Fix")]
public class LayoutGroupFix : MonoBehaviour
{
[SerializeField] private bool fixOnEnable = true;
[SerializeField] private bool fixWithDelay = true;
float fixDelay = 0.025f;
void OnEnable()
{
#if UNITY_EDITOR
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
if (Application.isPlaying == false) { return; }
#endif
if (fixWithDelay == false && fixOnEnable == true) { LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>()); }
else if (fixWithDelay == true) { StartCoroutine(FixDelay()); }
}
public void FixLayout()
{
if (fixWithDelay == false) { LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>()); }
else { StartCoroutine(FixDelay()); }
}
IEnumerator FixDelay()
{
yield return new WaitForSecondsRealtime(fixDelay);
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4f4ae5cbba538d449b15cffc97daa7d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 1ee61fa8a667ceb48bedcd774003f519, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,168 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Michsky.MUIP
{
[AddComponentMenu("Modern UI Pack/Layout Group/Radial Layout Group")]
public class RadialLayoutGroup : LayoutGroup
{
public enum Direction { Clockwise = 0, Counterclockwise = 1, Bidirectional = 2 }
public enum ConstraintMode { Interval = 0, Range = 1 }
[SerializeField] private Direction refLayoutDir;
public Direction layoutDir { get { return refLayoutDir; } set { SetProperty(ref refLayoutDir, value); } }
[SerializeField] private float refRadiusStart = 200;
public float radiusStart { get { return refRadiusStart; } set { SetProperty(ref refRadiusStart, value); } }
[SerializeField] private float refRadiusDelta;
public float radiusDelta { get { return refRadiusDelta; } set { SetProperty(ref refRadiusDelta, value); } }
[SerializeField] private float refRadiusRange;
public float radiusRange { get { return refRadiusRange; } set { SetProperty(ref refRadiusRange, value); } }
[SerializeField] private float refAngleDelta;
public float angleDelta { get { return refAngleDelta; } set { SetProperty(ref refAngleDelta, value); } }
[SerializeField] private float refAngleStart;
public float angleStart { get { return refAngleStart; } set { SetProperty(ref refAngleStart, value); } }
[SerializeField] private float refAngleCenter;
public float angleCenter { get { return refAngleCenter; } set { SetProperty(ref refAngleCenter, value); } }
[SerializeField] private float refAngleRange = 200;
public float angleRange { get { return refAngleRange; } set { SetProperty(ref refAngleRange, value); } }
[SerializeField] private bool refChildRotate = false;
public bool childRotate { get { return refChildRotate; } set { SetProperty(ref refChildRotate, value); } }
public override void CalculateLayoutInputVertical() { }
public override void CalculateLayoutInputHorizontal() { }
public override void SetLayoutHorizontal() { CalculateChildrenPositions(); }
public override void SetLayoutVertical() { CalculateChildrenPositions(); }
private List<RectTransform> childList = new List<RectTransform>();
private List<ILayoutIgnorer> ignoreList = new List<ILayoutIgnorer>();
private void CalculateChildrenPositions()
{
this.m_Tracker.Clear();
childList.Clear();
for (int i = 0; i < this.transform.childCount; ++i)
{
RectTransform rect = this.transform.GetChild(i) as RectTransform;
if (!rect.gameObject.activeSelf)
continue;
ignoreList.Clear();
rect.GetComponents(ignoreList);
if (ignoreList.Count == 0)
{
childList.Add(rect);
continue;
}
for (int j = 0; j < ignoreList.Count; j++)
{
if (!ignoreList[j].ignoreLayout)
{
childList.Add(rect);
break;
}
}
ignoreList.Clear();
}
EnsureParameters(childList.Count);
for (int i = 0; i < childList.Count; ++i)
{
var child = childList[i];
float delta = i * angleDelta;
float angle = layoutDir == Direction.Clockwise ? angleStart - delta : angleStart + delta;
ProcessOneChild(child, angle, radiusStart + (i * radiusDelta));
}
childList.Clear();
}
private void EnsureParameters(int childCount)
{
EnsureAngleParameters(childCount);
EnsureRadiusParameters(childCount);
}
private void EnsureAngleParameters(int childCount)
{
int intervalCount = childCount - 1;
switch (layoutDir)
{
case Direction.Clockwise:
if (intervalCount > 0) { this.angleDelta = this.angleRange / intervalCount; }
else { this.angleDelta = 0; }
break;
case Direction.Counterclockwise:
if (intervalCount > 0) { this.angleDelta = this.angleRange / intervalCount; }
else { this.angleDelta = 0; }
break;
case Direction.Bidirectional:
if (intervalCount > 0) { this.angleDelta = this.angleRange / intervalCount; }
else { this.angleDelta = 0; }
this.angleStart = this.angleCenter - angleRange * 0.5f;
break;
}
}
private void EnsureRadiusParameters(int childCount)
{
int intervalCount = childCount - 1;
switch (layoutDir)
{
case Direction.Clockwise:
if (intervalCount > 0) { this.radiusDelta = radiusRange / intervalCount; }
else { this.radiusDelta = 0; }
break;
case Direction.Counterclockwise:
case Direction.Bidirectional:
if (intervalCount > 0) { this.radiusDelta = radiusRange / intervalCount; }
else { this.radiusDelta = 0; }
break;
}
}
private static readonly Vector2 center = new Vector2(0.5f, 0.5f);
private void ProcessOneChild(RectTransform child, float angle, float radius)
{
Vector3 pos = new Vector3(
Mathf.Cos(angle * Mathf.Deg2Rad),
Mathf.Sin(angle * Mathf.Deg2Rad),
0.0f);
child.localPosition = pos * radius;
DrivenTransformProperties drivenProperties =
DrivenTransformProperties.Anchors | DrivenTransformProperties.AnchoredPosition | DrivenTransformProperties.Rotation | DrivenTransformProperties.Pivot;
m_Tracker.Add(this, child, drivenProperties);
child.anchorMin = center;
child.anchorMax = center;
child.pivot = center;
if (this.childRotate) { child.localEulerAngles = new Vector3(0, 0, angle); }
else { child.localEulerAngles = Vector3.zero; }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 675308088538b8340a8c91f8ac5d38e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: a6728f3c9bd53624fa556ca3f560cc9b, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,82 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace Michsky.MUIP
{
[CustomEditor(typeof(RadialLayoutGroup))]
public class RadialLayoutGroupEditor : Editor
{
private GUISkin customSkin;
private RadialLayoutGroup rlgTarget;
private int currentTab;
private SerializedProperty layoutDir;
private SerializedProperty radiusStart;
private SerializedProperty radiusRange;
private SerializedProperty angleStart;
private SerializedProperty angleCenter;
private SerializedProperty angleRange;
private SerializedProperty childRotate;
void OnEnable()
{
if (this.target == null)
return;
this.rlgTarget = this.target as RadialLayoutGroup;
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
var serObj = this.serializedObject;
this.layoutDir = serObj.FindProperty("refLayoutDir");
this.radiusStart = serObj.FindProperty("refRadiusStart");
this.radiusRange = serObj.FindProperty("refRadiusRange");
this.angleStart = serObj.FindProperty("refAngleStart");
this.angleCenter = serObj.FindProperty("refAngleCenter");
this.angleRange = serObj.FindProperty("refAngleRange");
this.childRotate = serObj.FindProperty("refChildRotate");
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "RLG Top Header");
GUIContent[] toolbarTabs = new GUIContent[1];
toolbarTabs[0] = new GUIContent("Settings");
currentTab = MUIPEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
currentTab = 0;
GUILayout.EndHorizontal();
serializedObject.Update();
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
GUILayout.BeginVertical(EditorStyles.helpBox);
MUIPEditorHandler.DrawPropertyPlain(layoutDir, customSkin, "Layout Direction");
EditorGUI.indentLevel = 1;
if (rlgTarget.layoutDir != RadialLayoutGroup.Direction.Bidirectional)
EditorGUILayout.PropertyField(angleStart, new GUIContent("Angle Start"));
else
EditorGUILayout.PropertyField(angleCenter, new GUIContent("Angle Center"));
EditorGUILayout.PropertyField(angleRange, new GUIContent("Angle Range"));
EditorGUILayout.PropertyField(radiusStart, new GUIContent("Radius Start"));
EditorGUILayout.PropertyField(radiusRange, new GUIContent("Radius Range"));
EditorGUI.indentLevel = 0;
GUILayout.EndVertical();
childRotate.boolValue = MUIPEditorHandler.DrawToggle(childRotate.boolValue, customSkin, "Rotate Child");
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 079ef68e9c033fd47ad1ce2e4a5550f8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f39f9ae0cf35ee64daac70a46d84623b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Michsky.MUIP
{
public class ListView : MonoBehaviour
{
// Resources
public Transform itemParent;
public GameObject itemPreset;
public GameObject scrollbar;
// Settings
public bool initializeOnAwake = true;
public bool showScrollbar = true;
public RowCount rowCount = RowCount.Two;
// Item list
[SerializeField]
public List<ListItem> listItems = new List<ListItem>();
[System.Serializable]
public class ListItem
{
public string itemTitle = "List Item";
[HideInInspector] public ListRow row0;
[HideInInspector] public ListRow row1;
[HideInInspector] public ListRow row2;
#if UNITY_EDITOR
[HideInInspector] public bool isExpanded;
#endif
}
[System.Serializable]
public class ListRow
{
public RowType rowType = RowType.Text;
public Sprite rowIcon;
public string rowText = "Row text";
public bool usePreferredWidth;
public int preferredWidth = 50;
[Range(0.1f, 1)] public float iconScale = 1;
}
public enum RowType { Icon, Text }
public enum RowCount { One, Two, Three }
void Awake()
{
if (itemParent == null) { Debug.LogError("<b>[List View]</b> 'Item Parent' is missing."); return; }
if (initializeOnAwake == true) { InitializeItems(); }
}
public void InitializeItems()
{
#if UNITY_EDITOR
if (Application.isPlaying == false) { for (int i = itemParent.childCount; i > 0; --i) { DestroyImmediate(itemParent.GetChild(0).gameObject); } }
else { foreach (Transform child in itemParent) { Destroy(child.gameObject); } }
#else
foreach (Transform child in itemParent) { Destroy(child.gameObject); }
#endif
for (int i = 0; i < listItems.Count; ++i)
{
GameObject go = Instantiate(itemPreset, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
go.transform.SetParent(itemParent, false);
go.name = listItems[i].itemTitle;
ListViewItem lvi = go.GetComponent<ListViewItem>();
lvi.rowCount = rowCount;
lvi.row0Ref = listItems[i].row0;
lvi.row1Ref = listItems[i].row1;
lvi.row2Ref = listItems[i].row2;
lvi.PassReferences();
}
if (showScrollbar == false && scrollbar != null) { scrollbar.transform.localScale = new Vector3(0, 0, 0); }
else if (showScrollbar == true && scrollbar != null) { scrollbar.transform.localScale = new Vector3(1, 1, 1); }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67a4caa482ba20f4a8749aba356f6fa9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 93f09189124b21e479fc891dbc1b93bf, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,257 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
namespace Michsky.MUIP
{
[CustomEditor(typeof(ListView))]
public class ListViewEditor : Editor
{
GUISkin customSkin;
private ListView lvTarget;
private int currentTab;
protected GUIStyle panelStyle;
protected GUIStyle lipStyle;
protected GUIStyle lipAltStyle;
Vector2 scrollPosition = Vector2.zero;
private void OnEnable()
{
lvTarget = (ListView)target;
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "LV Top Header");
Color defaultColor = GUI.color;
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 rowCount = serializedObject.FindProperty("rowCount");
var listItems = serializedObject.FindProperty("listItems");
var itemParent = serializedObject.FindProperty("itemParent");
var itemPreset = serializedObject.FindProperty("itemPreset");
var initializeOnAwake = serializedObject.FindProperty("initializeOnAwake");
var showScrollbar = serializedObject.FindProperty("showScrollbar");
var scrollbar = serializedObject.FindProperty("scrollbar");
// Foldout style
GUIStyle foldoutStyle = customSkin.FindStyle("UIM Foldout");
// Custom panel
panelStyle = new GUIStyle(GUI.skin.box);
panelStyle.normal.textColor = GUI.skin.label.normal.textColor;
panelStyle.margin = new RectOffset(0, 0, 0, 0);
panelStyle.padding = new RectOffset(0, 0, 0, 0);
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
GUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(listItems, new GUIContent("List Items"), true);
EditorGUI.indentLevel = 0;
if (GUILayout.Button("+ Add a new list item", customSkin.button))
{
ListView.ListItem item = new ListView.ListItem();
lvTarget.listItems.Add(item);
return;
}
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Customization Header", 10);
MUIPEditorHandler.DrawProperty(rowCount, customSkin, "Row Count");
if (lvTarget.listItems.Count == 0) { EditorGUILayout.HelpBox("There are no items in the list. ", MessageType.Info); }
else
{
int tempHeight;
if (lvTarget.listItems.Count < 3) { tempHeight = 0; }
else { tempHeight = 300; }
// Scroll panel
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Height(tempHeight));
GUILayout.BeginVertical(panelStyle);
for (int i = 0; i < lvTarget.listItems.Count; i++)
{
// Start Item Background
GUILayout.BeginVertical(EditorStyles.helpBox);
GUILayout.Space(5);
GUILayout.BeginHorizontal();
if (string.IsNullOrEmpty(lvTarget.listItems[i].itemTitle) == true) { lvTarget.listItems[i].isExpanded = EditorGUILayout.Foldout(lvTarget.listItems[i].isExpanded, "Item #" + i.ToString(), true, foldoutStyle); }
else { lvTarget.listItems[i].isExpanded = EditorGUILayout.Foldout(lvTarget.listItems[i].isExpanded, lvTarget.listItems[i].itemTitle, true, foldoutStyle); }
lvTarget.listItems[i].isExpanded = GUILayout.Toggle(lvTarget.listItems[i].isExpanded, new GUIContent(""), customSkin.FindStyle("Toggle Helper"));
GUILayout.EndHorizontal();
GUILayout.Space(2);
if (lvTarget.listItems[i].isExpanded)
{
// Row 1
GUILayout.BeginVertical(EditorStyles.helpBox);
// Row 1 Type
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Row #1 Type"), customSkin.FindStyle("Text"), GUILayout.Width(90));
lvTarget.listItems[i].row0.rowType = (ListView.RowType)EditorGUILayout.EnumPopup(lvTarget.listItems[i].row0.rowType);
GUILayout.EndHorizontal();
// Row 1 Content
EditorGUI.indentLevel++;
if (lvTarget.listItems[i].row0.rowType == ListView.RowType.Icon)
{
lvTarget.listItems[i].row0.rowIcon = EditorGUILayout.ObjectField(lvTarget.listItems[i].row0.rowIcon, typeof(Sprite), true) as Sprite;
lvTarget.listItems[i].row0.iconScale = EditorGUILayout.FloatField("Icon Scale", lvTarget.listItems[i].row0.iconScale);
}
else if (lvTarget.listItems[i].row0.rowType == ListView.RowType.Text)
{
lvTarget.listItems[i].row0.rowText = EditorGUILayout.TextField("Title", lvTarget.listItems[i].row0.rowText);
}
lvTarget.listItems[i].row0.usePreferredWidth = EditorGUILayout.Toggle("Use Preferred Width", lvTarget.listItems[i].row0.usePreferredWidth);
if (lvTarget.listItems[i].row0.usePreferredWidth == true) { lvTarget.listItems[i].row0.preferredWidth = EditorGUILayout.IntField("Preferred Width", lvTarget.listItems[i].row0.preferredWidth); }
EditorGUI.indentLevel--;
GUILayout.EndVertical();
// Row 2
if (rowCount.enumValueIndex > 0)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
// Row 2 Type
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Row #2 Type"), customSkin.FindStyle("Text"), GUILayout.Width(90));
lvTarget.listItems[i].row1.rowType = (ListView.RowType)EditorGUILayout.EnumPopup(lvTarget.listItems[i].row1.rowType);
GUILayout.EndHorizontal();
// Row 2 Content
EditorGUI.indentLevel++;
if (lvTarget.listItems[i].row1.rowType == ListView.RowType.Icon)
{
lvTarget.listItems[i].row1.rowIcon = EditorGUILayout.ObjectField(lvTarget.listItems[i].row1.rowIcon, typeof(Sprite), true) as Sprite;
lvTarget.listItems[i].row1.iconScale = EditorGUILayout.FloatField("Icon Scale", lvTarget.listItems[i].row1.iconScale);
}
else if (lvTarget.listItems[i].row1.rowType == ListView.RowType.Text)
{
lvTarget.listItems[i].row1.rowText = EditorGUILayout.TextField("Title", lvTarget.listItems[i].row1.rowText);
}
lvTarget.listItems[i].row1.usePreferredWidth = EditorGUILayout.Toggle("Use Preferred Width", lvTarget.listItems[i].row1.usePreferredWidth);
if (lvTarget.listItems[i].row1.usePreferredWidth == true) { lvTarget.listItems[i].row1.preferredWidth = EditorGUILayout.IntField("Preferred Width", lvTarget.listItems[i].row1.preferredWidth); }
EditorGUI.indentLevel--;
GUILayout.EndVertical();
}
// Row 3
if (rowCount.enumValueIndex > 1)
{
GUILayout.BeginVertical(EditorStyles.helpBox);
// Row 3 Type
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Row #3 Type"), customSkin.FindStyle("Text"), GUILayout.Width(90));
lvTarget.listItems[i].row2.rowType = (ListView.RowType)EditorGUILayout.EnumPopup(lvTarget.listItems[i].row2.rowType);
GUILayout.EndHorizontal();
// Row 3 Content
EditorGUI.indentLevel++;
if (lvTarget.listItems[i].row2.rowType == ListView.RowType.Icon)
{
lvTarget.listItems[i].row2.rowIcon = EditorGUILayout.ObjectField(lvTarget.listItems[i].row2.rowIcon, typeof(Sprite), true) as Sprite;
lvTarget.listItems[i].row2.iconScale = EditorGUILayout.FloatField("Icon Scale", lvTarget.listItems[i].row2.iconScale);
}
else if (lvTarget.listItems[i].row2.rowType == ListView.RowType.Text)
{
lvTarget.listItems[i].row2.rowText = EditorGUILayout.TextField("Title", lvTarget.listItems[i].row2.rowText);
}
lvTarget.listItems[i].row2.usePreferredWidth = EditorGUILayout.Toggle("Use Preferred Width", lvTarget.listItems[i].row2.usePreferredWidth);
if (lvTarget.listItems[i].row2.usePreferredWidth == true) { lvTarget.listItems[i].row2.preferredWidth = EditorGUILayout.IntField("Preferred Width", lvTarget.listItems[i].row2.preferredWidth); }
EditorGUI.indentLevel--;
GUILayout.EndVertical();
}
}
// End item
GUILayout.EndVertical();
}
if (GUILayout.Button("Pre-Initialize Items", customSkin.button)) { lvTarget.InitializeItems(); }
// Scroll Panel End
GUILayout.EndVertical();
GUILayout.EndScrollView();
if (GUI.enabled == true) { Repaint(); }
}
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(itemParent, customSkin, "Item Parent");
MUIPEditorHandler.DrawProperty(itemPreset, customSkin, "Item Preset");
MUIPEditorHandler.DrawProperty(scrollbar, customSkin, "Scrollbar");
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
initializeOnAwake.boolValue = MUIPEditorHandler.DrawToggle(initializeOnAwake.boolValue, customSkin, "Initialize On Awake");
showScrollbar.boolValue = MUIPEditorHandler.DrawToggle(showScrollbar.boolValue, customSkin, "Show Scrollbar");
if (GUILayout.Button("Sort List By Name (A to Z)")) { lvTarget.listItems.Sort(SortByNameAtoZ); }
if (GUILayout.Button("Sort List By Name (Z to A)")) { lvTarget.listItems.Sort(SortByNameZtoA); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
private static int SortByNameAtoZ(ListView.ListItem o1, ListView.ListItem o2)
{
// Compare the names and sort by A to Z
return o1.itemTitle.CompareTo(o2.itemTitle);
}
private static int SortByNameZtoA(ListView.ListItem o1, ListView.ListItem o2)
{
// Compare the names and sort by Z to A
return o2.itemTitle.CompareTo(o1.itemTitle);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e94e561fd83d42847a5ca2c2cf082bea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,88 @@
using UnityEngine;
namespace Michsky.MUIP
{
public class ListViewItem : MonoBehaviour
{
[Header("Settings")]
public ListViewRow row0;
public ListViewRow row1;
public ListViewRow row2;
[Header("References")]
public ListView.RowCount rowCount;
public ListView.ListRow row0Ref;
public ListView.ListRow row1Ref;
public ListView.ListRow row2Ref;
public void PassReferences()
{
if (rowCount == ListView.RowCount.One) { row0.gameObject.SetActive(true); row1.gameObject.SetActive(false); row2.gameObject.SetActive(false); }
else if (rowCount == ListView.RowCount.Two) { row0.gameObject.SetActive(true); row1.gameObject.SetActive(true); row2.gameObject.SetActive(false); }
else if (rowCount == ListView.RowCount.Three) { row0.gameObject.SetActive(true); row1.gameObject.SetActive(true); row2.gameObject.SetActive(true); }
// Row 1
if (row0Ref.rowType == ListView.RowType.Icon)
{
row0.iconImage.sprite = row0Ref.rowIcon;
row0.iconImage.gameObject.SetActive(true);
row0.textObject.gameObject.SetActive(false);
row0.iconImage.transform.localScale = new Vector3(row0Ref.iconScale, row0Ref.iconScale, row0Ref.iconScale);
}
else if (row0Ref.rowType == ListView.RowType.Text)
{
row0.textObject.text = row0Ref.rowText;
row0.iconImage.gameObject.SetActive(false);
row0.textObject.gameObject.SetActive(true);
}
if (row0Ref.usePreferredWidth == true) { row0.layoutElement.preferredWidth = row0Ref.preferredWidth; }
else { row0.layoutElement.preferredWidth = -1; }
// Row 2
if (row1Ref == null)
return;
if (row1Ref.rowType == ListView.RowType.Icon)
{
row1.iconImage.sprite = row1Ref.rowIcon;
row1.iconImage.gameObject.SetActive(true);
row1.textObject.gameObject.SetActive(false);
row1.iconImage.transform.localScale = new Vector3(row1Ref.iconScale, row1Ref.iconScale, row1Ref.iconScale);
}
else if (row1Ref.rowType == ListView.RowType.Text)
{
row1.textObject.text = row1Ref.rowText;
row1.iconImage.gameObject.SetActive(false);
row1.textObject.gameObject.SetActive(true);
}
if (row1Ref.usePreferredWidth == true) { row1.layoutElement.preferredWidth = row1Ref.preferredWidth; }
else { row1.layoutElement.preferredWidth = -1; }
// Row 3
if (row2Ref == null)
return;
if (row2Ref.rowType == ListView.RowType.Icon)
{
row2.iconImage.sprite = row2Ref.rowIcon;
row2.iconImage.gameObject.SetActive(true);
row2.textObject.gameObject.SetActive(false);
row2.iconImage.transform.localScale = new Vector3(row2Ref.iconScale, row2Ref.iconScale, row2Ref.iconScale);
}
else if (row2Ref.rowType == ListView.RowType.Text)
{
row2.textObject.text = row2Ref.rowText;
row2.iconImage.gameObject.SetActive(false);
row2.textObject.gameObject.SetActive(true);
}
if (row2Ref.usePreferredWidth == true) { row2.layoutElement.preferredWidth = row2Ref.preferredWidth; }
else { row2.layoutElement.preferredWidth = -1; }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e4851166b6d5f47478c1c34aac226415
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace Michsky.MUIP
{
public class ListViewRow : MonoBehaviour
{
[Header("Resources")]
public Image iconImage;
public TextMeshProUGUI textObject;
public LayoutElement layoutElement;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6980d488c131db45829d12b148fbb13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c07448e7c63fe24cb0480fd57c5824e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,131 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.Events;
namespace Michsky.MUIP
{
[RequireComponent(typeof(CanvasGroup))]
public class ModalWindowManager : MonoBehaviour
{
// Resources
public Image windowIcon;
public TextMeshProUGUI windowTitle;
public TextMeshProUGUI windowDescription;
public ButtonManager confirmButton;
public ButtonManager cancelButton;
public Animator mwAnimator;
// Content
public Sprite icon;
public string titleText = "Title";
[TextArea] public string descriptionText = "Description here";
// Events
public UnityEvent onOpen;
public UnityEvent onConfirm;
public UnityEvent onCancel;
// Settings
public bool useCustomContent = false;
public bool isOn = false;
public bool closeOnCancel = true;
public bool closeOnConfirm = true;
public bool showCancelButton = true;
public bool showConfirmButton = true;
public StartBehaviour startBehaviour = StartBehaviour.Disable;
public CloseBehaviour closeBehaviour = CloseBehaviour.Disable;
public enum StartBehaviour { None, Disable, Enable }
public enum CloseBehaviour { None, Disable, Destroy }
void Awake()
{
isOn = false;
if (mwAnimator == null) { mwAnimator = gameObject.GetComponent<Animator>(); }
if (closeOnCancel == true) { onCancel.AddListener(CloseWindow); }
if (closeOnConfirm == true) { onConfirm.AddListener(CloseWindow); }
if (confirmButton != null) { confirmButton.onClick.AddListener(onConfirm.Invoke); }
if (cancelButton != null) { cancelButton.onClick.AddListener(onCancel.Invoke); }
if (startBehaviour == StartBehaviour.Disable) { isOn = false; gameObject.SetActive(false); }
else if (startBehaviour == StartBehaviour.Enable) { isOn = false; OpenWindow(); }
UpdateUI();
}
public void UpdateUI()
{
if (useCustomContent == true)
return;
if (windowIcon != null) { windowIcon.sprite = icon; }
if (windowTitle != null) { windowTitle.text = titleText; }
if (windowDescription != null) { windowDescription.text = descriptionText; }
if (showCancelButton == true && cancelButton != null) { cancelButton.gameObject.SetActive(true); }
else if (cancelButton != null) { cancelButton.gameObject.SetActive(false); }
if (showConfirmButton == true && confirmButton != null) { confirmButton.gameObject.SetActive(true); }
else if (confirmButton != null) { confirmButton.gameObject.SetActive(false); }
}
public void Open()
{
if (isOn == false)
{
StopCoroutine("DisableObject");
gameObject.SetActive(true);
isOn = true;
onOpen.Invoke();
mwAnimator.Play("Fade-in");
}
}
public void Close()
{
if (isOn == true)
{
isOn = false;
mwAnimator.Play("Fade-out");
StartCoroutine("DisableObject");
}
}
// Obsolete
public void OpenWindow() { Open(); }
public void CloseWindow() { Close(); }
public void AnimateWindow()
{
if (isOn == false)
{
StopCoroutine("DisableObject");
isOn = true;
gameObject.SetActive(true);
mwAnimator.Play("Fade-in");
}
else
{
isOn = false;
mwAnimator.Play("Fade-out");
StartCoroutine("DisableObject");
}
}
IEnumerator DisableObject()
{
yield return new WaitForSeconds(1);
if (closeBehaviour == CloseBehaviour.Disable) { gameObject.SetActive(false); }
else if (closeBehaviour == CloseBehaviour.Destroy) { Destroy(gameObject); }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ff5b50d8ff89864090b86d1fee33b66
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 443b1643bec077e478f70a7a0fd1adcd, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,187 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
namespace Michsky.MUIP
{
[CustomEditor(typeof(ModalWindowManager))]
public class ModalWindowManagerEditor : Editor
{
private GUISkin customSkin;
private ModalWindowManager mwTarget;
private UIManagerModalWindow tempUIM;
private int currentTab;
private void OnEnable()
{
mwTarget = (ModalWindowManager)target;
try { tempUIM = mwTarget.GetComponent<UIManagerModalWindow>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "MW 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 windowIcon = serializedObject.FindProperty("windowIcon");
var windowTitle = serializedObject.FindProperty("windowTitle");
var windowDescription = serializedObject.FindProperty("windowDescription");
var onConfirm = serializedObject.FindProperty("onConfirm");
var onCancel = serializedObject.FindProperty("onCancel");
var onOpen = serializedObject.FindProperty("onOpen");
var icon = serializedObject.FindProperty("icon");
var titleText = serializedObject.FindProperty("titleText");
var descriptionText = serializedObject.FindProperty("descriptionText");
var confirmButton = serializedObject.FindProperty("confirmButton");
var cancelButton = serializedObject.FindProperty("cancelButton");
var mwAnimator = serializedObject.FindProperty("mwAnimator");
var useCustomContent = serializedObject.FindProperty("useCustomContent");
var closeBehaviour = serializedObject.FindProperty("closeBehaviour");
var startBehaviour = serializedObject.FindProperty("startBehaviour");
var closeOnCancel = serializedObject.FindProperty("closeOnCancel");
var closeOnConfirm = serializedObject.FindProperty("closeOnConfirm");
var showCancelButton = serializedObject.FindProperty("showCancelButton");
var showConfirmButton = serializedObject.FindProperty("showConfirmButton");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
if (useCustomContent.boolValue == false)
{
MUIPEditorHandler.DrawProperty(icon, customSkin, "Icon");
if (mwTarget.windowIcon != null) { mwTarget.windowIcon.sprite = mwTarget.icon; }
else if (mwTarget.windowIcon == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Icon Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
MUIPEditorHandler.DrawProperty(titleText, customSkin, "Title");
if (mwTarget.windowTitle != null) { mwTarget.windowTitle.text = titleText.stringValue; }
else if (mwTarget.windowTitle == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Title Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal(EditorStyles.helpBox);
EditorGUILayout.LabelField(new GUIContent("Description"), customSkin.FindStyle("Text"), GUILayout.Width(-3));
EditorGUILayout.PropertyField(descriptionText, new GUIContent(""), GUILayout.Height(80));
GUILayout.EndHorizontal();
if (mwTarget.windowDescription != null) { mwTarget.windowDescription.text = descriptionText.stringValue; }
else if (mwTarget.windowDescription == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Description Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
}
else { EditorGUILayout.HelpBox("'Use Custom Content' is enabled.", MessageType.Info); }
if (mwTarget.GetComponent<CanvasGroup>().alpha == 0)
{
if (GUILayout.Button("Make It Visible", customSkin.button))
{
mwTarget.GetComponent<CanvasGroup>().alpha = 1;
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
}
else
{
if (GUILayout.Button("Make It Invisible", customSkin.button))
{
mwTarget.GetComponent<CanvasGroup>().alpha = 0;
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
}
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
EditorGUILayout.PropertyField(onOpen, new GUIContent("On Open"), true);
EditorGUILayout.PropertyField(onConfirm, new GUIContent("On Confirm"), true);
EditorGUILayout.PropertyField(onCancel, new GUIContent("On Cancel"), true);
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(windowIcon, customSkin, "Icon Object");
MUIPEditorHandler.DrawProperty(windowTitle, customSkin, "Title Object");
MUIPEditorHandler.DrawProperty(windowDescription, customSkin, "Description Object");
MUIPEditorHandler.DrawProperty(confirmButton, customSkin, "Confirm Button");
MUIPEditorHandler.DrawProperty(cancelButton, customSkin, "Cancel Button");
MUIPEditorHandler.DrawProperty(mwAnimator, customSkin, "Animator");
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
MUIPEditorHandler.DrawProperty(startBehaviour, customSkin, "Start Behaviour");
MUIPEditorHandler.DrawProperty(closeBehaviour, customSkin, "Close Behaviour");
useCustomContent.boolValue = MUIPEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content");
closeOnCancel.boolValue = MUIPEditorHandler.DrawToggle(closeOnCancel.boolValue, customSkin, "Close Window On Cancel");
closeOnConfirm.boolValue = MUIPEditorHandler.DrawToggle(closeOnConfirm.boolValue, customSkin, "Close Window On Confirm");
showCancelButton.boolValue = MUIPEditorHandler.DrawToggle(showCancelButton.boolValue, customSkin, "Show Cancel Button");
showConfirmButton.boolValue = MUIPEditorHandler.DrawToggle(showConfirmButton.boolValue, customSkin, "Show Confirm Button");
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>[Modal Window]</b> Failed to delete UI Manager connection.", this); }
}
}
}
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a4a5d2752ec07da4aa46f6540abbd763
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c0db2f43179626c4c8c191409b03c43a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,116 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Events;
using TMPro;
namespace Michsky.MUIP
{
[DisallowMultipleComponent]
[RequireComponent(typeof(Animator))]
public class NotificationManager : MonoBehaviour
{
// Content
public Sprite icon;
public string title = "Notification Title";
[TextArea] public string description = "Notification description";
// Resources
public Animator notificationAnimator;
public Image iconObj;
public TextMeshProUGUI titleObj;
public TextMeshProUGUI descriptionObj;
// Settings
public bool enableTimer = true;
public float timer = 3f;
public bool useCustomContent = false;
public bool useStacking = false;
[HideInInspector] public bool isOn;
public StartBehaviour startBehaviour = StartBehaviour.Disable;
public CloseBehaviour closeBehaviour = CloseBehaviour.Disable;
// Events
public UnityEvent onOpen;
public UnityEvent onClose;
public enum StartBehaviour { None, Disable }
public enum CloseBehaviour { None, Disable, Destroy }
void Awake()
{
isOn = false;
if (useCustomContent == false) { UpdateUI(); }
if (notificationAnimator == null) { notificationAnimator = gameObject.GetComponent<Animator>(); }
if (startBehaviour == StartBehaviour.Disable) { gameObject.SetActive(false); }
if (useStacking == true)
{
try
{
NotificationStacking stacking = transform.GetComponentInParent<NotificationStacking>();
stacking.notifications.Add(this);
stacking.enableUpdating = true;
}
catch { Debug.LogError("<b>[Notification]</b> 'Stacking' is enabled but 'Notification Stacking' cannot be found in parent.", this); }
}
}
public void Open()
{
if (isOn == true)
return;
gameObject.SetActive(true);
isOn = true;
StopCoroutine("StartTimer");
StopCoroutine("DisableNotification");
notificationAnimator.Play("In");
onOpen.Invoke();
if (enableTimer == true) { StartCoroutine("StartTimer"); }
}
public void Close()
{
if (isOn == false)
return;
isOn = false;
notificationAnimator.Play("Out");
onClose.Invoke();
StartCoroutine("DisableNotification");
}
// Obsolete
public void OpenNotification() { Open(); }
public void CloseNotification() { Close(); }
public void UpdateUI()
{
if (iconObj != null) { iconObj.sprite = icon; }
if (titleObj != null) { titleObj.text = title; }
if (descriptionObj != null) { descriptionObj.text = description; }
}
IEnumerator StartTimer()
{
yield return new WaitForSeconds(timer);
CloseNotification();
StartCoroutine("DisableNotification");
}
IEnumerator DisableNotification()
{
yield return new WaitForSeconds(1f);
if (closeBehaviour == CloseBehaviour.Disable) { gameObject.SetActive(false); isOn = false; }
else if (closeBehaviour == CloseBehaviour.Destroy) { Destroy(gameObject); }
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b4bbdcf873a4164eabf85f0d7820717
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: adf3c8361dd31e1448483775ea241c10, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,191 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
namespace Michsky.MUIP
{
[CustomEditor(typeof(NotificationManager))]
public class NotificationManagerEditor : Editor
{
private GUISkin customSkin;
private NotificationManager ntfTarget;
private UIManagerNotification tempUIM;
private int currentTab;
private void OnEnable()
{
ntfTarget = (NotificationManager)target;
try { tempUIM = ntfTarget.GetComponent<UIManagerNotification>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "Notification 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 icon = serializedObject.FindProperty("icon");
var title = serializedObject.FindProperty("title");
var description = serializedObject.FindProperty("description");
var notificationAnimator = serializedObject.FindProperty("notificationAnimator");
var iconObj = serializedObject.FindProperty("iconObj");
var titleObj = serializedObject.FindProperty("titleObj");
var descriptionObj = serializedObject.FindProperty("descriptionObj");
var enableTimer = serializedObject.FindProperty("enableTimer");
var timer = serializedObject.FindProperty("timer");
var useCustomContent = serializedObject.FindProperty("useCustomContent");
var useStacking = serializedObject.FindProperty("useStacking");
var closeBehaviour = serializedObject.FindProperty("closeBehaviour");
var startBehaviour = serializedObject.FindProperty("startBehaviour");
var onOpen = serializedObject.FindProperty("onOpen");
var onClose = serializedObject.FindProperty("onClose");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
MUIPEditorHandler.DrawProperty(icon, customSkin, "Icon");
if (ntfTarget.iconObj != null)
ntfTarget.iconObj.sprite = ntfTarget.icon;
else
{
if (ntfTarget.iconObj == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Icon Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
}
MUIPEditorHandler.DrawProperty(title, customSkin, "Title");
if (ntfTarget.titleObj != null)
ntfTarget.titleObj.text = title.stringValue;
else
{
if (ntfTarget.titleObj == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Title Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
}
GUILayout.BeginHorizontal(EditorStyles.helpBox);
EditorGUILayout.LabelField(new GUIContent("Description"), customSkin.FindStyle("Text"), GUILayout.Width(-3));
EditorGUILayout.PropertyField(description, new GUIContent(""), GUILayout.Height(50));
GUILayout.EndHorizontal();
if (ntfTarget.descriptionObj != null)
ntfTarget.descriptionObj.text = description.stringValue;
else
{
if (ntfTarget.descriptionObj == null)
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("'Description Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
GUILayout.EndHorizontal();
}
}
if (ntfTarget.GetComponent<CanvasGroup>().alpha == 0)
{
if (GUILayout.Button("Make It Visible", customSkin.button))
{
ntfTarget.GetComponent<CanvasGroup>().alpha = 1;
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
}
else
{
if (GUILayout.Button("Make It Invisible", customSkin.button))
{
ntfTarget.GetComponent<CanvasGroup>().alpha = 0;
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
}
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
EditorGUILayout.PropertyField(onOpen, new GUIContent("On Open"), true);
EditorGUILayout.PropertyField(onClose, new GUIContent("On Close"), true);
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
MUIPEditorHandler.DrawProperty(notificationAnimator, customSkin, "Animator");
MUIPEditorHandler.DrawProperty(iconObj, customSkin, "Icon Object");
MUIPEditorHandler.DrawProperty(titleObj, customSkin, "Title Object");
MUIPEditorHandler.DrawProperty(descriptionObj, customSkin, "Description Object");
break;
case 2:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
MUIPEditorHandler.DrawProperty(startBehaviour, customSkin, "Start Behaviour");
MUIPEditorHandler.DrawProperty(closeBehaviour, customSkin, "Close Behaviour");
useCustomContent.boolValue = MUIPEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content");
useStacking.boolValue = MUIPEditorHandler.DrawToggle(useStacking.boolValue, customSkin, "Use Stacking");
enableTimer.boolValue = MUIPEditorHandler.DrawToggle(enableTimer.boolValue, customSkin, "Enable Timer");
if (enableTimer.boolValue == true)
MUIPEditorHandler.DrawProperty(timer, customSkin, "Timer");
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>[Notification Manager]</b> Failed to delete UI Manager connection.", this); }
}
}
}
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b72fc390a6760374ba76d6ae40841bac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Michsky.MUIP
{
[AddComponentMenu("Modern UI Pack/Notification/Notification Stacking")]
public class NotificationStacking : MonoBehaviour
{
public List<NotificationManager> notifications = new List<NotificationManager>();
[HideInInspector] public bool enableUpdating = false;
[Header("Settings")]
public float delay = 1;
int currentNotification = 0;
void Update()
{
if (enableUpdating == true)
{
try
{
notifications[currentNotification].gameObject.SetActive(true);
if (notifications[currentNotification].notificationAnimator.GetCurrentAnimatorStateInfo(0).IsName("Wait"))
{
notifications[currentNotification].OpenNotification();
StartCoroutine("StartNotification");
enableUpdating = false;
}
if (currentNotification >= notifications.Count)
{
enableUpdating = false;
currentNotification = 0;
}
}
catch
{
enableUpdating = false;
currentNotification = 0;
notifications.Clear();
}
}
}
IEnumerator StartNotification()
{
yield return new WaitForSeconds(notifications[currentNotification].timer + delay);
Destroy(notifications[currentNotification].gameObject);
// notifications.Remove(notifications[currentNotification]);
enableUpdating = true;
currentNotification += 1;
StopCoroutine("StartNotification");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d6e5a79c713c094fb2ea4246d215d24
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: adf3c8361dd31e1448483775ea241c10, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c6d490e1ba0a8d04ebc8d0cf69829e77
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b3d601986abab74cb6b3901c4bb2508
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: be8d03bb95afe0641976d654781e9e44, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
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 == false)
return;
if (currentPercent <= maxValue && invert == false) { currentPercent += speed * Time.deltaTime; }
else if (currentPercent >= minValue && invert == true) { currentPercent -= speed * Time.deltaTime; }
if (currentPercent >= maxValue && speed != 0 && restart == true && invert == false) { currentPercent = 0; }
else if (currentPercent <= minValue && speed != 0 && restart == true && invert == true) { currentPercent = maxValue; }
else if (currentPercent >= maxValue && speed != 0 && restart == false && invert == false) { currentPercent = maxValue; }
else if (currentPercent <= minValue && speed != 0 && restart == false && invert == true) { currentPercent = minValue; }
UpdateUI();
}
public void UpdateUI()
{
loadingBar.fillAmount = currentPercent / maxValue;
if (addSuffix == true) { textPercent.text = currentPercent.ToString("F" + decimals) + suffix; }
else { textPercent.text = currentPercent.ToString("F" + decimals); }
if (addPrefix == true)
textPercent.text = prefix + textPercent.text;
if (eventSource != null)
eventSource.value = currentPercent;
}
public void InitializeEvents()
{
if (Application.isPlaying == true && 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(); }
public void ChangeValue(float newValue) { currentPercent = newValue; UpdateUI(); }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20c6dbf0102c7bc468113ccdd97dad83
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: be8d03bb95afe0641976d654781e9e44, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View 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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e24fda0b81feb8343abb048c3c912da3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More