parent
744c52b370
commit
9168b4e67e
|
@ -23,6 +23,11 @@ Control | Description | Menu Command | Component Command | Notes | Credits
|
||||||
**HorizontalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | UI / Extensions / Horizontal Scroll Snap | UI / Extensions / Horizontal Scroll Snap | | BinaryX
|
**HorizontalScrollSnap** | A pages scroll rect that can work in steps / pages, includes button support | UI / Extensions / Horizontal Scroll Snap | UI / Extensions / Horizontal Scroll Snap | | BinaryX
|
||||||
**UIButton** | Improved Button control with additional events | UI / Extensions / UI Button | UI / Extensions / UI Button | | AriathTheWise
|
**UIButton** | Improved Button control with additional events | UI / Extensions / UI Button | UI / Extensions / UI Button | | AriathTheWise
|
||||||
**UIWindowBase** | A draggable Window implementation | UI / Extensions / UI Window Base | UI / Extensions / UI Window Base | | GXMark, alexzzzz, CaoMengde777, TroyDavis
|
**UIWindowBase** | A draggable Window implementation | UI / Extensions / UI Window Base | UI / Extensions / UI Window Base | | GXMark, alexzzzz, CaoMengde777, TroyDavis
|
||||||
|
**ComboBox** | A fixed combobox implementation for text | UI / Extensions / ComboBox | UI / Extensions / ComboBox | | Perchik
|
||||||
|
**AutoCompleteComboBox** | A text combobox with autocomplete selection | UI / Extensions / AutoComplete ComboBox | UI / Extensions / AutoComplete ComboBox | | Perchik
|
||||||
|
**DropDownList** | A basic drop down list with text and image support | UI / Extensions / Dropdown List | UI / Extensions / Dropdown List | | Perchik
|
||||||
|
**BoundToolTip** | An alternate Tooltip implementation with central listener | UI / Extensions / Bound Tooltip / Tooltip | UI / Extensions / Bound Tooltip / Tooltip Item | Offset and tooltip placement needs work | Martin Sharkbomb
|
||||||
|
| | | UI / Extensions / Bound Tooltip / Tooltip Trigger | | Martin Sharkbomb
|
||||||
|
|
||||||
## Effect components ##
|
## Effect components ##
|
||||||
=====================
|
=====================
|
||||||
|
@ -46,6 +51,7 @@ Component | Description | Component Command | Notes | Credits
|
||||||
**ReturnKeyTrigger** | Does something?? | UI / Extensions / ReturnKey Trigger | | Melang, ddreaper
|
**ReturnKeyTrigger** | Does something?? | UI / Extensions / ReturnKey Trigger | | Melang, ddreaper
|
||||||
**TabNavigation** | An example Tab navigation script | UI / Extensions / Tab Navigation | | Melang, omatase
|
**TabNavigation** | An example Tab navigation script | UI / Extensions / Tab Navigation | | Melang, omatase
|
||||||
**uGUITools** | | Menu / uGUI | | Senshi
|
**uGUITools** | | Menu / uGUI | | Senshi
|
||||||
|
**FlowLayoutGroup** | A more rugged grid style layout group | Layout / Extensions / Flow Layout Group | [Example Video](https://www.youtube.com/watch?v=tMe_3tJTZvc) | Simie
|
||||||
|
|
||||||
|
|
||||||
*More to come*
|
*More to come*
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dcabbd73a79cd8c4a966e44d7f276790
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,56 @@
|
||||||
|
///Credit Martin Sharkbomb
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/tooltips.264395/#post-1957075
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.Extensions
|
||||||
|
{
|
||||||
|
[AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Item")]
|
||||||
|
public class BoundTooltipItem : MonoBehaviour
|
||||||
|
{
|
||||||
|
public bool IsActive
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return gameObject.activeSelf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnityEngine.UI.Text TooltipText;
|
||||||
|
public Vector3 ToolTipOffset;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
if(!TooltipText) TooltipText = GetComponentInChildren<Text>();
|
||||||
|
HideTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowTooltip(string text, Vector3 pos)
|
||||||
|
{
|
||||||
|
if (TooltipText.text != text)
|
||||||
|
TooltipText.text = text;
|
||||||
|
|
||||||
|
transform.position = pos + ToolTipOffset;
|
||||||
|
|
||||||
|
gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HideTooltip()
|
||||||
|
{
|
||||||
|
gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Standard Singleton Access
|
||||||
|
private static BoundTooltipItem instance;
|
||||||
|
public static BoundTooltipItem Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
instance = GameObject.FindObjectOfType<BoundTooltipItem>();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2d6f5ec6d595a31459e6942110d86aaa
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,39 @@
|
||||||
|
///Credit Martin Sharkbomb
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/tooltips.264395/#post-1957075
|
||||||
|
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.Extensions
|
||||||
|
{
|
||||||
|
[AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Trigger")]
|
||||||
|
public class BoundTooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler
|
||||||
|
{
|
||||||
|
public string text;
|
||||||
|
|
||||||
|
public void OnPointerEnter(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
StartHover(new Vector3(eventData.position.x, eventData.position.y, 0f));
|
||||||
|
}
|
||||||
|
public void OnSelect(BaseEventData eventData)
|
||||||
|
{
|
||||||
|
StartHover(transform.position);
|
||||||
|
}
|
||||||
|
public void OnPointerExit(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
StopHover();
|
||||||
|
}
|
||||||
|
public void OnDeselect(BaseEventData eventData)
|
||||||
|
{
|
||||||
|
StopHover();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartHover(Vector3 position)
|
||||||
|
{
|
||||||
|
BoundTooltipItem.Instance.ShowTooltip(text, position);
|
||||||
|
}
|
||||||
|
void StopHover()
|
||||||
|
{
|
||||||
|
BoundTooltipItem.Instance.HideTooltip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d4d7c934af453a9469701b72267593ec
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,344 @@
|
||||||
|
///Credit perchik
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.Extensions
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(RectTransform))]
|
||||||
|
[AddComponentMenu("UI/Extensions/AutoComplete ComboBox")]
|
||||||
|
public class AutoCompleteComboBox : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Color disabledTextColor;
|
||||||
|
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
|
||||||
|
|
||||||
|
public List<string> AvailableOptions;
|
||||||
|
|
||||||
|
public System.Action<int> OnSelectionChanged; // fires when selection is changed;
|
||||||
|
|
||||||
|
//private bool isInitialized = false;
|
||||||
|
private bool _isPanelActive = false;
|
||||||
|
private bool _hasDrawnOnce = false;
|
||||||
|
|
||||||
|
private InputField _mainInput;
|
||||||
|
private RectTransform _inputRT;
|
||||||
|
|
||||||
|
|
||||||
|
private RectTransform _rectTransform;
|
||||||
|
|
||||||
|
private RectTransform _overlayRT;
|
||||||
|
private RectTransform _scrollPanelRT;
|
||||||
|
private RectTransform _scrollBarRT;
|
||||||
|
private RectTransform _slidingAreaRT;
|
||||||
|
// private RectTransform scrollHandleRT;
|
||||||
|
private RectTransform _itemsPanelRT;
|
||||||
|
private Canvas _canvas;
|
||||||
|
private RectTransform _canvasRT;
|
||||||
|
|
||||||
|
private ScrollRect _scrollRect;
|
||||||
|
|
||||||
|
private List<string> _panelItems; //items that will get shown in the dropdown
|
||||||
|
private List<string> _prunedPanelItems; //items that used to show in the dropdown
|
||||||
|
|
||||||
|
private Dictionary<string, GameObject> panelObjects;
|
||||||
|
|
||||||
|
private GameObject itemTemplate;
|
||||||
|
|
||||||
|
public string Text { get; private set; }
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private float _scrollBarWidth = 20.0f;
|
||||||
|
public float ScrollBarWidth
|
||||||
|
{
|
||||||
|
get { return _scrollBarWidth; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_scrollBarWidth = value;
|
||||||
|
RedrawPanel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// private int scrollOffset; //offset of the selected item
|
||||||
|
private int _selectedIndex = 0;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private int _itemsToDisplay;
|
||||||
|
public int ItemsToDisplay
|
||||||
|
{
|
||||||
|
get { return _itemsToDisplay; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_itemsToDisplay = value;
|
||||||
|
RedrawPanel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Awake()
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Initialize()
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_rectTransform = GetComponent<RectTransform>();
|
||||||
|
_inputRT = _rectTransform.FindChild("InputField").GetComponent<RectTransform>();
|
||||||
|
_mainInput = _inputRT.GetComponent<InputField>();
|
||||||
|
|
||||||
|
_overlayRT = _rectTransform.FindChild("Overlay").GetComponent<RectTransform>();
|
||||||
|
_overlayRT.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
|
||||||
|
_scrollPanelRT = _overlayRT.FindChild("ScrollPanel").GetComponent<RectTransform>();
|
||||||
|
_scrollBarRT = _scrollPanelRT.FindChild("Scrollbar").GetComponent<RectTransform>();
|
||||||
|
_slidingAreaRT = _scrollBarRT.FindChild("SlidingArea").GetComponent<RectTransform>();
|
||||||
|
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
|
||||||
|
_itemsPanelRT = _scrollPanelRT.FindChild("Items").GetComponent<RectTransform>();
|
||||||
|
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
|
||||||
|
|
||||||
|
_canvas = GetComponentInParent<Canvas>();
|
||||||
|
_canvasRT = _canvas.GetComponent<RectTransform>();
|
||||||
|
|
||||||
|
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
|
||||||
|
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
|
||||||
|
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
|
||||||
|
_scrollRect.content = _itemsPanelRT;
|
||||||
|
|
||||||
|
itemTemplate = _rectTransform.FindChild("ItemTemplate").gameObject;
|
||||||
|
itemTemplate.SetActive(false);
|
||||||
|
}
|
||||||
|
catch (System.NullReferenceException ex)
|
||||||
|
{
|
||||||
|
Debug.LogException(ex);
|
||||||
|
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Refernece Exception");
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
panelObjects = new Dictionary<string, GameObject>();
|
||||||
|
|
||||||
|
_prunedPanelItems = new List<string>();
|
||||||
|
_panelItems = AvailableOptions.ToList();
|
||||||
|
|
||||||
|
RebuildPanel();
|
||||||
|
RedrawPanel();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* currently just using items in the list instead of being able to add to it.
|
||||||
|
public void AddItems(params object[] list)
|
||||||
|
{
|
||||||
|
List<DropDownListItem> ddItems = new List<DropDownListItem>();
|
||||||
|
foreach (var obj in list)
|
||||||
|
{
|
||||||
|
if (obj is DropDownListItem)
|
||||||
|
{
|
||||||
|
ddItems.Add((DropDownListItem)obj);
|
||||||
|
}
|
||||||
|
else if (obj is string)
|
||||||
|
{
|
||||||
|
ddItems.Add(new DropDownListItem(caption: (string)obj));
|
||||||
|
}
|
||||||
|
else if (obj is Sprite)
|
||||||
|
{
|
||||||
|
ddItems.Add(new DropDownListItem(image: (Sprite)obj));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Items.AddRange(ddItems);
|
||||||
|
Items = Items.Distinct().ToList();//remove any duplicates
|
||||||
|
RebuildPanel();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rebuilds the contents of the panel in response to items being added.
|
||||||
|
/// </summary>
|
||||||
|
private void RebuildPanel()
|
||||||
|
{
|
||||||
|
//panel starts with all options
|
||||||
|
_panelItems.Clear();
|
||||||
|
foreach (string option in AvailableOptions)
|
||||||
|
{
|
||||||
|
_panelItems.Add(option.ToLower());
|
||||||
|
}
|
||||||
|
_panelItems.Sort();
|
||||||
|
|
||||||
|
_prunedPanelItems.Clear();
|
||||||
|
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
|
||||||
|
panelObjects.Clear();
|
||||||
|
|
||||||
|
int indx = 0;
|
||||||
|
while (itemObjs.Count < AvailableOptions.Count)
|
||||||
|
{
|
||||||
|
GameObject newItem = Instantiate(itemTemplate) as GameObject;
|
||||||
|
newItem.name = "Item " + indx;
|
||||||
|
newItem.transform.SetParent(_itemsPanelRT, false);
|
||||||
|
itemObjs.Add(newItem);
|
||||||
|
indx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < itemObjs.Count; i++)
|
||||||
|
{
|
||||||
|
itemObjs[i].SetActive(i <= AvailableOptions.Count);
|
||||||
|
if (i < AvailableOptions.Count)
|
||||||
|
{
|
||||||
|
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
|
||||||
|
itemObjs[i].transform.FindChild("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value
|
||||||
|
|
||||||
|
Button itemBtn = itemObjs[i].GetComponent<Button>();
|
||||||
|
itemBtn.onClick.RemoveAllListeners();
|
||||||
|
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
|
||||||
|
itemBtn.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
OnItemClicked(textOfItem);
|
||||||
|
});
|
||||||
|
panelObjects[_panelItems[i]] = itemObjs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// what happens when an item in the list is selected
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
private void OnItemClicked(string item)
|
||||||
|
{
|
||||||
|
//Debug.Log("item " + item + " clicked");
|
||||||
|
Text = item;
|
||||||
|
_mainInput.text = Text;
|
||||||
|
ToggleDropdownPanel(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//private void UpdateSelected()
|
||||||
|
//{
|
||||||
|
// SelectedItem = (_selectedIndex > -1 && _selectedIndex < Items.Count) ? Items[_selectedIndex] : null;
|
||||||
|
// if (SelectedItem == null) return;
|
||||||
|
|
||||||
|
// bool hasImage = SelectedItem.Image != null;
|
||||||
|
// if (hasImage)
|
||||||
|
// {
|
||||||
|
// mainButton.img.sprite = SelectedItem.Image;
|
||||||
|
// mainButton.img.color = Color.white;
|
||||||
|
|
||||||
|
// //if (Interactable) mainButton.img.color = Color.white;
|
||||||
|
// //else mainButton.img.color = new Color(1, 1, 1, .5f);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// mainButton.img.sprite = null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// mainButton.txt.text = SelectedItem.Caption;
|
||||||
|
|
||||||
|
// //update selected index color
|
||||||
|
// for (int i = 0; i < itemsPanelRT.childCount; i++)
|
||||||
|
// {
|
||||||
|
// panelItems[i].btnImg.color = (_selectedIndex == i) ? mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
private void RedrawPanel()
|
||||||
|
{
|
||||||
|
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
|
||||||
|
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
|
||||||
|
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
|
||||||
|
{
|
||||||
|
_hasDrawnOnce = true;
|
||||||
|
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
||||||
|
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
|
||||||
|
|
||||||
|
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
|
||||||
|
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
|
||||||
|
|
||||||
|
//make the overlay fill the screen
|
||||||
|
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
|
||||||
|
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
|
||||||
|
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
|
||||||
|
|
||||||
|
_overlayRT.SetParent(transform, true);//reattach to this object
|
||||||
|
_scrollPanelRT.SetParent(_overlayRT, true); //reattach the scrollpanel to the overlay
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_panelItems.Count < 1) return;
|
||||||
|
|
||||||
|
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count);
|
||||||
|
|
||||||
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
||||||
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
||||||
|
|
||||||
|
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
|
||||||
|
_itemsPanelRT.anchoredPosition = new Vector2(5, 0);
|
||||||
|
|
||||||
|
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
|
||||||
|
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
||||||
|
|
||||||
|
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
|
||||||
|
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnValueChanged(string currText)
|
||||||
|
{
|
||||||
|
Text = currText;
|
||||||
|
PruneItems(currText);
|
||||||
|
RedrawPanel();
|
||||||
|
//Debug.Log("value changed to: " + currText);
|
||||||
|
|
||||||
|
if (_panelItems.Count == 0)
|
||||||
|
{
|
||||||
|
_isPanelActive = true;//this makes it get turned off
|
||||||
|
ToggleDropdownPanel(false);
|
||||||
|
}
|
||||||
|
else if (!_isPanelActive)
|
||||||
|
{
|
||||||
|
ToggleDropdownPanel(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggle the drop down list
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directClick"> whether an item was directly clicked on</param>
|
||||||
|
public void ToggleDropdownPanel(bool directClick)
|
||||||
|
{
|
||||||
|
_isPanelActive = !_isPanelActive;
|
||||||
|
|
||||||
|
_overlayRT.gameObject.SetActive(_isPanelActive);
|
||||||
|
if (_isPanelActive)
|
||||||
|
{
|
||||||
|
transform.SetAsLastSibling();
|
||||||
|
}
|
||||||
|
else if (directClick)
|
||||||
|
{
|
||||||
|
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PruneItems(string currText)
|
||||||
|
{
|
||||||
|
List<string> notToPrune = _panelItems.Where(x => x.ToLower().Contains(currText.ToLower())).ToList();
|
||||||
|
List<string> toPrune = _panelItems.Except(notToPrune).ToList();
|
||||||
|
foreach (string key in toPrune)
|
||||||
|
{
|
||||||
|
// Debug.Log("pruning key " + key);
|
||||||
|
panelObjects[key].SetActive(false);
|
||||||
|
_panelItems.Remove(key);
|
||||||
|
_prunedPanelItems.Add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> toAddBack = _prunedPanelItems.Where(x => x.ToLower().Contains(currText)).ToList();
|
||||||
|
foreach (string key in toAddBack)
|
||||||
|
{
|
||||||
|
// Debug.Log("adding back key " + key);
|
||||||
|
panelObjects[key].SetActive(true);
|
||||||
|
_panelItems.Add(key);
|
||||||
|
_prunedPanelItems.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ef22b091ebae52c47aa3e86ad9040c05
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -39,7 +39,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
private ScrollRect _scrollRect;
|
private ScrollRect _scrollRect;
|
||||||
|
|
||||||
private List<string> _panelItems; //items that will get shown in the dropdown
|
private List<string> _panelItems; //items that will get shown in the dropdown
|
||||||
private List<string> _prunedPanelItems; //items that used to show in the dropdown
|
|
||||||
|
|
||||||
private Dictionary<string, GameObject> panelObjects;
|
private Dictionary<string, GameObject> panelObjects;
|
||||||
|
|
||||||
|
@ -118,7 +117,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
panelObjects = new Dictionary<string, GameObject>();
|
panelObjects = new Dictionary<string, GameObject>();
|
||||||
|
|
||||||
_prunedPanelItems = new List<string>();
|
|
||||||
_panelItems = AvailableOptions.ToList();
|
_panelItems = AvailableOptions.ToList();
|
||||||
|
|
||||||
RebuildPanel();
|
RebuildPanel();
|
||||||
|
@ -168,7 +166,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
_panelItems.Sort();
|
_panelItems.Sort();
|
||||||
|
|
||||||
_prunedPanelItems.Clear();
|
|
||||||
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
|
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
|
||||||
panelObjects.Clear();
|
panelObjects.Clear();
|
||||||
|
|
||||||
|
@ -285,7 +282,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
public void OnValueChanged(string currText)
|
public void OnValueChanged(string currText)
|
||||||
{
|
{
|
||||||
Text = currText;
|
Text = currText;
|
||||||
PruneItems(currText);
|
|
||||||
RedrawPanel();
|
RedrawPanel();
|
||||||
//Debug.Log("value changed to: " + currText);
|
//Debug.Log("value changed to: " + currText);
|
||||||
|
|
||||||
|
@ -318,27 +314,5 @@ namespace UnityEngine.UI.Extensions
|
||||||
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
|
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PruneItems(string currText)
|
|
||||||
{
|
|
||||||
List<string> notToPrune = _panelItems.Where(x => x.ToLower().Contains(currText.ToLower())).ToList();
|
|
||||||
List<string> toPrune = _panelItems.Except(notToPrune).ToList();
|
|
||||||
foreach (string key in toPrune)
|
|
||||||
{
|
|
||||||
// Debug.Log("pruning key " + key);
|
|
||||||
panelObjects[key].SetActive(false);
|
|
||||||
_panelItems.Remove(key);
|
|
||||||
_prunedPanelItems.Add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> toAddBack = _prunedPanelItems.Where(x => x.ToLower().Contains(currText)).ToList();
|
|
||||||
foreach (string key in toAddBack)
|
|
||||||
{
|
|
||||||
// Debug.Log("adding back key " + key);
|
|
||||||
panelObjects[key].SetActive(true);
|
|
||||||
_panelItems.Add(key);
|
|
||||||
_prunedPanelItems.Remove(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1,4 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e2a3ef238d1087247ac988b1c9552363
|
|
||||||
NativeFormatImporter:
|
|
||||||
userData:
|
|
|
@ -213,14 +213,11 @@ namespace UnityEditor.UI
|
||||||
{
|
{
|
||||||
GameObject horizontalScrollSnapRoot = CreateUIElementRoot("Horizontal Scroll Snap", menuCommand, s_ThickGUIElementSize);
|
GameObject horizontalScrollSnapRoot = CreateUIElementRoot("Horizontal Scroll Snap", menuCommand, s_ThickGUIElementSize);
|
||||||
|
|
||||||
GameObject childContent = new GameObject("Content");
|
GameObject childContent = CreateUIObject("Content", horizontalScrollSnapRoot);
|
||||||
GameObjectUtility.SetParentAndAlign(childContent, horizontalScrollSnapRoot);
|
|
||||||
|
|
||||||
GameObject childPage01 = new GameObject("Page_01");
|
GameObject childPage01 = CreateUIObject("Page_01", childContent);
|
||||||
GameObjectUtility.SetParentAndAlign(childPage01, childContent);
|
|
||||||
|
|
||||||
GameObject childText = new GameObject("Text");
|
GameObject childText = CreateUIObject("Text", childPage01);
|
||||||
GameObjectUtility.SetParentAndAlign(childText, childPage01);
|
|
||||||
|
|
||||||
// Set RectTransform to stretch
|
// Set RectTransform to stretch
|
||||||
RectTransform rectTransformScrollSnapRoot = horizontalScrollSnapRoot.GetComponent<RectTransform>();
|
RectTransform rectTransformScrollSnapRoot = horizontalScrollSnapRoot.GetComponent<RectTransform>();
|
||||||
|
@ -285,8 +282,7 @@ namespace UnityEditor.UI
|
||||||
static public void AddUIButton(MenuCommand menuCommand)
|
static public void AddUIButton(MenuCommand menuCommand)
|
||||||
{
|
{
|
||||||
GameObject uiButtonRoot = CreateUIElementRoot("UI Button", menuCommand, s_ThickGUIElementSize);
|
GameObject uiButtonRoot = CreateUIElementRoot("UI Button", menuCommand, s_ThickGUIElementSize);
|
||||||
GameObject childText = new GameObject("Text");
|
GameObject childText = CreateUIObject("Text", uiButtonRoot);
|
||||||
GameObjectUtility.SetParentAndAlign(childText, uiButtonRoot);
|
|
||||||
|
|
||||||
Image image = uiButtonRoot.AddComponent<Image>();
|
Image image = uiButtonRoot.AddComponent<Image>();
|
||||||
image.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
|
image.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
|
||||||
|
@ -348,6 +344,102 @@ namespace UnityEditor.UI
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MenuItem("GameObject/UI/Extensions/AutoComplete ComboBox", false)]
|
||||||
|
static public void AddAutoCompleteComboBox(MenuCommand menuCommand)
|
||||||
|
{
|
||||||
|
GameObject autoCompleteComboBoxRoot = CreateUIElementRoot("AutoCompleteComboBox", menuCommand, s_ThickGUIElementSize);
|
||||||
|
|
||||||
|
//Create Template
|
||||||
|
GameObject itemTemplate = AddButtonAsChild(autoCompleteComboBoxRoot);
|
||||||
|
|
||||||
|
//Create Inputfield
|
||||||
|
GameObject inputField = AddInputFieldAsChild(autoCompleteComboBoxRoot);
|
||||||
|
|
||||||
|
//Create Overlay
|
||||||
|
GameObject overlay = CreateUIObject("Overlay", autoCompleteComboBoxRoot);
|
||||||
|
GameObject overlayScrollPanel = CreateUIObject("ScrollPanel", overlay);
|
||||||
|
GameObject overlayScrollPanelItems = CreateUIObject("Items", overlayScrollPanel);
|
||||||
|
GameObject overlayScrollPanelScrollBar = AddScrollbarAsChild(overlayScrollPanel);
|
||||||
|
|
||||||
|
//Create Arrow Button
|
||||||
|
GameObject arrowButton = AddButtonAsChild(autoCompleteComboBoxRoot);
|
||||||
|
|
||||||
|
//Setup ComboBox
|
||||||
|
var autoCompleteComboBox = autoCompleteComboBoxRoot.AddComponent<AutoCompleteComboBox>();
|
||||||
|
var cbbRT = autoCompleteComboBoxRoot.GetComponent<RectTransform>();
|
||||||
|
|
||||||
|
//Setup Template
|
||||||
|
itemTemplate.name = "ItemTemplate";
|
||||||
|
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
|
||||||
|
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
|
||||||
|
var itemTemplateButton = itemTemplate.GetComponent<Button>();
|
||||||
|
itemTemplateButton.transition = Selectable.Transition.None;
|
||||||
|
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
|
||||||
|
itemTemplateLayoutElement.minHeight = cbbRT.rect.height;
|
||||||
|
itemTemplate.SetActive(false);
|
||||||
|
|
||||||
|
//Setup InputField
|
||||||
|
var inputFieldRT = inputField.GetComponent<RectTransform>();
|
||||||
|
inputFieldRT.anchorMin = Vector2.zero;
|
||||||
|
inputFieldRT.anchorMax = Vector2.one;
|
||||||
|
inputFieldRT.sizeDelta = Vector2.zero;
|
||||||
|
Events.UnityEventTools.AddPersistentListener<string>(inputField.GetComponent<InputField>().onValueChange, new UnityEngine.Events.UnityAction<string>(autoCompleteComboBox.OnValueChanged));
|
||||||
|
|
||||||
|
//Setup Overlay
|
||||||
|
var overlayRT = overlay.GetComponent<RectTransform>();
|
||||||
|
overlayRT.anchorMin = new Vector2(0f, 1f);
|
||||||
|
overlayRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
overlayRT.sizeDelta = new Vector2(0f, 1f);
|
||||||
|
overlayRT.pivot = new Vector2(0f, 1f);
|
||||||
|
overlay.AddComponent<Image>().color = new Color(0.243f, 0.871f, 0f, 0f);
|
||||||
|
Events.UnityEventTools.AddBoolPersistentListener(overlay.AddComponent<Button>().onClick, new UnityEngine.Events.UnityAction<bool>(autoCompleteComboBox.ToggleDropdownPanel), true);
|
||||||
|
//Overlay Scroll Panel
|
||||||
|
var overlayScrollPanelRT = overlayScrollPanel.GetComponent<RectTransform>();
|
||||||
|
overlayScrollPanelRT.position += new Vector3(0, -cbbRT.sizeDelta.y, 0);
|
||||||
|
overlayScrollPanelRT.anchorMin = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelRT.sizeDelta = new Vector2(cbbRT.sizeDelta.x, cbbRT.sizeDelta.y * 3);
|
||||||
|
overlayScrollPanelRT.pivot = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanel.AddComponent<Image>();
|
||||||
|
overlayScrollPanel.AddComponent<Mask>();
|
||||||
|
var scrollRect = overlayScrollPanel.AddComponent<ScrollRect>();
|
||||||
|
scrollRect.horizontal = false;
|
||||||
|
scrollRect.movementType = ScrollRect.MovementType.Clamped;
|
||||||
|
scrollRect.verticalScrollbar = overlayScrollPanelScrollBar.GetComponent<Scrollbar>();
|
||||||
|
//Overlay Items list
|
||||||
|
var overlayScrollPanelItemsRT = overlayScrollPanelItems.GetComponent<RectTransform>();
|
||||||
|
overlayScrollPanelItemsRT.position += new Vector3(5, 0, 0);
|
||||||
|
overlayScrollPanelItemsRT.anchorMin = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelItemsRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelItemsRT.sizeDelta = new Vector2(120f, 5f);
|
||||||
|
overlayScrollPanelItemsRT.pivot = new Vector2(0f, 1f);
|
||||||
|
scrollRect.content = overlayScrollPanelItemsRT;
|
||||||
|
var overlayScrollPanelItemsVLG = overlayScrollPanelItems.AddComponent<VerticalLayoutGroup>();
|
||||||
|
overlayScrollPanelItemsVLG.padding = new RectOffset(0, 0, 5, 0);
|
||||||
|
var overlayScrollPanelItemsFitter = overlayScrollPanelItems.AddComponent<ContentSizeFitter>();
|
||||||
|
overlayScrollPanelItemsFitter.verticalFit = ContentSizeFitter.FitMode.MinSize;
|
||||||
|
//Overlay Scrollbar
|
||||||
|
var overlayScrollPanelScrollbarRT = overlayScrollPanelScrollBar.GetComponent<RectTransform>();
|
||||||
|
overlayScrollPanelScrollbarRT.anchorMin = new Vector2(1f, 0f);
|
||||||
|
overlayScrollPanelScrollbarRT.anchorMax = Vector2.one;
|
||||||
|
overlayScrollPanelScrollbarRT.sizeDelta = new Vector2(cbbRT.sizeDelta.y, 0f);
|
||||||
|
overlayScrollPanelScrollbarRT.pivot = Vector2.one;
|
||||||
|
overlayScrollPanelScrollbarRT.GetComponent<Scrollbar>().direction = Scrollbar.Direction.BottomToTop;
|
||||||
|
overlayScrollPanelScrollBar.transform.GetChild(0).name = "SlidingArea";
|
||||||
|
|
||||||
|
//Arrow Button
|
||||||
|
arrowButton.name = "ArrowBtn";
|
||||||
|
var arrowButtonRT = arrowButton.GetComponent<RectTransform>();
|
||||||
|
arrowButtonRT.anchorMin = Vector2.one;
|
||||||
|
arrowButtonRT.anchorMax = Vector2.one;
|
||||||
|
arrowButtonRT.sizeDelta = new Vector2(cbbRT.sizeDelta.y, cbbRT.sizeDelta.y);
|
||||||
|
arrowButtonRT.pivot = Vector2.one;
|
||||||
|
Events.UnityEventTools.AddBoolPersistentListener(arrowButton.GetComponent<Button>().onClick, new UnityEngine.Events.UnityAction<bool>(autoCompleteComboBox.ToggleDropdownPanel), true);
|
||||||
|
arrowButton.GetComponentInChildren<Text>().text = "▼";
|
||||||
|
|
||||||
|
Selection.activeGameObject = autoCompleteComboBoxRoot;
|
||||||
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/UI/Extensions/ComboBox", false)]
|
[MenuItem("GameObject/UI/Extensions/ComboBox", false)]
|
||||||
static public void AddComboBox(MenuCommand menuCommand)
|
static public void AddComboBox(MenuCommand menuCommand)
|
||||||
{
|
{
|
||||||
|
@ -444,6 +536,138 @@ namespace UnityEditor.UI
|
||||||
Selection.activeGameObject = comboBoxRoot;
|
Selection.activeGameObject = comboBoxRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MenuItem("GameObject/UI/Extensions/DropDownList", false)]
|
||||||
|
static public void AddDropDownList(MenuCommand menuCommand)
|
||||||
|
{
|
||||||
|
GameObject dropDownListRoot = CreateUIElementRoot("DropDownList", menuCommand, s_ThickGUIElementSize);
|
||||||
|
|
||||||
|
//Create Template
|
||||||
|
GameObject itemTemplate = AddButtonAsChild(dropDownListRoot);
|
||||||
|
GameObject itemTemplateImage = AddImageAsChild(itemTemplate);
|
||||||
|
itemTemplateImage.GetComponent<Transform>().SetSiblingIndex(0);
|
||||||
|
|
||||||
|
//Create Main Button
|
||||||
|
GameObject mainButton = AddButtonAsChild(dropDownListRoot);
|
||||||
|
GameObject mainButtonImage = AddImageAsChild(mainButton);
|
||||||
|
mainButtonImage.GetComponent<Transform>().SetSiblingIndex(0);
|
||||||
|
|
||||||
|
//Create Overlay
|
||||||
|
GameObject overlay = CreateUIObject("Overlay", dropDownListRoot);
|
||||||
|
GameObject overlayScrollPanel = CreateUIObject("ScrollPanel", overlay);
|
||||||
|
GameObject overlayScrollPanelItems = CreateUIObject("Items", overlayScrollPanel);
|
||||||
|
GameObject overlayScrollPanelScrollBar = AddScrollbarAsChild(overlayScrollPanel);
|
||||||
|
|
||||||
|
//Create Arrow Button
|
||||||
|
GameObject arrowText = AddTextAsChild(dropDownListRoot);
|
||||||
|
|
||||||
|
//Setup DropDownList
|
||||||
|
var dropDownList = dropDownListRoot.AddComponent<DropDownList>();
|
||||||
|
var cbbRT = dropDownListRoot.GetComponent<RectTransform>();
|
||||||
|
|
||||||
|
//Setup Template
|
||||||
|
itemTemplate.name = "ItemTemplate";
|
||||||
|
var itemTemplateRT = itemTemplate.GetComponent<RectTransform>();
|
||||||
|
itemTemplateRT.sizeDelta = cbbRT.sizeDelta;
|
||||||
|
var itemTemplateButton = itemTemplate.GetComponent<Button>();
|
||||||
|
itemTemplateButton.transition = Selectable.Transition.None;
|
||||||
|
var itemTemplateLayoutElement = itemTemplate.AddComponent<LayoutElement>();
|
||||||
|
itemTemplateLayoutElement.minHeight = cbbRT.rect.height;
|
||||||
|
itemTemplate.SetActive(false);
|
||||||
|
//Item Template Image
|
||||||
|
var itemTemplateImageRT = itemTemplateImage.GetComponent<RectTransform>();
|
||||||
|
itemTemplateImageRT.anchorMin = Vector2.zero;
|
||||||
|
itemTemplateImageRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
itemTemplateImageRT.pivot = new Vector2(0f, 1f);
|
||||||
|
itemTemplateImageRT.sizeDelta = Vector2.one;
|
||||||
|
itemTemplateImageRT.offsetMin = new Vector2(4f, 4f);
|
||||||
|
itemTemplateImageRT.offsetMax = new Vector2(22f, -4f);
|
||||||
|
itemTemplateImage.GetComponent<Image>().color = new Color(0, 0, 0, 0);
|
||||||
|
|
||||||
|
//Setup Main Button
|
||||||
|
mainButton.name = "MainButton";
|
||||||
|
var mainButtonRT = mainButton.GetComponent<RectTransform>();
|
||||||
|
mainButtonRT.anchorMin = Vector2.zero;
|
||||||
|
mainButtonRT.anchorMax = Vector2.one;
|
||||||
|
mainButtonRT.sizeDelta = Vector2.zero;
|
||||||
|
Events.UnityEventTools.AddBoolPersistentListener(mainButton.GetComponent<Button>().onClick, new UnityEngine.Events.UnityAction<bool>(dropDownList.ToggleDropdownPanel), true);
|
||||||
|
var mainButtonText = mainButton.GetComponentInChildren<Text>();
|
||||||
|
mainButtonText.alignment = TextAnchor.MiddleLeft;
|
||||||
|
mainButtonText.text = "Select Item...";
|
||||||
|
var mainButtonTextRT = mainButtonText.GetComponent<RectTransform>();
|
||||||
|
mainButtonTextRT.anchorMin = Vector2.zero;
|
||||||
|
mainButtonTextRT.anchorMin = Vector2.zero;
|
||||||
|
mainButtonTextRT.pivot = new Vector2(0f, 1f);
|
||||||
|
mainButtonTextRT.offsetMin = new Vector2(10f,0f);
|
||||||
|
mainButtonTextRT.offsetMax = new Vector2(-4f,0f);
|
||||||
|
//Main Button Image
|
||||||
|
var mainButtonImageRT = mainButtonImage.GetComponent<RectTransform>();
|
||||||
|
mainButtonImageRT.anchorMin = Vector2.zero;
|
||||||
|
mainButtonImageRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
mainButtonImageRT.pivot = new Vector2(0f, 1f);
|
||||||
|
mainButtonImageRT.sizeDelta = Vector2.one;
|
||||||
|
mainButtonImageRT.offsetMin = new Vector2(4f, 4f);
|
||||||
|
mainButtonImageRT.offsetMax = new Vector2(22f, -4f);
|
||||||
|
mainButtonImageRT.GetComponent<Image>().color = new Color(1, 1, 1, 0);
|
||||||
|
|
||||||
|
|
||||||
|
//Setup Overlay
|
||||||
|
var overlayRT = overlay.GetComponent<RectTransform>();
|
||||||
|
overlayRT.anchorMin = new Vector2(0f, 1f);
|
||||||
|
overlayRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
overlayRT.sizeDelta = new Vector2(0f, 1f);
|
||||||
|
overlayRT.pivot = new Vector2(0f, 1f);
|
||||||
|
overlay.AddComponent<Image>().color = new Color(0.243f, 0.871f, 0f, 0f);
|
||||||
|
Events.UnityEventTools.AddBoolPersistentListener(overlay.AddComponent<Button>().onClick, new UnityEngine.Events.UnityAction<bool>(dropDownList.ToggleDropdownPanel), true);
|
||||||
|
//Overlay Scroll Panel
|
||||||
|
var overlayScrollPanelRT = overlayScrollPanel.GetComponent<RectTransform>();
|
||||||
|
overlayScrollPanelRT.position += new Vector3(0, -cbbRT.sizeDelta.y, 0);
|
||||||
|
overlayScrollPanelRT.anchorMin = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelRT.sizeDelta = new Vector2(cbbRT.sizeDelta.x, cbbRT.sizeDelta.y * 3);
|
||||||
|
overlayScrollPanelRT.pivot = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanel.AddComponent<Image>();
|
||||||
|
overlayScrollPanel.AddComponent<Mask>();
|
||||||
|
var scrollRect = overlayScrollPanel.AddComponent<ScrollRect>();
|
||||||
|
scrollRect.horizontal = false;
|
||||||
|
scrollRect.movementType = ScrollRect.MovementType.Clamped;
|
||||||
|
scrollRect.verticalScrollbar = overlayScrollPanelScrollBar.GetComponent<Scrollbar>();
|
||||||
|
//Overlay Items list
|
||||||
|
var overlayScrollPanelItemsRT = overlayScrollPanelItems.GetComponent<RectTransform>();
|
||||||
|
overlayScrollPanelItemsRT.position += new Vector3(5, 0, 0);
|
||||||
|
overlayScrollPanelItemsRT.anchorMin = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelItemsRT.anchorMax = new Vector2(0f, 1f);
|
||||||
|
overlayScrollPanelItemsRT.sizeDelta = new Vector2(120f, 5f);
|
||||||
|
overlayScrollPanelItemsRT.pivot = new Vector2(0f, 1f);
|
||||||
|
scrollRect.content = overlayScrollPanelItemsRT;
|
||||||
|
var overlayScrollPanelItemsVLG = overlayScrollPanelItems.AddComponent<VerticalLayoutGroup>();
|
||||||
|
overlayScrollPanelItemsVLG.padding = new RectOffset(0, 0, 5, 0);
|
||||||
|
var overlayScrollPanelItemsFitter = overlayScrollPanelItems.AddComponent<ContentSizeFitter>();
|
||||||
|
overlayScrollPanelItemsFitter.verticalFit = ContentSizeFitter.FitMode.MinSize;
|
||||||
|
//Overlay Scrollbar
|
||||||
|
var overlayScrollPanelScrollbarRT = overlayScrollPanelScrollBar.GetComponent<RectTransform>();
|
||||||
|
overlayScrollPanelScrollbarRT.anchorMin = new Vector2(1f, 0f);
|
||||||
|
overlayScrollPanelScrollbarRT.anchorMax = Vector2.one;
|
||||||
|
overlayScrollPanelScrollbarRT.sizeDelta = new Vector2(cbbRT.sizeDelta.y, 0f);
|
||||||
|
overlayScrollPanelScrollbarRT.pivot = Vector2.one;
|
||||||
|
overlayScrollPanelScrollbarRT.GetComponent<Scrollbar>().direction = Scrollbar.Direction.BottomToTop;
|
||||||
|
overlayScrollPanelScrollBar.transform.GetChild(0).name = "SlidingArea";
|
||||||
|
|
||||||
|
//Arrow Button
|
||||||
|
arrowText.name = "Arrow";
|
||||||
|
var arrowTextRT = arrowText.GetComponent<RectTransform>();
|
||||||
|
arrowTextRT.anchorMin = new Vector2(1f, 0f);
|
||||||
|
arrowTextRT.anchorMax = Vector2.one;
|
||||||
|
arrowTextRT.sizeDelta = new Vector2(cbbRT.sizeDelta.y, cbbRT.sizeDelta.y);
|
||||||
|
arrowTextRT.pivot = new Vector2(1f, 0.5f);
|
||||||
|
var arrowTextComponent = arrowText.GetComponent<Text>();
|
||||||
|
arrowTextComponent.text = "▼";
|
||||||
|
arrowTextComponent.alignment = TextAnchor.MiddleCenter;
|
||||||
|
var arrowTextCanvasGroup = arrowText.AddComponent<CanvasGroup>();
|
||||||
|
arrowTextCanvasGroup.interactable = false;
|
||||||
|
arrowTextCanvasGroup.blocksRaycasts = false;
|
||||||
|
Selection.activeGameObject = dropDownListRoot;
|
||||||
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/UI/Extensions/Selection Box", false)]
|
[MenuItem("GameObject/UI/Extensions/Selection Box", false)]
|
||||||
static public void AddSelectionBox(MenuCommand menuCommand)
|
static public void AddSelectionBox(MenuCommand menuCommand)
|
||||||
{
|
{
|
||||||
|
@ -468,8 +692,7 @@ namespace UnityEditor.UI
|
||||||
selectableArea.color = new Color(0.816f, 0.816f, 0.816f, 0.353f);
|
selectableArea.color = new Color(0.816f, 0.816f, 0.816f, 0.353f);
|
||||||
|
|
||||||
|
|
||||||
GameObject childSelectableItem = new GameObject("Selectable");
|
GameObject childSelectableItem = CreateUIObject("Selectable", go);
|
||||||
GameObjectUtility.SetParentAndAlign(childSelectableItem, go);
|
|
||||||
childSelectableItem.AddComponent<Image>();
|
childSelectableItem.AddComponent<Image>();
|
||||||
childSelectableItem.AddComponent<ExampleSelectable>();
|
childSelectableItem.AddComponent<ExampleSelectable>();
|
||||||
|
|
||||||
|
@ -477,6 +700,53 @@ namespace UnityEditor.UI
|
||||||
Selection.activeGameObject = go;
|
Selection.activeGameObject = go;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MenuItem("GameObject/UI/Extensions/Bound Tooltip/Tooltip", false)]
|
||||||
|
static public void AddBoundTooltip(MenuCommand menuCommand)
|
||||||
|
{
|
||||||
|
GameObject go = CreateUIElementRoot("Tooltip", menuCommand, s_ImageGUIElementSize);
|
||||||
|
var tooltip = go.AddComponent<BoundTooltipTrigger>();
|
||||||
|
tooltip.text = "This is my Tooltip Text";
|
||||||
|
var boundTooltip = go.AddComponent<Image>();
|
||||||
|
boundTooltip.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpriteResourcePath);
|
||||||
|
|
||||||
|
// if there is no ToolTipItem add one...
|
||||||
|
CreateToolTipItem(false, go);
|
||||||
|
Selection.activeGameObject = go;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CreateToolTipItem(bool select)
|
||||||
|
{
|
||||||
|
CreateToolTipItem(select, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CreateToolTipItem(bool select, GameObject parent)
|
||||||
|
{
|
||||||
|
var btti = Object.FindObjectOfType<BoundTooltipItem>();
|
||||||
|
if (btti == null)
|
||||||
|
{
|
||||||
|
var boundTooltipItem = CreateUIObject("ToolTipItem", parent.GetComponentInParent<Canvas>().gameObject);
|
||||||
|
btti = boundTooltipItem.AddComponent<BoundTooltipItem>();
|
||||||
|
var boundTooltipItemCanvasGroup = boundTooltipItem.AddComponent<CanvasGroup>();
|
||||||
|
boundTooltipItemCanvasGroup.interactable = false;
|
||||||
|
boundTooltipItemCanvasGroup.blocksRaycasts = false;
|
||||||
|
var boundTooltipItemImage = boundTooltipItem.AddComponent<Image>();
|
||||||
|
boundTooltipItemImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpriteResourcePath);
|
||||||
|
var boundTooltipItemText = CreateUIObject("Text", boundTooltipItem);
|
||||||
|
var boundTooltipItemTextRT = boundTooltipItemText.GetComponent<RectTransform>();
|
||||||
|
boundTooltipItemTextRT.anchorMin = Vector2.zero;
|
||||||
|
boundTooltipItemTextRT.anchorMax = Vector2.one;
|
||||||
|
boundTooltipItemTextRT.sizeDelta = Vector2.one;
|
||||||
|
var boundTooltipItemTextcomponent = boundTooltipItemText.AddComponent<Text>();
|
||||||
|
boundTooltipItemTextcomponent.alignment = TextAnchor.MiddleCenter;
|
||||||
|
Undo.RegisterCreatedObjectUndo(boundTooltipItem, "Create " + boundTooltipItem.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (select && btti != null)
|
||||||
|
{
|
||||||
|
Selection.activeGameObject = btti.gameObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helper Functions
|
#region Helper Functions
|
||||||
|
@ -573,6 +843,15 @@ namespace UnityEditor.UI
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static GameObject AddImageAsChild(GameObject parent)
|
||||||
|
{
|
||||||
|
GameObject go = CreateUIObject("Image", parent);
|
||||||
|
|
||||||
|
go.AddComponent<Image>();
|
||||||
|
|
||||||
|
return go;
|
||||||
|
}
|
||||||
|
|
||||||
private static GameObject AddButtonAsChild(GameObject parent)
|
private static GameObject AddButtonAsChild(GameObject parent)
|
||||||
{
|
{
|
||||||
GameObject buttonRoot = CreateUIObject("Button", parent);
|
GameObject buttonRoot = CreateUIObject("Button", parent);
|
||||||
|
@ -600,6 +879,7 @@ namespace UnityEditor.UI
|
||||||
|
|
||||||
return buttonRoot;
|
return buttonRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Layout Group controller that arranges children in rows, fitting as many on a line until total width exceeds parent bounds
|
/// Layout Group controller that arranges children in rows, fitting as many on a line until total width exceeds parent bounds
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AddComponentMenu("UI/Extensions/Flow Layout Group")]
|
[AddComponentMenu("Layout/Extensions/Flow Layout Group")]
|
||||||
public class FlowLayoutGroup : LayoutGroup
|
public class FlowLayoutGroup : LayoutGroup
|
||||||
{
|
{
|
||||||
public float Spacing = 0f;
|
public float Spacing = 0f;
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue