Initial Unity project commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93feaebba6181044899d22b5e0f2047e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,511 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class ButtonManager : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, 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;
|
||||
[SerializeField] private HorizontalLayoutGroup mainLayout;
|
||||
[SerializeField] private ContentSizeFitter mainFitter;
|
||||
[SerializeField] private ContentSizeFitter targetFitter;
|
||||
[SerializeField] private 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;
|
||||
[SerializeField] private GameObject rippleParent;
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool enableIcon = false;
|
||||
public bool enableText = true;
|
||||
public bool useCustomContent = false;
|
||||
[SerializeField] private 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;
|
||||
[SerializeField] private 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
|
||||
[SerializeField] private RippleUpdateMode rippleUpdateMode = RippleUpdateMode.UnscaledTime;
|
||||
[SerializeField] private Canvas targetCanvas;
|
||||
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);
|
||||
[SerializeField] private bool renderOnTop = false;
|
||||
[SerializeField] private bool centered = false;
|
||||
|
||||
// Helpers
|
||||
bool isInitialized = false;
|
||||
Button targetButton;
|
||||
bool isPointerOn;
|
||||
bool waitingForDoubleClickInput;
|
||||
const int navHelper = 1;
|
||||
|
||||
#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()
|
||||
{
|
||||
if (!isInitialized) { Initialize(); }
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
if (disabledCG != null) { disabledCG.alpha = 0; }
|
||||
if (normalCG != null) { normalCG.alpha = 1; }
|
||||
if (highlightCG != null) { highlightCG.alpha = 0; }
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying) { return; }
|
||||
#endif
|
||||
if (animationSolution == AnimationSolution.ScriptBased && TryGetComponent<Animator>(out var tempAnimator)) { Destroy(tempAnimator); }
|
||||
if (gameObject.GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
if (targetCanvas == null) { targetCanvas = GetComponentInParent<Canvas>(); }
|
||||
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 && rippleParent != null) { rippleParent.SetActive(false); }
|
||||
else if (!useRipple && rippleParent != null) { Destroy(rippleParent); }
|
||||
|
||||
if (gameObject.activeInHierarchy) { StartCoroutine(nameof(LayoutFix)); }
|
||||
if (targetButton == null)
|
||||
{
|
||||
if (gameObject.GetComponent<Button>() == null) { targetButton = gameObject.AddComponent<Button>(); }
|
||||
else { targetButton = GetComponent<Button>(); }
|
||||
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = Navigation.Mode.None;
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
if (useUINavigation) { AddUINavigation(); }
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
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) { normalCG.alpha = 1; }
|
||||
if (disabledCG != null && !isInteractable) { disabledCG.alpha = 1; }
|
||||
if (highlightCG != null) { highlightCG.alpha = 0; }
|
||||
|
||||
if (!useCustomContent)
|
||||
{
|
||||
|
||||
if (enableText)
|
||||
{
|
||||
if (normalText != null)
|
||||
{
|
||||
normalText.gameObject.SetActive(true);
|
||||
normalText.text = buttonText;
|
||||
if (!useCustomTextSize) { normalText.fontSize = textSize; }
|
||||
}
|
||||
|
||||
if (highlightedText != null)
|
||||
{
|
||||
highlightedText.gameObject.SetActive(true);
|
||||
highlightedText.text = buttonText;
|
||||
if (!useCustomTextSize) { highlightedText.fontSize = textSize; }
|
||||
}
|
||||
|
||||
if (disabledText != null)
|
||||
{
|
||||
disabledText.gameObject.SetActive(true);
|
||||
disabledText.text = buttonText;
|
||||
if (!useCustomTextSize) { disabledText.fontSize = textSize; }
|
||||
}
|
||||
}
|
||||
|
||||
else if (!enableText)
|
||||
{
|
||||
if (normalText != null) { normalText.gameObject.SetActive(false); }
|
||||
if (highlightedText != null) { highlightedText.gameObject.SetActive(false); }
|
||||
if (disabledText != null) { disabledText.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
if (enableIcon)
|
||||
{
|
||||
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 && autoFitContent)
|
||||
{
|
||||
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 || !gameObject.activeInHierarchy) { return; }
|
||||
if (!isInteractable) { StartCoroutine(nameof(SetDisabled)); }
|
||||
else if (isInteractable && disabledCG.alpha == 1) { StartCoroutine(nameof(SetNormal)); }
|
||||
|
||||
StartCoroutine(nameof(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) { return; }
|
||||
if (!isInteractable) { StartCoroutine(nameof(SetDisabled)); }
|
||||
else if (isInteractable && disabledCG.alpha == 1) { StartCoroutine(nameof(SetNormal)); }
|
||||
}
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
if (targetButton == null)
|
||||
return;
|
||||
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
Navigation customNav = new Navigation
|
||||
{
|
||||
mode = navigationMode
|
||||
};
|
||||
|
||||
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
|
||||
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine(nameof(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 || eventData.button != PointerEventData.InputButton.Left) { return; }
|
||||
if (enableButtonSounds && useClickSound == true && soundSource != null) { soundSource.PlayOneShot(clickSound); }
|
||||
|
||||
// Invoke click actions
|
||||
onClick.Invoke();
|
||||
|
||||
// Check for double click
|
||||
if (checkForDoubleClick == false || !gameObject.activeInHierarchy) { return; }
|
||||
if (waitingForDoubleClickInput == true)
|
||||
{
|
||||
onDoubleClick.Invoke();
|
||||
waitingForDoubleClickInput = false;
|
||||
return;
|
||||
}
|
||||
|
||||
waitingForDoubleClickInput = true;
|
||||
|
||||
StopCoroutine("CheckForDoubleClick");
|
||||
StartCoroutine("CheckForDoubleClick");
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine(nameof(SetHighlight)); }
|
||||
if (useRipple)
|
||||
#else
|
||||
if (useRipple && isPointerOn)
|
||||
#endif
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
if (targetCanvas != null && (targetCanvas.renderMode == RenderMode.ScreenSpaceCamera || targetCanvas.renderMode == RenderMode.WorldSpace)) { CreateRipple(targetCanvas.worldCamera.ScreenToWorldPoint(Input.mousePosition)); }
|
||||
else { CreateRipple(Input.mousePosition); }
|
||||
#elif ENABLE_INPUT_SYSTEM
|
||||
if (targetCanvas != null && (targetCanvas.renderMode == RenderMode.ScreenSpaceCamera || targetCanvas.renderMode == RenderMode.WorldSpace)) { CreateRipple(targetCanvas.worldCamera.ScreenToWorldPoint(Mouse.current.position.ReadValue())); }
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
else { CreateRipple(Touchscreen.current.primaryTouch.position.ReadValue()); }
|
||||
#else
|
||||
else { CreateRipple(Mouse.current.position.ReadValue()); }
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
if (!isInteractable) { return; }
|
||||
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine(nameof(SetNormal)); }
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (enableButtonSounds && useHoverSound && soundSource != null) { soundSource.PlayOneShot(hoverSound); }
|
||||
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine(nameof(SetHighlight)); }
|
||||
|
||||
isPointerOn = true;
|
||||
onHover.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine(nameof(SetNormal)); }
|
||||
|
||||
isPointerOn = false;
|
||||
onLeave.Invoke();
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine(nameof(SetHighlight)); }
|
||||
if (useUINavigation) { onHover.Invoke(); }
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine(nameof(SetNormal)); }
|
||||
if (useUINavigation) { onLeave.Invoke(); }
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (animationSolution == AnimationSolution.ScriptBased) { StartCoroutine(nameof(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(nameof(SetHighlight));
|
||||
StopCoroutine(nameof(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(nameof(SetNormal));
|
||||
StopCoroutine(nameof(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(nameof(SetNormal));
|
||||
StopCoroutine(nameof(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(navHelper);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Button/ButtonManager.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,357 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
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 targetCanvas = serializedObject.FindProperty("targetCanvas");
|
||||
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);
|
||||
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);
|
||||
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(targetCanvas, customSkin, "Target Canvas");
|
||||
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(MUIPEditorHandler.UIM_SHORTCUT);
|
||||
|
||||
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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4027e626241ca4140aa30808faae978a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Button/ButtonManagerEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7e0b87066b687e449d3c6c7bef1a8fd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e4a4384d3c229846b0d84dc8ec948dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 3ae7671fb73a5df4ebec7a6b32ae8e8c, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Charts/PieChart.cs
|
||||
uploadId: 778406
|
||||
@@ -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(MUIPEditorHandler.UIM_SHORTCUT);
|
||||
|
||||
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
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e02c02515eb09c04caeb0ab2d66d83da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Charts/PieChartEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24042a316d186e24cb8ff5555642e401
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
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>();
|
||||
|
||||
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
|
||||
{
|
||||
#if UNITY_2023_2_OR_NEWER
|
||||
contextManager = FindObjectsByType<ContextMenuManager>(FindObjectsSortMode.None)[0];
|
||||
#else
|
||||
contextManager = (ContextMenuManager)FindObjectsOfType(typeof(ContextMenuManager))[0];
|
||||
#endif
|
||||
itemParent = contextManager.transform.Find("Content/Item List").transform;
|
||||
}
|
||||
|
||||
catch { Debug.LogError("<b>[Context Menu]</b> Context Manager is missing.", this); return; }
|
||||
}
|
||||
|
||||
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(contextManager.Close);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
contextManager.Open();
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (contextManager.isOn == true) { contextManager.Close(); }
|
||||
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);
|
||||
}
|
||||
|
||||
#if !UNITY_IOS && !UNITY_ANDROID
|
||||
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();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public void AddNewItem()
|
||||
{
|
||||
ContextItem item = new ContextItem();
|
||||
contexItems.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe4f202dc85015b48aa586eba6d38692
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: cceded5b1d0834e48849fb152ac8e53d, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Context Menu/ContextMenuContent.cs
|
||||
uploadId: 778406
|
||||
+86
@@ -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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6027ca9dc17f95b4f8e126a1326329ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Context Menu/ContextMenuContentEditor.cs
|
||||
uploadId: 778406
|
||||
+159
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f93b797e33a2590489a95b86d8490887
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: cceded5b1d0834e48849fb152ac8e53d, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Context Menu/ContextMenuContentMobile.cs
|
||||
uploadId: 778406
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
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
|
||||
[SerializeField] private bool debugMode;
|
||||
public bool autoSubMenuPosition = true;
|
||||
public SubMenuBehaviour subMenuBehaviour;
|
||||
public CameraSource cameraSource = CameraSource.Main;
|
||||
|
||||
// Bounds
|
||||
public CursorBoundHorizontal horizontalBound;
|
||||
public CursorBoundVertical verticalBound;
|
||||
[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;
|
||||
|
||||
public enum CameraSource { Main, Custom }
|
||||
public enum SubMenuBehaviour { Hover, Click }
|
||||
public enum CursorBoundHorizontal { Left, Right }
|
||||
public enum CursorBoundVertical { Bottom, Top }
|
||||
|
||||
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 CheckForBound()
|
||||
{
|
||||
if (uiPos.x <= -100)
|
||||
{
|
||||
horizontalBound = CursorBoundHorizontal.Left;
|
||||
contentPos = new Vector3(hBorderLeft, contentPos.y, 0); contentRect.pivot = new Vector2(0f, contentRect.pivot.y);
|
||||
}
|
||||
|
||||
else if (uiPos.x >= 100)
|
||||
{
|
||||
horizontalBound = CursorBoundHorizontal.Right;
|
||||
contentPos = new Vector3(hBorderRight, contentPos.y, 0); contentRect.pivot = new Vector2(1f, contentRect.pivot.y);
|
||||
}
|
||||
|
||||
if (uiPos.y <= -75)
|
||||
{
|
||||
verticalBound = CursorBoundVertical.Bottom;
|
||||
contentPos = new Vector3(contentPos.x, vBorderBottom, 0); contentRect.pivot = new Vector2(contentRect.pivot.x, 0f);
|
||||
}
|
||||
|
||||
else if (uiPos.y >= 75)
|
||||
{
|
||||
verticalBound = CursorBoundVertical.Top;
|
||||
contentPos = new Vector3(contentPos.x, vBorderTop, 0); contentRect.pivot = new Vector2(contentRect.pivot.x, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetContextMenuPosition()
|
||||
{
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
cursorPos = Input.mousePosition;
|
||||
#elif ENABLE_INPUT_SYSTEM
|
||||
cursorPos = Mouse.current.position.ReadValue();
|
||||
#endif
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
uiPos = contextRect.anchoredPosition;
|
||||
CheckForBound();
|
||||
|
||||
if (debugMode == true)
|
||||
{
|
||||
PrintDebug();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFixedPosition()
|
||||
{
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
cursorPos = Input.mousePosition;
|
||||
#elif ENABLE_INPUT_SYSTEM
|
||||
cursorPos = Mouse.current.position.ReadValue();
|
||||
#endif
|
||||
SetContextMenuPosition();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
uiPos = contextRect.anchoredPosition;
|
||||
CheckForBound();
|
||||
|
||||
if (debugMode == true)
|
||||
{
|
||||
PrintDebug();
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessContextRect()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintDebug()
|
||||
{
|
||||
Debug.Log("<b>[Context Menu]</b> UI Pos: " + uiPos + ", H: " + horizontalBound + ", V: " + verticalBound, this);
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
contextAnimator.Play("Menu In");
|
||||
isOn = true;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
contextAnimator.Play("Menu Out");
|
||||
isOn = false;
|
||||
}
|
||||
|
||||
public void OpenInFixedPosition()
|
||||
{
|
||||
SetFixedPosition();
|
||||
Open();
|
||||
}
|
||||
|
||||
#region Obsolote
|
||||
public void OpenContextMenu() { Open(); }
|
||||
public void CloseOnClick() { Close(); }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9021c5c7bd04ec245bf10c985a37c848
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: cceded5b1d0834e48849fb152ac8e53d, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Context Menu/ContextMenuManager.cs
|
||||
uploadId: 778406
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
#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");
|
||||
var debugMode = serializedObject.FindProperty("debugMode");
|
||||
|
||||
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);
|
||||
debugMode.boolValue = MUIPEditorHandler.DrawToggle(debugMode.boolValue, customSkin, "Debug Mode");
|
||||
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(MUIPEditorHandler.UIM_SHORTCUT);
|
||||
|
||||
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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 527585204cee0694b9800f8f51baace0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Context Menu/ContextMenuManagerEditor.cs
|
||||
uploadId: 778406
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
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.horizontalBound == ContextMenuManager.CursorBoundHorizontal.Left) { listParent.pivot = new Vector2(0f, listParent.pivot.y); }
|
||||
else if (cmManager.horizontalBound == ContextMenuManager.CursorBoundHorizontal.Right) { listParent.pivot = new Vector2(1f, listParent.pivot.y); }
|
||||
|
||||
if (cmManager.verticalBound == ContextMenuManager.CursorBoundVertical.Top) { listParent.pivot = new Vector2(listParent.pivot.x, 0f); }
|
||||
else if (cmManager.verticalBound == ContextMenuManager.CursorBoundVertical.Bottom) { 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d93fb32bb7e8384d863c98e08445c2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Context Menu/ContextMenuSubMenu.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 363a9fdea62181342b3ad1b7419f1420
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class MUIPInternalTools : MonoBehaviour
|
||||
{
|
||||
public static string modalWindowStateName = "Fade-out";
|
||||
public static string windowManagerStateName = "WM Window Out";
|
||||
|
||||
public static float GetAnimatorClipLength(Animator _animator, string _clipName)
|
||||
{
|
||||
float _lengthValue = -1;
|
||||
RuntimeAnimatorController _rac = _animator.runtimeAnimatorController;
|
||||
|
||||
for (int i = 0; i < _rac.animationClips.Length; i++)
|
||||
{
|
||||
if (_rac.animationClips[i].name == _clipName)
|
||||
{
|
||||
_lengthValue = _rac.animationClips[i].length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return _lengthValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95af5c5e221987642aecaf2d59a3469a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Core/MUIPInternalTools.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fd2bd6ff4a0be1448b7c7b9db99c03e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,226 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
#if !ENABLE_LEGACY_INPUT_MANAGER
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7afc8c12ad2e104ebc86906fc37ec31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Demo/DemoElementSway.cs
|
||||
uploadId: 778406
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fa48de8543315549bf27cc38c7eceea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Demo/DemoElementSwayParent.cs
|
||||
uploadId: 778406
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e373f9a5f6c9bab449c78beab64a8d53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Demo/DemoListShadow.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem.UI;
|
||||
#endif
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class InputSystemChecker : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
|
||||
|
||||
if (!gameObject.TryGetComponent<InputSystemUIInputModule>(out var tempModule))
|
||||
{
|
||||
gameObject.AddComponent<InputSystemUIInputModule>();
|
||||
if (gameObject.TryGetComponent<StandaloneInputModule>(out var oldModule)) { Destroy(oldModule); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dfe135108c08d54d8978d026b05b601
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Demo/InputSystemChecker.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class LaunchURL : MonoBehaviour
|
||||
{
|
||||
public void GoToURL(string URL)
|
||||
{
|
||||
Application.OpenURL(URL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 731973609e4a7a94aa4d2f33c86dc13f
|
||||
timeCreated: 1493639454
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Demo/LaunchURL.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0673eef6087e6b41af2be453632efb5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,380 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
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 AudioSource soundSource;
|
||||
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 = new DropdownEvent();
|
||||
[System.Serializable] public class ItemTextChangedEvent : UnityEvent<TMP_Text> { }
|
||||
public ItemTextChangedEvent onItemTextChanged = new ItemTextChangedEvent();
|
||||
|
||||
// Audio
|
||||
public AudioClip hoverSound;
|
||||
public AudioClip clickSound;
|
||||
|
||||
// Helpers
|
||||
bool isInitialized = false;
|
||||
[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 OnEnable()
|
||||
{
|
||||
if (!isInitialized) { Initialize(); }
|
||||
if (updateOnEnable && index < items.Count) { SetDropdownIndex(selectedItemIndex, false); }
|
||||
|
||||
listCG.alpha = 0;
|
||||
listCG.interactable = false;
|
||||
listCG.blocksRaycasts = false;
|
||||
listRect.sizeDelta = new Vector2(listRect.sizeDelta.x, 0);
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
if (enableTrigger && 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)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
|
||||
dropdownAnimator = gameObject.GetComponent<Animator>();
|
||||
|
||||
if (listCG == null) { listCG = gameObject.GetComponentInChildren<CanvasGroup>(); }
|
||||
if (listRect == null) { listRect = listCG.GetComponent<RectTransform>(); }
|
||||
if (initAtStart && items.Count != 0) { SetupDropdown(); }
|
||||
if (animationType == AnimationType.Modular && dropdownAnimator != null) { Destroy(dropdownAnimator); }
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
public void SetupDropdown()
|
||||
{
|
||||
if (!enableScrollbar && 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);
|
||||
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) { PlayerPrefs.SetInt("Dropdown_" + saveKey, mainItem.itemIndex); }
|
||||
});
|
||||
}
|
||||
|
||||
if (selectedImage != null && !enableIcon) { 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)
|
||||
{
|
||||
if (invokeAtStart) { items[PlayerPrefs.GetInt("Dropdown_" + saveKey)].OnItemSelection.Invoke(); }
|
||||
else { SetDropdownIndex(PlayerPrefs.GetInt("Dropdown_" + saveKey), false); }
|
||||
}
|
||||
else if (invokeAtStart) { items[selectedItemIndex].OnItemSelection.Invoke(); }
|
||||
}
|
||||
|
||||
// Obsolete
|
||||
public void ChangeDropdownInfo(int itemIndex)
|
||||
{
|
||||
SetDropdownIndex(itemIndex);
|
||||
}
|
||||
|
||||
public void SetDropdownIndex(int itemIndex)
|
||||
{
|
||||
SetDropdownIndex(itemIndex, true);
|
||||
}
|
||||
|
||||
public void SetDropdownIndex(int itemIndex, bool bypassSound = false)
|
||||
{
|
||||
if (selectedImage != null && enableIcon && items[itemIndex].itemIcon != null) { selectedImage.gameObject.SetActive(true); selectedImage.sprite = items[itemIndex].itemIcon; }
|
||||
else if (selectedImage != null && enableIcon && items[itemIndex].itemIcon == null) { selectedImage.gameObject.SetActive(false); }
|
||||
if (selectedText != null) { selectedText.text = items[itemIndex].itemName; onItemTextChanged?.Invoke(selectedText); }
|
||||
if (!bypassSound && enableDropdownSounds && useClickSound) { soundSource.PlayOneShot(clickSound); }
|
||||
|
||||
selectedItemIndex = itemIndex;
|
||||
}
|
||||
|
||||
public void Animate()
|
||||
{
|
||||
if (!isOn && animationType == AnimationType.Modular)
|
||||
{
|
||||
isOn = true;
|
||||
listCG.blocksRaycasts = true;
|
||||
listCG.interactable = true;
|
||||
listCG.gameObject.SetActive(true);
|
||||
|
||||
StopCoroutine("StartMinimize");
|
||||
StopCoroutine("StartExpand");
|
||||
StartCoroutine("StartExpand");
|
||||
}
|
||||
|
||||
else if (isOn && animationType == AnimationType.Modular)
|
||||
{
|
||||
isOn = false;
|
||||
listCG.blocksRaycasts = false;
|
||||
listCG.interactable = false;
|
||||
|
||||
StopCoroutine("StartMinimize");
|
||||
StopCoroutine("StartExpand");
|
||||
StartCoroutine("StartMinimize");
|
||||
}
|
||||
|
||||
else if (!isOn && animationType == AnimationType.Custom)
|
||||
{
|
||||
dropdownAnimator.Play("Stylish In");
|
||||
isOn = true;
|
||||
}
|
||||
|
||||
else if (isOn && animationType == AnimationType.Custom)
|
||||
{
|
||||
dropdownAnimator.Play("Stylish Out");
|
||||
isOn = false;
|
||||
}
|
||||
|
||||
if (enableTrigger && !isOn) { triggerObject.SetActive(false); }
|
||||
else if (enableTrigger && isOn) { triggerObject.SetActive(true); }
|
||||
if (enableTrigger && outOnPointerExit) { triggerObject.SetActive(false); }
|
||||
}
|
||||
|
||||
public void Interactable(bool value)
|
||||
{
|
||||
isInteractable = value;
|
||||
}
|
||||
|
||||
public void CreateNewItem(string title, Sprite icon, bool notify = false)
|
||||
{
|
||||
Item item = new Item
|
||||
{
|
||||
itemName = title,
|
||||
itemIcon = icon
|
||||
};
|
||||
items.Add(item);
|
||||
|
||||
if (selectedItemIndex > items.Count) { selectedItemIndex = 0; }
|
||||
if (notify) { SetupDropdown(); }
|
||||
}
|
||||
|
||||
public void CreateNewItem(string title, bool notify = false)
|
||||
{
|
||||
Item item = new Item
|
||||
{
|
||||
itemName = title
|
||||
};
|
||||
items.Add(item);
|
||||
|
||||
if (selectedItemIndex > items.Count) { selectedItemIndex = 0; }
|
||||
if (notify) { SetupDropdown(); }
|
||||
}
|
||||
|
||||
public void RemoveItem(string itemTitle, bool notify = false)
|
||||
{
|
||||
var item = items.Find(x => x.itemName == itemTitle);
|
||||
items.Remove(item);
|
||||
|
||||
if (selectedItemIndex > items.Count) { selectedItemIndex = 0; }
|
||||
if (notify) { 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) { return; }
|
||||
if (enableDropdownSounds && useClickSound) { soundSource.PlayOneShot(clickSound); }
|
||||
|
||||
Animate();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (enableDropdownSounds && useHoverSound) { soundSource.PlayOneShot(hoverSound); }
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (outOnPointerExit && isOn) { Animate(); isOn = false; }
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (enableDropdownSounds && useClickSound) { 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3c6e5718ae5e9246af72590402986a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 0a39a4452fd810640afd1be6e700edee, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdown.cs
|
||||
uploadId: 778406
|
||||
+321
@@ -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(82));
|
||||
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(MUIPEditorHandler.UIM_SHORTCUT);
|
||||
|
||||
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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 227402b59bd462249a7f83d4fee619fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdownEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,321 @@
|
||||
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;
|
||||
public CanvasGroup contentCG;
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool initAtStart = true;
|
||||
public bool enableIcon = true;
|
||||
public bool enableTrigger = true;
|
||||
public bool enableScrollbar = true;
|
||||
public bool setHighPriority = 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
|
||||
bool isInitialized = false;
|
||||
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 (isInitialized == false) { Initialize(); }
|
||||
|
||||
listCG.alpha = 0;
|
||||
listCG.interactable = false;
|
||||
listCG.blocksRaycasts = false;
|
||||
listRect.sizeDelta = new Vector2(listRect.sizeDelta.x, closeOn);
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
if (listCG == null) { listCG = gameObject.GetComponentInChildren<CanvasGroup>(); }
|
||||
if (listRect == null) { listRect = listCG.GetComponent<RectTransform>(); }
|
||||
if (initAtStart == true) { SetupDropdown(); }
|
||||
if (animationType == AnimationType.Modular && dropdownAnimator != null) { Destroy(dropdownAnimator); }
|
||||
|
||||
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>();
|
||||
}
|
||||
|
||||
currentListParent = transform.parent;
|
||||
closeOn = gameObject.GetComponent<RectTransform>().sizeDelta.y;
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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); }
|
||||
}
|
||||
|
||||
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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9142f1b2d4f467c49af32a1445cf9117
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 0a39a4452fd810640afd1be6e700edee, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/DropdownMultiSelect.cs
|
||||
uploadId: 778406
|
||||
+199
@@ -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 setHighPriority = serializedObject.FindProperty("setHighPriority");
|
||||
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();
|
||||
}
|
||||
|
||||
setHighPriority.boolValue = MUIPEditorHandler.DrawToggle(setHighPriority.boolValue, customSkin, "Set High Priority");
|
||||
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(MUIPEditorHandler.UIM_SHORTCUT);
|
||||
|
||||
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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11fa941289c070249b66bfda86e99c36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/DropdownMultiSelectEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5de90d83aba420940bf5dab364e530ca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class MUIPEditorHandler : Editor
|
||||
{
|
||||
public const string UIM_SHORTCUT = "Tools/Modern UI Pack/Open UI Manager %#M";
|
||||
|
||||
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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b3d37a8c2278a54380cde1dbb7524d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Editor Handlers/MUIPEditorHandler.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e80c1147aaddb0842b5ed350af305d52
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+339
@@ -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)
|
||||
{
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (gameObject.activeInHierarchy) { StartCoroutine("DisableAnimator"); }
|
||||
}
|
||||
|
||||
public void SetupSelector()
|
||||
{
|
||||
if (items.Count == 0)
|
||||
return;
|
||||
|
||||
if (saveSelected)
|
||||
{
|
||||
if (PlayerPrefs.HasKey("HorizontalSelector_" + saveKey)) { 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)
|
||||
{
|
||||
labelIcon.sprite = items[defaultIndex].itemIcon;
|
||||
labelIconHelper.sprite = labelIcon.sprite;
|
||||
}
|
||||
|
||||
else if (!enableIcon)
|
||||
{
|
||||
if (labelIcon != null) { labelIcon.gameObject.SetActive(false); }
|
||||
if (labelIconHelper != null) { labelIconHelper.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
index = defaultIndex;
|
||||
|
||||
if (enableIndicators) { UpdateIndicators(); }
|
||||
else if (indicatorParent != null) { Destroy(indicatorParent.gameObject); }
|
||||
}
|
||||
|
||||
public void PreviousItem()
|
||||
{
|
||||
if (items.Count == 0)
|
||||
return;
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
selectorAnimator.enabled = true;
|
||||
|
||||
if (!loopSelection)
|
||||
{
|
||||
if (index != 0)
|
||||
{
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon) { 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) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
if (invertAnimation) { selectorAnimator.Play("Forward"); }
|
||||
else { selectorAnimator.Play("Previous"); }
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon) { 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) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
if (invertAnimation) { selectorAnimator.Play("Forward"); }
|
||||
else { selectorAnimator.Play("Previous"); }
|
||||
}
|
||||
|
||||
if (saveSelected) { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, index); }
|
||||
if (gameObject.activeInHierarchy) { StartCoroutine("DisableAnimator"); }
|
||||
if (enableIndicators)
|
||||
{
|
||||
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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NextItem()
|
||||
{
|
||||
if (items.Count == 0)
|
||||
return;
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
selectorAnimator.enabled = true;
|
||||
|
||||
if (!loopSelection)
|
||||
{
|
||||
if (index != items.Count - 1)
|
||||
{
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon) { 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) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
if (invertAnimation) { selectorAnimator.Play("Previous"); }
|
||||
else { selectorAnimator.Play("Forward"); }
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon) { 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) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
if (invertAnimation) { selectorAnimator.Play("Previous"); }
|
||||
else { selectorAnimator.Play("Forward"); }
|
||||
}
|
||||
|
||||
if (saveSelected) { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, index); }
|
||||
if (enableIndicators)
|
||||
{
|
||||
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) { 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) { labelIcon.sprite = items[index].itemIcon; }
|
||||
if (gameObject.activeInHierarchy) { StartCoroutine("DisableAnimator"); }
|
||||
|
||||
UpdateContentLayout();
|
||||
UpdateIndicators();
|
||||
}
|
||||
|
||||
public void UpdateIndicators()
|
||||
{
|
||||
if (!enableIndicators)
|
||||
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);
|
||||
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 WaitForSecondsRealtime(0.5f);
|
||||
selectorAnimator.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 125c77e2c7bf16f4792824151a1d9249
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7a33180745301ca4b903e0c6e51cfeb6, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Horizontal Selector/HorizontalSelector.cs
|
||||
uploadId: 778406
|
||||
Vendored
+217
@@ -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(82));
|
||||
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(MUIPEditorHandler.UIM_SHORTCUT); }
|
||||
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
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dc4a3eba298e1c4b851efe79a336cb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Horizontal Selector/HorizontalSelectorEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e158faa1d0027ba4ea870c2750e8d40e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86b8e0ba11d23674b90c578d7eec2d09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 3ed3bfb48269e2646b4dc2130299c956, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Icon/AnimatedIconHandler.cs
|
||||
uploadId: 778406
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Icon/IconLibrary.cs
|
||||
uploadId: 778406
|
||||
@@ -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
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1161e041bde9c9f4f9d1118349cd5968
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Icon/IconLibraryEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -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 + "'"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 603d9687b95941549aee6d293dae7de4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 3ed3bfb48269e2646b4dc2130299c956, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Icon/IconManager.cs
|
||||
uploadId: 778406
|
||||
@@ -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
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc8d4f7f18559ed43b3f3074a40553e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Icon/IconManagerEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca95fe39461d3be48b5e7c489913b16f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,150 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
#if !ENABLE_LEGACY_INPUT_MANAGER
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[RequireComponent(typeof(TMP_InputField))]
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class CustomInputField : MonoBehaviour
|
||||
{
|
||||
[Header("Resources")]
|
||||
public TMP_InputField inputText;
|
||||
[SerializeField] private Animator inputFieldAnimator;
|
||||
|
||||
[Header("Settings")]
|
||||
public bool processSubmit = false;
|
||||
public bool clearOnSubmit = true;
|
||||
[Tooltip("Set the current event system object as null.")]
|
||||
[SerializeField] private bool setEventSystem = false;
|
||||
|
||||
[Header("Events")]
|
||||
public UnityEvent onSubmit = new UnityEvent();
|
||||
|
||||
// Hidden variables
|
||||
private float cachedDuration = 0.5f;
|
||||
private string inAnim = "In";
|
||||
private string outAnim = "Out";
|
||||
private string instaInAnim = "Instant In";
|
||||
private string instaOutAnim = "Instant Out";
|
||||
private bool isActive = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
inputText.onSelect.AddListener(delegate { AnimateIn(); });
|
||||
inputText.onEndEdit.AddListener(delegate { HandleEndEdit(); });
|
||||
inputText.onValueChanged.AddListener(delegate { UpdateState(); });
|
||||
|
||||
UpdateStateInstant();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (inputText == null || inputFieldAnimator == null) { Initialize(); }
|
||||
inputText.ForceLabelUpdate();
|
||||
UpdateStateInstant();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!processSubmit || string.IsNullOrEmpty(inputText.text) || EventSystem.current.currentSelectedGameObject != inputText.gameObject)
|
||||
return;
|
||||
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
if (Input.GetKeyDown(KeyCode.Return))
|
||||
{
|
||||
onSubmit.Invoke();
|
||||
|
||||
if (clearOnSubmit)
|
||||
{
|
||||
inputText.text = "";
|
||||
UpdateState();
|
||||
}
|
||||
}
|
||||
#elif ENABLE_INPUT_SYSTEM
|
||||
if (Keyboard.current.enterKey.wasPressedThisFrame)
|
||||
{
|
||||
onSubmit.Invoke();
|
||||
|
||||
if (clearOnSubmit)
|
||||
{
|
||||
inputText.text = "";
|
||||
UpdateState();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
if (inputText == null) { inputText = gameObject.GetComponent<TMP_InputField>(); }
|
||||
if (inputFieldAnimator == null) { inputFieldAnimator = gameObject.GetComponent<Animator>(); }
|
||||
}
|
||||
|
||||
public void AnimateIn()
|
||||
{
|
||||
if (inputFieldAnimator.gameObject.activeInHierarchy && !isActive)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
|
||||
isActive = true;
|
||||
inputFieldAnimator.enabled = true;
|
||||
inputFieldAnimator.Play(inAnim);
|
||||
}
|
||||
}
|
||||
|
||||
public void AnimateOut()
|
||||
{
|
||||
if (inputFieldAnimator.gameObject.activeInHierarchy && inputText.text.Length == 0 && isActive)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
|
||||
isActive = false;
|
||||
inputFieldAnimator.enabled = true;
|
||||
inputFieldAnimator.Play(outAnim);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
if (inputText.text.Length == 0) { AnimateOut(); }
|
||||
else { AnimateIn(); }
|
||||
}
|
||||
|
||||
public void UpdateStateInstant()
|
||||
{
|
||||
inputFieldAnimator.enabled = true;
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
|
||||
if (inputText.text.Length == 0) { isActive = false; inputFieldAnimator.Play(instaOutAnim); }
|
||||
else { isActive = true; inputFieldAnimator.Play(instaInAnim); }
|
||||
}
|
||||
|
||||
void HandleEndEdit()
|
||||
{
|
||||
if (setEventSystem && string.IsNullOrEmpty(inputText.text) && !EventSystem.current.alreadySelecting && EventSystem.current.currentSelectedGameObject == inputText.gameObject)
|
||||
{
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
}
|
||||
|
||||
AnimateOut();
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(cachedDuration);
|
||||
inputFieldAnimator.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c65c7917835d8a04b94c8b906234b09e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: e956b4f7a85075c43a444a9f05cc765a, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Input Field/CustomInputField.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0d8ff45d6ce1ff479a6b3796e115826
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4f4ae5cbba538d449b15cffc97daa7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 1ee61fa8a667ceb48bedcd774003f519, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Layout Group/LayoutGroupFix.cs
|
||||
uploadId: 778406
|
||||
+168
@@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 675308088538b8340a8c91f8ac5d38e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a6728f3c9bd53624fa556ca3f560cc9b, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Layout Group/RadialLayoutGroup.cs
|
||||
uploadId: 778406
|
||||
+82
@@ -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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 079ef68e9c033fd47ad1ce2e4a5550f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Layout Group/RadialLayoutGroupEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f39f9ae0cf35ee64daac70a46d84623b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67a4caa482ba20f4a8749aba356f6fa9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 93f09189124b21e479fc891dbc1b93bf, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/ListView/ListView.cs
|
||||
uploadId: 778406
|
||||
@@ -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
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e94e561fd83d42847a5ca2c2cf082bea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/ListView/ListViewEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4851166b6d5f47478c1c34aac226415
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/ListView/ListViewItem.cs
|
||||
uploadId: 778406
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6980d488c131db45829d12b148fbb13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/ListView/ListViewRow.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c07448e7c63fe24cb0480fd57c5824e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
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(1, 4)] public string descriptionText = "Description here";
|
||||
|
||||
// Events
|
||||
public UnityEvent onOpen = new UnityEvent();
|
||||
public UnityEvent onClose = new UnityEvent();
|
||||
public UnityEvent onConfirm = new UnityEvent();
|
||||
public UnityEvent onCancel = new UnityEvent();
|
||||
|
||||
// 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 OnEnableBehaviour onEnableBehaviour = OnEnableBehaviour.None;
|
||||
|
||||
// Helpers
|
||||
float cachedStateLength;
|
||||
|
||||
public enum StartBehaviour { None, Disable, Enable }
|
||||
public enum CloseBehaviour { None, Disable, Destroy }
|
||||
public enum OnEnableBehaviour { None, Restore }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
isOn = false;
|
||||
|
||||
if (mwAnimator == null) { mwAnimator = gameObject.GetComponent<Animator>(); }
|
||||
if (closeOnCancel) { onCancel.AddListener(CloseWindow); }
|
||||
if (closeOnConfirm) { 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(); }
|
||||
|
||||
cachedStateLength = MUIPInternalTools.GetAnimatorClipLength(mwAnimator, MUIPInternalTools.modalWindowStateName);
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (onEnableBehaviour == OnEnableBehaviour.Restore && isOn)
|
||||
{
|
||||
isOn = false;
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (onEnableBehaviour == OnEnableBehaviour.None)
|
||||
{
|
||||
isOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (useCustomContent)
|
||||
return;
|
||||
|
||||
if (windowIcon != null) { windowIcon.sprite = icon; }
|
||||
if (windowTitle != null) { windowTitle.text = titleText; }
|
||||
if (windowDescription != null) { windowDescription.text = descriptionText; }
|
||||
|
||||
if (showCancelButton && cancelButton != null) { cancelButton.gameObject.SetActive(true); }
|
||||
else if (cancelButton != null) { cancelButton.gameObject.SetActive(false); }
|
||||
|
||||
if (showConfirmButton && confirmButton != null) { confirmButton.gameObject.SetActive(true); }
|
||||
else if (confirmButton != null) { confirmButton.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
if (isOn)
|
||||
return;
|
||||
|
||||
isOn = true;
|
||||
gameObject.SetActive(true);
|
||||
onOpen.Invoke();
|
||||
|
||||
StopCoroutine("DisableObject");
|
||||
mwAnimator.Play("Fade-in");
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (!isOn)
|
||||
return;
|
||||
|
||||
isOn = false;
|
||||
onClose.Invoke();
|
||||
|
||||
mwAnimator.Play("Fade-out");
|
||||
StartCoroutine("DisableObject");
|
||||
}
|
||||
|
||||
#region Obsolote
|
||||
public void OpenWindow() { Open(); }
|
||||
public void CloseWindow() { Close(); }
|
||||
#endregion
|
||||
|
||||
public void AnimateWindow()
|
||||
{
|
||||
if (!isOn)
|
||||
{
|
||||
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 WaitForSecondsRealtime(cachedStateLength);
|
||||
|
||||
if (closeBehaviour == CloseBehaviour.Disable) { gameObject.SetActive(false); }
|
||||
else if (closeBehaviour == CloseBehaviour.Destroy) { Destroy(gameObject); }
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ff5b50d8ff89864090b86d1fee33b66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 443b1643bec077e478f70a7a0fd1adcd, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Modal Window/ModalWindowManager.cs
|
||||
uploadId: 778406
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
#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 onEnableBehaviour = serializedObject.FindProperty("onEnableBehaviour");
|
||||
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.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(onEnableBehaviour, customSkin, "On Enable Behavior");
|
||||
MUIPEditorHandler.DrawProperty(startBehaviour, customSkin, "Start Behavior");
|
||||
MUIPEditorHandler.DrawProperty(closeBehaviour, customSkin, "Close Behavior");
|
||||
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(MUIPEditorHandler.UIM_SHORTCUT);
|
||||
|
||||
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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4a5d2752ec07da4aa46f6540abbd763
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Modal Window/ModalWindowManagerEditor.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0db2f43179626c4c8c191409b03c43a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class NotificationManager : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
// Content
|
||||
public Sprite icon;
|
||||
public string title = "Notification Title";
|
||||
[TextArea(1, 4)] 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;
|
||||
[SerializeField] private bool useCustomContent = false;
|
||||
public bool closeOnClick = false;
|
||||
public bool useStacking = false;
|
||||
[HideInInspector] public bool isOn;
|
||||
public StartBehaviour startBehaviour = StartBehaviour.Disable;
|
||||
public CloseBehaviour closeBehaviour = CloseBehaviour.Disable;
|
||||
public SlideDirection slideDirection = SlideDirection.Default;
|
||||
|
||||
// Events
|
||||
public UnityEvent onOpen = new UnityEvent();
|
||||
public UnityEvent onClose = new UnityEvent();
|
||||
|
||||
public enum StartBehaviour { None, Disable, Open }
|
||||
public enum CloseBehaviour { None, Disable, Destroy }
|
||||
public enum SlideDirection { Default, Left, Right }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
isOn = false;
|
||||
|
||||
if (!useCustomContent) { UpdateUI(); }
|
||||
if (notificationAnimator == null) { notificationAnimator = gameObject.GetComponent<Animator>(); }
|
||||
if (useStacking)
|
||||
{
|
||||
try { transform.GetComponentInParent<NotificationStacking>().AddToStack(this); }
|
||||
catch { Debug.LogError("<b>[Notification]</b> 'Stacking' is enabled but 'Notification Stacking' cannot be found in parent.", this); }
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (startBehaviour == StartBehaviour.Disable) { gameObject.SetActive(false); }
|
||||
else if (startBehaviour == StartBehaviour.Open) { Open(); }
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
if (isOn)
|
||||
return;
|
||||
|
||||
gameObject.SetActive(true);
|
||||
isOn = true;
|
||||
|
||||
StopCoroutine("StartTimer");
|
||||
StopCoroutine("DisableNotification");
|
||||
|
||||
notificationAnimator.Play("In");
|
||||
onOpen.Invoke();
|
||||
|
||||
if (enableTimer)
|
||||
{
|
||||
StartCoroutine("StartTimer");
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (!isOn)
|
||||
return;
|
||||
|
||||
isOn = false;
|
||||
notificationAnimator.Play("Out");
|
||||
onClose.Invoke();
|
||||
|
||||
StopCoroutine("StartTimer");
|
||||
StopCoroutine("DisableNotification");
|
||||
StartCoroutine("DisableNotification");
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
public void OpenNotification() { Open(); }
|
||||
public void CloseNotification() { Close(); }
|
||||
#endregion
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (iconObj != null) { iconObj.sprite = icon; }
|
||||
if (titleObj != null) { titleObj.text = title; }
|
||||
if (descriptionObj != null) { descriptionObj.text = description; }
|
||||
|
||||
if (slideDirection == SlideDirection.Left)
|
||||
{
|
||||
transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
|
||||
transform.GetChild(0).transform.localScale = new Vector3(-1, transform.GetChild(0).transform.localScale.y, transform.GetChild(0).transform.localScale.z);
|
||||
}
|
||||
|
||||
else if (slideDirection == SlideDirection.Right)
|
||||
{
|
||||
transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
|
||||
transform.GetChild(0).transform.localScale = new Vector3(1, transform.GetChild(0).transform.localScale.y, transform.GetChild(0).transform.localScale.z);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!closeOnClick)
|
||||
return;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
IEnumerator StartTimer()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(timer);
|
||||
Close();
|
||||
}
|
||||
|
||||
IEnumerator DisableNotification()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
|
||||
if (closeBehaviour == CloseBehaviour.Disable) { gameObject.SetActive(false); isOn = false; }
|
||||
else if (closeBehaviour == CloseBehaviour.Destroy) { Destroy(gameObject); }
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b4bbdcf873a4164eabf85f0d7820717
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: adf3c8361dd31e1448483775ea241c10, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Notification/NotificationManager.cs
|
||||
uploadId: 778406
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
#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 closeOnClick = serializedObject.FindProperty("closeOnClick");
|
||||
var useStacking = serializedObject.FindProperty("useStacking");
|
||||
var closeBehaviour = serializedObject.FindProperty("closeBehaviour");
|
||||
var startBehaviour = serializedObject.FindProperty("startBehaviour");
|
||||
var slideDirection = serializedObject.FindProperty("slideDirection");
|
||||
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.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("Set Visible", customSkin.button))
|
||||
{
|
||||
ntfTarget.GetComponent<CanvasGroup>().alpha = 1;
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Set 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");
|
||||
MUIPEditorHandler.DrawProperty(slideDirection, customSkin, "Slide Direction");
|
||||
useCustomContent.boolValue = MUIPEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content");
|
||||
closeOnClick.boolValue = MUIPEditorHandler.DrawToggle(closeOnClick.boolValue, customSkin, "Close On Click");
|
||||
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(MUIPEditorHandler.UIM_SHORTCUT);
|
||||
|
||||
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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b72fc390a6760374ba76d6ae40841bac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Notification/NotificationManagerEditor.cs
|
||||
uploadId: 778406
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[AddComponentMenu("Modern UI Pack/Notification/Notification Stacking")]
|
||||
public class NotificationStacking : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
public float delay = 1;
|
||||
|
||||
// Helpers
|
||||
List<NotificationManager> notifications = new List<NotificationManager>();
|
||||
int currentNotification = 0;
|
||||
bool enableUpdating = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (notifications.Count == 0)
|
||||
return;
|
||||
|
||||
if (enableUpdating && notifications[currentNotification] != null)
|
||||
{
|
||||
notifications[currentNotification].Open();
|
||||
|
||||
StopCoroutine("StartNotification");
|
||||
StartCoroutine("StartNotification");
|
||||
|
||||
enableUpdating = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddToStack(NotificationManager notif)
|
||||
{
|
||||
notifications.Add(notif);
|
||||
notif.gameObject.SetActive(false);
|
||||
enableUpdating = true;
|
||||
}
|
||||
|
||||
IEnumerator StartNotification()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(notifications[currentNotification].timer + delay);
|
||||
|
||||
Destroy(notifications[currentNotification].gameObject);
|
||||
|
||||
if (currentNotification == notifications.Count - 1)
|
||||
{
|
||||
notifications.Clear();
|
||||
currentNotification = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
currentNotification += 1;
|
||||
enableUpdating = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d6e5a79c713c094fb2ea4246d215d24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: adf3c8361dd31e1448483775ea241c10, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Notification/NotificationStacking.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6d490e1ba0a8d04ebc8d0cf69829e77
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b3d601986abab74cb6b3901c4bb2508
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: be8d03bb95afe0641976d654781e9e44, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.28
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Progress Bar/PBFilled.cs
|
||||
uploadId: 778406
|
||||
@@ -0,0 +1,109 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
public class ProgressBar : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public float currentPercent;
|
||||
[Range(0, 100)] public int speed;
|
||||
public float minValue = 0;
|
||||
public float maxValue = 100;
|
||||
public float valueLimit = 100;
|
||||
|
||||
// Resources
|
||||
public Image loadingBar;
|
||||
public TextMeshProUGUI textPercent;
|
||||
|
||||
// Settings
|
||||
public bool isOn;
|
||||
public bool restart;
|
||||
public bool invert;
|
||||
public bool addPrefix;
|
||||
public bool addSuffix = true;
|
||||
public string prefix = "";
|
||||
public string suffix = "%";
|
||||
public bool isLooped = false;
|
||||
[Range(0, 5)] public int decimals = 0;
|
||||
|
||||
// Events
|
||||
[System.Serializable]
|
||||
public class ProgressBarEvent : UnityEvent<float> { }
|
||||
public ProgressBarEvent onValueChanged;
|
||||
[HideInInspector] public Slider eventSource;
|
||||
|
||||
void Start()
|
||||
{
|
||||
UpdateUI();
|
||||
InitializeEvents();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isOn)
|
||||
return;
|
||||
|
||||
if (currentPercent <= maxValue && !invert) { currentPercent += speed * Time.unscaledDeltaTime; }
|
||||
else if (currentPercent >= minValue && invert) { currentPercent -= speed * Time.unscaledDeltaTime; }
|
||||
|
||||
if (currentPercent >= maxValue && speed != 0 && restart && !invert) { currentPercent = 0; }
|
||||
else if (currentPercent <= minValue && speed != 0 && restart && invert) { currentPercent = maxValue; }
|
||||
else if (currentPercent >= maxValue && speed != 0 && !restart && !invert) { currentPercent = maxValue; }
|
||||
else if (currentPercent <= minValue && speed != 0 && !restart && invert) { currentPercent = minValue; }
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
loadingBar.fillAmount = currentPercent / maxValue;
|
||||
|
||||
if (addSuffix) { textPercent.text = currentPercent.ToString("F" + decimals) + suffix; }
|
||||
else { textPercent.text = currentPercent.ToString("F" + decimals); }
|
||||
|
||||
if (addPrefix) { textPercent.text = prefix + textPercent.text; }
|
||||
if (eventSource != null) { eventSource.value = currentPercent; }
|
||||
}
|
||||
|
||||
public void InitializeEvents()
|
||||
{
|
||||
if (Application.isPlaying && onValueChanged.GetPersistentEventCount() != 0)
|
||||
{
|
||||
if (eventSource == null) { eventSource = gameObject.AddComponent(typeof(Slider)) as Slider; }
|
||||
eventSource.transition = Selectable.Transition.None;
|
||||
eventSource.minValue = minValue;
|
||||
eventSource.maxValue = maxValue;
|
||||
eventSource.onValueChanged.AddListener(onValueChanged.Invoke);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearEvents()
|
||||
{
|
||||
eventSource.onValueChanged.RemoveAllListeners();
|
||||
}
|
||||
|
||||
// Will be replaced in future versions
|
||||
public void ChangeValue(float newValue)
|
||||
{
|
||||
currentPercent = newValue;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void SetValue(float newValue)
|
||||
{
|
||||
currentPercent = newValue;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void SetValue(float newValue, string newPrefix = null, string newSuffix = null, bool updateUI = true)
|
||||
{
|
||||
currentPercent = newValue;
|
||||
prefix = newPrefix;
|
||||
suffix = newSuffix;
|
||||
if (updateUI) { UpdateUI(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user