From 744c52b370fc0bb534481395b836a04d3927c677 Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Tue, 10 Feb 2015 00:03:38 +0000 Subject: [PATCH 1/2] Added new combo box and Editor Menu option Added FlowLayout and AimerInput module but yet to test. --HG-- branch : develop --- LICENSE.meta | 4 + Scripts/AimerInputModule.cs | 92 +++ ...ckBtn.cs.meta => AimerInputModule.cs.meta} | 2 +- Scripts/ComboBox/ClickBtn.cs | 13 - Scripts/ComboBox/ComboBox.cs | 781 ++++++------------ Scripts/ComboBox/DropDownList.cs | 292 +++++++ ...boBoxItem.cs.meta => DropDownList.cs.meta} | 2 +- Scripts/ComboBox/DropDownListButton.cs | 26 + Scripts/ComboBox/DropDownListButton.cs.meta | 8 + .../{ComboBoxItem.cs => DropDownListItem.cs} | 28 +- Scripts/ComboBox/DropDownListItem.cs.meta | 8 + Scripts/Editor/UIExtensionsMenuOptions.cs | 252 +++++- Scripts/FlowLayoutGroup.cs | 254 ++++++ Scripts/FlowLayoutGroup.cs.meta | 8 + UnityUIExtensions.unitypackage.meta | 4 + 15 files changed, 1199 insertions(+), 575 deletions(-) create mode 100644 LICENSE.meta create mode 100644 Scripts/AimerInputModule.cs rename Scripts/{ComboBox/ClickBtn.cs.meta => AimerInputModule.cs.meta} (78%) delete mode 100644 Scripts/ComboBox/ClickBtn.cs create mode 100644 Scripts/ComboBox/DropDownList.cs rename Scripts/ComboBox/{ComboBoxItem.cs.meta => DropDownList.cs.meta} (78%) create mode 100644 Scripts/ComboBox/DropDownListButton.cs create mode 100644 Scripts/ComboBox/DropDownListButton.cs.meta rename Scripts/ComboBox/{ComboBoxItem.cs => DropDownListItem.cs} (71%) create mode 100644 Scripts/ComboBox/DropDownListItem.cs.meta create mode 100644 Scripts/FlowLayoutGroup.cs create mode 100644 Scripts/FlowLayoutGroup.cs.meta create mode 100644 UnityUIExtensions.unitypackage.meta diff --git a/LICENSE.meta b/LICENSE.meta new file mode 100644 index 0000000..c691be0 --- /dev/null +++ b/LICENSE.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: c35f61edc180166489847c79f4b8ea46 +DefaultImporter: + userData: diff --git a/Scripts/AimerInputModule.cs b/Scripts/AimerInputModule.cs new file mode 100644 index 0000000..5c8f835 --- /dev/null +++ b/Scripts/AimerInputModule.cs @@ -0,0 +1,92 @@ +/// Credit Chris Trueman +/// Sourced from - http://forum.unity3d.com/threads/use-reticle-like-mouse-for-worldspace-uis.295271/ + +using System.Collections.Generic; + +namespace UnityEngine.EventSystems.Extensions +{ + + [RequireComponent(typeof(EventSystem))] + [AddComponentMenu("UI/Extensions/Aimer Input Module")] + public class AimerInputModule : BaseInputModule + { + public string ActivateAxis = "Interact"; + + public static GameObject ObjectUnderAimer; + + public static Camera CurrentPlayerCamera; + + protected AimerInputModule() { } + + public void Awake() + { + var StandAloneSystem = GetComponent(); + if (StandAloneSystem != null) + { + Debug.LogError("Aimer Input Module is incompatible with the StandAloneInputSystem, please remove it from the Event System in this scene"); + } + if (!CurrentPlayerCamera) + { + CurrentPlayerCamera = Camera.main; + } + } + + public override void UpdateModule() + { + GetObjectUnderAimer(); + } + + public override void Process() + { + if (ObjectUnderAimer) + { + if (Input.GetButtonDown(ActivateAxis)) + { + BaseEventData eventData = GetBaseEventData(); + eventData.selectedObject = ObjectUnderAimer; + ExecuteEvents.Execute(ObjectUnderAimer, eventData, ExecuteEvents.submitHandler); + } + } + } + + List results = new List(); + + private bool GetObjectUnderAimer() + { + PointerEventData pointerData = new PointerEventData(eventSystem); + pointerData.worldPosition = CurrentPlayerCamera.transform.position; + + eventSystem.RaycastAll(pointerData, results); + + if (results.Count > 0) + { + RaycastResult rayResult = FindFirstRaycast(results); + if (ObjectUnderAimer != rayResult.gameObject) + { + Debug.Log(rayResult.gameObject.name); + ObjectUnderAimer = rayResult.gameObject; + BaseEventData eData = GetBaseEventData(); + eData.selectedObject = ObjectUnderAimer; + ExecuteEvents.Execute(ObjectUnderAimer, eData, ExecuteEvents.pointerEnterHandler); + } + + results.Clear(); + return true; + } + + //We didn't hit anything + + if (ObjectUnderAimer) + { + BaseEventData eData = GetBaseEventData(); + eData.selectedObject = ObjectUnderAimer; + + ExecuteEvents.Execute(ObjectUnderAimer, eData, ExecuteEvents.pointerExitHandler); + } + + results.Clear(); + ObjectUnderAimer = null; + return false; + } + } +} \ No newline at end of file diff --git a/Scripts/ComboBox/ClickBtn.cs.meta b/Scripts/AimerInputModule.cs.meta similarity index 78% rename from Scripts/ComboBox/ClickBtn.cs.meta rename to Scripts/AimerInputModule.cs.meta index f15ec30..9a98d82 100644 --- a/Scripts/ComboBox/ClickBtn.cs.meta +++ b/Scripts/AimerInputModule.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 33a5d65e2f7d10648af0fde6d2de99cc +guid: f7d3d69aa5226dc4493464d3b5e4ddc3 MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/Scripts/ComboBox/ClickBtn.cs b/Scripts/ComboBox/ClickBtn.cs deleted file mode 100644 index a06f2e5..0000000 --- a/Scripts/ComboBox/ClickBtn.cs +++ /dev/null @@ -1,13 +0,0 @@ -///Credit perchik -///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/ - -using UnityEngine; -using System.Collections; - -public class ClickBtn : MonoBehaviour -{ - public void Click() - { - Debug.Log("Clicked"); - } -} diff --git a/Scripts/ComboBox/ComboBox.cs b/Scripts/ComboBox/ComboBox.cs index 984295f..6f01e95 100644 --- a/Scripts/ComboBox/ComboBox.cs +++ b/Scripts/ComboBox/ComboBox.cs @@ -10,616 +10,335 @@ namespace UnityEngine.UI.Extensions [AddComponentMenu("UI/Extensions/ComboBox")] public class ComboBox : MonoBehaviour { - #region declarations - #region private members + public Color disabledTextColor; + public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it - private bool _isActive = false; //is the drop down panel active + public List AvailableOptions; - private Button comboBtn; - private Image comboBtnImg; - private Text comboBtnText; + public System.Action OnSelectionChanged; // fires when selection is changed; - private Button overlayBtn; + //private bool isInitialized = false; + private bool _isPanelActive = false; + private bool _hasDrawnOnce = false; - private GridLayoutGroup itemLayout; + private InputField _mainInput; + private RectTransform _inputRT; - private float _scrollbarWidth = 20.0f; - - private int scrollOffset; //offset of the selected item - - private int _itemsToDisplay = 4; //how many items to show in the dropdown panel - - private bool _hideFirstItem = false; //lets us hide the prompt after something is chosen - - private int _selectedIndex = 0; - - private List _items; //conceptual items in the list - - private bool _interactable = true; - - private Canvas _canvas; - - #region private rect transforms - /// All of these have to be properties so that the editor script can access them - - private RectTransform _overlay; //overlayRT is a screensized box to handle clicks *not* on the button. (although this might have to change with multiple things on the screen. - private RectTransform overlayRT - { - get - { - if (_overlay == null) - { - _overlay = rectTransform.FindChild("Overlay").GetComponent(); - overlayBtn = _overlay.gameObject.GetComponent