diff --git a/README.md b/README.md index d2de9dc..ad5cb3a 100644 --- a/README.md +++ b/README.md @@ -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 **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 +**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 ## ===================== @@ -46,6 +51,7 @@ Component | Description | Component Command | Notes | Credits **ReturnKeyTrigger** | Does something?? | UI / Extensions / ReturnKey Trigger | | Melang, ddreaper **TabNavigation** | An example Tab navigation script | UI / Extensions / Tab Navigation | | Melang, omatase **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* diff --git a/Scripts/BoundTooltip.meta b/Scripts/BoundTooltip.meta new file mode 100644 index 0000000..f209a1e --- /dev/null +++ b/Scripts/BoundTooltip.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: dcabbd73a79cd8c4a966e44d7f276790 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/BoundTooltip/BoundTooltipItem.cs b/Scripts/BoundTooltip/BoundTooltipItem.cs new file mode 100644 index 0000000..7294d1e --- /dev/null +++ b/Scripts/BoundTooltip/BoundTooltipItem.cs @@ -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(); + 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(); + return instance; + } + } + } +} + + diff --git a/Scripts/BoundTooltip/BoundTooltipItem.cs.meta b/Scripts/BoundTooltip/BoundTooltipItem.cs.meta new file mode 100644 index 0000000..758dd80 --- /dev/null +++ b/Scripts/BoundTooltip/BoundTooltipItem.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2d6f5ec6d595a31459e6942110d86aaa +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/BoundTooltip/BoundTooltipTrigger.cs b/Scripts/BoundTooltip/BoundTooltipTrigger.cs new file mode 100644 index 0000000..2195c7d --- /dev/null +++ b/Scripts/BoundTooltip/BoundTooltipTrigger.cs @@ -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(); + } + } +} diff --git a/Scripts/BoundTooltip/BoundTooltipTrigger.cs.meta b/Scripts/BoundTooltip/BoundTooltipTrigger.cs.meta new file mode 100644 index 0000000..af5b63a --- /dev/null +++ b/Scripts/BoundTooltip/BoundTooltipTrigger.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d4d7c934af453a9469701b72267593ec +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/ComboBox/AutoCompleteComboBox.cs b/Scripts/ComboBox/AutoCompleteComboBox.cs new file mode 100644 index 0000000..dfdc006 --- /dev/null +++ b/Scripts/ComboBox/AutoCompleteComboBox.cs @@ -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 AvailableOptions; + + public System.Action 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 _panelItems; //items that will get shown in the dropdown + private List _prunedPanelItems; //items that used to show in the dropdown + + private Dictionary 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(); + _inputRT = _rectTransform.FindChild("InputField").GetComponent(); + _mainInput = _inputRT.GetComponent(); + + _overlayRT = _rectTransform.FindChild("Overlay").GetComponent(); + _overlayRT.gameObject.SetActive(false); + + + _scrollPanelRT = _overlayRT.FindChild("ScrollPanel").GetComponent(); + _scrollBarRT = _scrollPanelRT.FindChild("Scrollbar").GetComponent(); + _slidingAreaRT = _scrollBarRT.FindChild("SlidingArea").GetComponent(); + // scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent(); + _itemsPanelRT = _scrollPanelRT.FindChild("Items").GetComponent(); + //itemPanelLayout = itemsPanelRT.gameObject.GetComponent(); + + _canvas = GetComponentInParent(); + _canvasRT = _canvas.GetComponent(); + + _scrollRect = _scrollPanelRT.GetComponent(); + _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(); + + _prunedPanelItems = new List(); + _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 ddItems = new List(); + 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(); + } + */ + + /// + /// Rebuilds the contents of the panel in response to items being added. + /// + private void RebuildPanel() + { + //panel starts with all options + _panelItems.Clear(); + foreach (string option in AvailableOptions) + { + _panelItems.Add(option.ToLower()); + } + _panelItems.Sort(); + + _prunedPanelItems.Clear(); + List itemObjs = new List(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 = _panelItems[i]; //set the text value + + Button itemBtn = itemObjs[i].GetComponent