基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
380
Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdown.cs
Normal file
380
Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdown.cs
Normal file
@@ -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.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdown.cs
|
||||
uploadId: 628721
|
||||
321
Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdownEditor.cs
Normal file
321
Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdownEditor.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[CustomEditor(typeof(CustomDropdown))]
|
||||
public class CustomDropdownEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private CustomDropdown dTarget;
|
||||
private UIManagerDropdown tempUIM;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
dTarget = (CustomDropdown)target;
|
||||
|
||||
try { tempUIM = dTarget.GetComponent<UIManagerDropdown>(); }
|
||||
catch { }
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
|
||||
|
||||
if (dTarget.selectedItemIndex > dTarget.items.Count - 1) { dTarget.selectedItemIndex = 0; }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
MUIPEditorHandler.DrawComponentHeader(customSkin, "Dropdown Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = MUIPEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var items = serializedObject.FindProperty("items");
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
var onItemTextChanged = serializedObject.FindProperty("onItemTextChanged");
|
||||
|
||||
var triggerObject = serializedObject.FindProperty("triggerObject");
|
||||
var selectedText = serializedObject.FindProperty("selectedText");
|
||||
var selectedImage = serializedObject.FindProperty("selectedImage");
|
||||
var itemParent = serializedObject.FindProperty("itemParent");
|
||||
var itemObject = serializedObject.FindProperty("itemObject");
|
||||
var scrollbar = serializedObject.FindProperty("scrollbar");
|
||||
var listParent = serializedObject.FindProperty("listParent");
|
||||
var listRect = serializedObject.FindProperty("listRect");
|
||||
var listCG = serializedObject.FindProperty("listCG");
|
||||
|
||||
var animationType = serializedObject.FindProperty("animationType");
|
||||
var panelDirection = serializedObject.FindProperty("panelDirection");
|
||||
var panelSize = serializedObject.FindProperty("panelSize");
|
||||
var curveSpeed = serializedObject.FindProperty("curveSpeed");
|
||||
var animationCurve = serializedObject.FindProperty("animationCurve");
|
||||
|
||||
var saveSelected = serializedObject.FindProperty("saveSelected");
|
||||
var saveKey = serializedObject.FindProperty("saveKey");
|
||||
var enableIcon = serializedObject.FindProperty("enableIcon");
|
||||
var enableTrigger = serializedObject.FindProperty("enableTrigger");
|
||||
var enableScrollbar = serializedObject.FindProperty("enableScrollbar");
|
||||
var outOnPointerExit = serializedObject.FindProperty("outOnPointerExit");
|
||||
var setHighPriority = serializedObject.FindProperty("setHighPriority");
|
||||
var invokeAtStart = serializedObject.FindProperty("invokeAtStart");
|
||||
var initAtStart = serializedObject.FindProperty("initAtStart");
|
||||
var selectedItemIndex = serializedObject.FindProperty("selectedItemIndex");
|
||||
var enableDropdownSounds = serializedObject.FindProperty("enableDropdownSounds");
|
||||
var useHoverSound = serializedObject.FindProperty("useHoverSound");
|
||||
var useClickSound = serializedObject.FindProperty("useClickSound");
|
||||
var hoverSound = serializedObject.FindProperty("hoverSound");
|
||||
var clickSound = serializedObject.FindProperty("clickSound");
|
||||
var soundSource = serializedObject.FindProperty("soundSource");
|
||||
var itemSpacing = serializedObject.FindProperty("itemSpacing");
|
||||
var itemPaddingLeft = serializedObject.FindProperty("itemPaddingLeft");
|
||||
var itemPaddingRight = serializedObject.FindProperty("itemPaddingRight");
|
||||
var itemPaddingTop = serializedObject.FindProperty("itemPaddingTop");
|
||||
var itemPaddingBottom = serializedObject.FindProperty("itemPaddingBottom");
|
||||
var extendEvents = serializedObject.FindProperty("extendEvents");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (Application.isPlaying == false && dTarget.items.Count != 0)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.LabelField(new GUIContent("Selected Item:"), customSkin.FindStyle("Text"), GUILayout.Width(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("Tools/Modern UI Pack/Show UI Manager");
|
||||
|
||||
if (GUILayout.Button("Disable UI Manager Connection", customSkin.button))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Modern UI Pack", "Are you sure you want to disable UI Manager connection with the object? " +
|
||||
"This operation cannot be undone.", "Yes", "Cancel"))
|
||||
{
|
||||
try { DestroyImmediate(tempUIM); }
|
||||
catch { Debug.LogError("<b>[Dropdown]</b> Failed to delete UI Manager connection.", this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Application.isPlaying == false) { this.Repaint(); }
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -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.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/CustomDropdownEditor.cs
|
||||
uploadId: 628721
|
||||
321
Assets/Modern UI Pack/Scripts/Dropdown/DropdownMultiSelect.cs
Normal file
321
Assets/Modern UI Pack/Scripts/Dropdown/DropdownMultiSelect.cs
Normal file
@@ -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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/DropdownMultiSelect.cs
|
||||
uploadId: 628721
|
||||
@@ -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("Tools/Modern UI Pack/Show UI Manager");
|
||||
|
||||
if (GUILayout.Button("Disable UI Manager Connection", customSkin.button))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Modern UI Pack", "Are you sure you want to disable UI Manager connection with the object? " +
|
||||
"This operation cannot be undone.", "Yes", "Cancel"))
|
||||
{
|
||||
try { DestroyImmediate(tempUIM); }
|
||||
catch { Debug.LogError("<b>[Dropdown]</b> Failed to delete UI Manager connection.", this); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Application.isPlaying == false) { this.Repaint(); }
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -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.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Dropdown/DropdownMultiSelectEditor.cs
|
||||
uploadId: 628721
|
||||
Reference in New Issue
Block a user