1st Pass update, Updated controls:
* DropDownList/ComboBox * Reorderable List (Screen Space Camera Updates * Curved text fixesrelease
parent
a09a5b5322
commit
dc809858b9
|
@ -37,7 +37,7 @@ RenderSettings:
|
|||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_IndirectSpecularColor: {r: 0.44657868, g: 0.49641263, b: 0.57481706, a: 1}
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -756,9 +756,9 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 97a58789aa01843488ef44dc747ee8e8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
useHalfCharWidth: 0
|
||||
halfCharWidth: 0
|
||||
m_spacing: 94.2
|
||||
HalfCharWidth: 1
|
||||
UseHalfCharWidth: 0
|
||||
--- !u!114 &755348327
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -985,7 +985,7 @@ RectTransform:
|
|||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1101119004}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
|
@ -1009,7 +1009,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 0ec526a95e7733b4396be80d3e1df80e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
radius: 121.96
|
||||
radius: 98.31
|
||||
--- !u!114 &1101119007
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1339,9 +1339,9 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 97a58789aa01843488ef44dc747ee8e8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
useHalfCharWidth: 1
|
||||
halfCharWidth: 4.55
|
||||
m_spacing: 71.12
|
||||
HalfCharWidth: 1
|
||||
UseHalfCharWidth: 0
|
||||
--- !u!114 &1814753282
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -76,8 +76,9 @@ namespace UnityEngine.UI.Extensions
|
|||
public bool SelectFirstItemOnStart = false;
|
||||
|
||||
[SerializeField]
|
||||
private bool _ChangeInputTextColorBasedOnMatchingItems = false;
|
||||
public bool ChangeInputTextColorBasedOnMatchingItems{
|
||||
[Tooltip("Change input text color based on matching items")]
|
||||
private bool _ChangeInputTextColorBasedOnMatchingItems = false;
|
||||
public bool InputColorMatching{
|
||||
get { return _ChangeInputTextColorBasedOnMatchingItems; }
|
||||
set
|
||||
{
|
||||
|
@ -99,8 +100,8 @@ namespace UnityEngine.UI.Extensions
|
|||
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string, bool> {
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SelectinTextChangedEvent : UnityEngine.Events.UnityEvent<string> {
|
||||
[System.Serializable]
|
||||
public class SelectionTextChangedEvent : UnityEngine.Events.UnityEvent<string> {
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
@ -108,14 +109,12 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
|
||||
// fires when input text is changed;
|
||||
public SelectinTextChangedEvent OnSelectinTextChanged;
|
||||
public SelectionTextChangedEvent OnSelectionTextChanged;
|
||||
// fires when when an Item gets selected / deselected (including when items are added/removed once this is possible)
|
||||
public SelectionValidityChangedEvent OnSelectionValidityChanged;
|
||||
// fires in both cases
|
||||
public SelectionChangedEvent OnSelectionChanged;
|
||||
|
||||
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
Initialize();
|
||||
|
@ -354,7 +353,7 @@ namespace UnityEngine.UI.Extensions
|
|||
bool validity_changed = (_panelItems.Contains (Text) == _selectionIsValid);
|
||||
_selectionIsValid = _panelItems.Contains (Text);
|
||||
OnSelectionChanged.Invoke (Text, _selectionIsValid);
|
||||
OnSelectinTextChanged.Invoke (Text);
|
||||
OnSelectionTextChanged.Invoke (Text);
|
||||
if(validity_changed){
|
||||
OnSelectionValidityChanged.Invoke (_selectionIsValid);
|
||||
}
|
||||
|
@ -363,7 +362,7 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
|
||||
private void SetInputTextColor(){
|
||||
if (ChangeInputTextColorBasedOnMatchingItems) {
|
||||
if (InputColorMatching) {
|
||||
if (_selectionIsValid) {
|
||||
_mainInput.textComponent.color = ValidSelectionTextColor;
|
||||
} else if (_panelItems.Count > 0) {
|
||||
|
|
|
@ -15,7 +15,18 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
public List<string> AvailableOptions;
|
||||
|
||||
public System.Action<int> OnSelectionChanged; // fires when selection is changed;
|
||||
[SerializeField]
|
||||
private float _scrollBarWidth = 20.0f;
|
||||
|
||||
[SerializeField]
|
||||
private int _itemsToDisplay;
|
||||
|
||||
[System.Serializable]
|
||||
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string>
|
||||
{
|
||||
}
|
||||
// fires when item is changed;
|
||||
public SelectionChangedEvent OnSelectionChanged;
|
||||
|
||||
//private bool isInitialized = false;
|
||||
private bool _isPanelActive = false;
|
||||
|
@ -46,8 +57,6 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
public string Text { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
private float _scrollBarWidth = 20.0f;
|
||||
public float ScrollBarWidth
|
||||
{
|
||||
get { return _scrollBarWidth; }
|
||||
|
@ -61,8 +70,6 @@ namespace UnityEngine.UI.Extensions
|
|||
// private int scrollOffset; //offset of the selected item
|
||||
// private int _selectedIndex = 0;
|
||||
|
||||
[SerializeField]
|
||||
private int _itemsToDisplay;
|
||||
public int ItemsToDisplay
|
||||
{
|
||||
get { return _itemsToDisplay; }
|
||||
|
@ -294,6 +301,7 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
ToggleDropdownPanel(false);
|
||||
}
|
||||
OnSelectionChanged.Invoke(Text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -79,8 +79,6 @@ namespace UnityEngine.UI.Extensions
|
|||
public SelectionChangedEvent OnSelectionChanged;
|
||||
|
||||
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Initialize();
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
/// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
|
@ -22,12 +24,13 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
[Tooltip("Can new draggable items be dropped in to the container?")]
|
||||
public bool IsDropable = true;
|
||||
|
||||
|
||||
|
||||
[Header("UI Re-orderable Events")]
|
||||
public ReorderableListHandler OnElementDropped = new ReorderableListHandler();
|
||||
public ReorderableListHandler OnElementGrabbed = new ReorderableListHandler();
|
||||
public ReorderableListHandler OnElementRemoved = new ReorderableListHandler();
|
||||
public ReorderableListHandler OnElementAdded = new ReorderableListHandler();
|
||||
|
||||
private RectTransform _content;
|
||||
private ReorderableListContent _listContent;
|
||||
|
@ -83,9 +86,9 @@ namespace UnityEngine.UI.Extensions
|
|||
Debug.LogError("You need to have a Graphic control (such as an Image) for the list [" + name + "] to be droppable", gameObject);
|
||||
return;
|
||||
}
|
||||
if (GetCanvas().renderMode != RenderMode.ScreenSpaceOverlay)
|
||||
if (GetCanvas().renderMode > RenderMode.ScreenSpaceCamera)
|
||||
{
|
||||
Debug.LogError("The ReOrderable List is only supported on a Screenspace-Overlay Canvas at the moment");
|
||||
Debug.LogError("The ReOrderable List is only supported on a Screen-Space Canvas at the moment");
|
||||
}
|
||||
|
||||
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
|
||||
|
@ -104,6 +107,11 @@ namespace UnityEngine.UI.Extensions
|
|||
public GameObject SourceObject;
|
||||
public int ToIndex;
|
||||
public ReorderableList ToList;
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
SourceObject.GetComponent<ReorderableListElement>().isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b333d67eb08d464d823874f6a1666c2
|
||||
timeCreated: 1446072130
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
fileFormatVersion: 2
|
||||
guid: 6b333d67eb08d464d823874f6a1666c2
|
||||
timeCreated: 1492560112
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
|
@ -14,9 +14,15 @@ namespace UnityEngine.UI.Extensions
|
|||
private ReorderableList _extList;
|
||||
private RectTransform _rect;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if(_rect)StartCoroutine(RefreshChildren());
|
||||
}
|
||||
|
||||
|
||||
public void OnTransformChildrenChanged()
|
||||
{
|
||||
StartCoroutine(RefreshChildren());
|
||||
if(this.isActiveAndEnabled)StartCoroutine(RefreshChildren());
|
||||
}
|
||||
|
||||
public void Init(ReorderableList extList)
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
/// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/
|
||||
/// Last Child Fix - https://bitbucket.org/ddreaper/unity-ui-extensions/issues/70/all-re-orderable-lists-cause-a-transform
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
|
@ -11,6 +13,14 @@ namespace UnityEngine.UI.Extensions
|
|||
[RequireComponent(typeof(RectTransform))]
|
||||
public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
||||
{
|
||||
[Tooltip("Can this element be dragged?")]
|
||||
public bool IsGrabbable = true;
|
||||
[Tooltip("Can this element be transfered to another list")]
|
||||
public bool IsTransferable = true;
|
||||
[Tooltip("Can this element be dropped in space?")]
|
||||
public bool isDroppableInSpace = false;
|
||||
|
||||
|
||||
private readonly List<RaycastResult> _raycastResults = new List<RaycastResult>();
|
||||
private ReorderableList _currentReorderableListRaycasted;
|
||||
private RectTransform _draggingObject;
|
||||
|
@ -22,16 +32,18 @@ namespace UnityEngine.UI.Extensions
|
|||
private bool _isDragging;
|
||||
private RectTransform _rect;
|
||||
private ReorderableList _reorderableList;
|
||||
internal bool isValid;
|
||||
|
||||
#region IBeginDragHandler Members
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
isValid = true;
|
||||
if (_reorderableList == null)
|
||||
return;
|
||||
|
||||
//Can't drag, return...
|
||||
if (!_reorderableList.IsDraggable)
|
||||
if (!_reorderableList.IsDraggable || !this.IsGrabbable)
|
||||
{
|
||||
_draggingObject = null;
|
||||
return;
|
||||
|
@ -54,6 +66,11 @@ namespace UnityEngine.UI.Extensions
|
|||
FromIndex = _fromIndex,
|
||||
});
|
||||
}
|
||||
if (isValid == false)
|
||||
{
|
||||
_draggingObject = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Else Duplicate
|
||||
else
|
||||
|
@ -86,6 +103,12 @@ namespace UnityEngine.UI.Extensions
|
|||
FromList = _reorderableList,
|
||||
FromIndex = _fromIndex,
|
||||
});
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
CancelDrag();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_isDragging = true;
|
||||
|
@ -99,10 +122,18 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
if (!_isDragging)
|
||||
return;
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
CancelDrag();
|
||||
return;
|
||||
}
|
||||
//Set dragging object on cursor
|
||||
_draggingObject.position = eventData.position;
|
||||
|
||||
var canvas = _draggingObject.GetComponentInParent<Canvas>();
|
||||
Vector3 worldPoint;
|
||||
RectTransformUtility.ScreenPointToWorldPointInRectangle(canvas.GetComponent<RectTransform>(), eventData.position,
|
||||
canvas.worldCamera, out worldPoint);
|
||||
_draggingObject.position = worldPoint;
|
||||
|
||||
//Check everything under the cursor to find a ReorderableList
|
||||
EventSystem.current.RaycastAll(eventData, _raycastResults);
|
||||
for (int i = 0; i < _raycastResults.Count; i++)
|
||||
|
@ -135,11 +166,11 @@ namespace UnityEngine.UI.Extensions
|
|||
var c = _currentReorderableListRaycasted.Content.GetChild(j).GetComponent<RectTransform>();
|
||||
|
||||
if (_currentReorderableListRaycasted.ContentLayout is VerticalLayoutGroup)
|
||||
dist = Mathf.Abs(c.position.y - eventData.position.y);
|
||||
dist = Mathf.Abs(c.position.y - worldPoint.y);
|
||||
else if (_currentReorderableListRaycasted.ContentLayout is HorizontalLayoutGroup)
|
||||
dist = Mathf.Abs(c.position.x - eventData.position.x);
|
||||
dist = Mathf.Abs(c.position.x - worldPoint.x);
|
||||
else if (_currentReorderableListRaycasted.ContentLayout is GridLayoutGroup)
|
||||
dist = (Mathf.Abs(c.position.x - eventData.position.x) + Mathf.Abs(c.position.y - eventData.position.y));
|
||||
dist = (Mathf.Abs(c.position.x - worldPoint.x) + Mathf.Abs(c.position.y - worldPoint.y));
|
||||
|
||||
if (dist < minDistance)
|
||||
{
|
||||
|
@ -167,42 +198,56 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
//If we have a, ReorderableList that is dropable
|
||||
//Put the dragged object into the content and at the right index
|
||||
if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable)
|
||||
if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable
|
||||
&& (IsTransferable || _currentReorderableListRaycasted == _reorderableList ))
|
||||
{
|
||||
var args = new ReorderableList.ReorderableListEventStruct
|
||||
{
|
||||
DroppedObject = _draggingObject.gameObject,
|
||||
IsAClone = _reorderableList.CloneDraggedObject,
|
||||
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
||||
FromList = _reorderableList,
|
||||
FromIndex = _fromIndex,
|
||||
ToList = _currentReorderableListRaycasted,
|
||||
ToIndex = _fakeElement.GetSiblingIndex()
|
||||
};
|
||||
//Send OnelementDropped Event
|
||||
if (_reorderableList && _reorderableList.OnElementDropped != null)
|
||||
{
|
||||
_reorderableList.OnElementDropped.Invoke(args);
|
||||
}
|
||||
if (!isValid)
|
||||
{
|
||||
CancelDrag();
|
||||
return;
|
||||
}
|
||||
RefreshSizes();
|
||||
_draggingObject.SetParent(_currentReorderableListRaycasted.Content, false);
|
||||
_draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex());
|
||||
|
||||
_reorderableList.OnElementAdded.Invoke(args);
|
||||
|
||||
//Send OnelementDropped Event
|
||||
if (_reorderableList.OnElementDropped != null)
|
||||
if(!isValid) throw new Exception("It's too late to cancel the Transfer! Do so in OnElementDropped!");
|
||||
|
||||
}
|
||||
//We don't have an ReorderableList
|
||||
else
|
||||
{
|
||||
if (this.isDroppableInSpace)
|
||||
{
|
||||
_reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct
|
||||
{
|
||||
DroppedObject = _draggingObject.gameObject,
|
||||
IsAClone = _reorderableList.CloneDraggedObject,
|
||||
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
||||
SourceObject =
|
||||
_reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
||||
FromList = _reorderableList,
|
||||
FromIndex = _fromIndex,
|
||||
ToList = _currentReorderableListRaycasted,
|
||||
ToIndex = _fakeElement.GetSiblingIndex() - 1
|
||||
FromIndex = _fromIndex
|
||||
});
|
||||
}
|
||||
}
|
||||
//We don't have an ReorderableList
|
||||
else
|
||||
{
|
||||
//If it's a clone, delete it
|
||||
if (_reorderableList.CloneDraggedObject)
|
||||
{
|
||||
Destroy(_draggingObject.gameObject);
|
||||
}
|
||||
//Else replace the draggedObject to his first place
|
||||
else
|
||||
{
|
||||
RefreshSizes();
|
||||
_draggingObject.SetParent(_reorderableList.Content, false);
|
||||
_draggingObject.SetSiblingIndex(_fromIndex);
|
||||
CancelDrag();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -214,6 +259,45 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
#endregion
|
||||
|
||||
void CancelDrag()
|
||||
{
|
||||
_isDragging = false;
|
||||
//If it's a clone, delete it
|
||||
if (_reorderableList.CloneDraggedObject)
|
||||
{
|
||||
Destroy(_draggingObject.gameObject);
|
||||
}
|
||||
//Else replace the draggedObject to his first place
|
||||
else
|
||||
{
|
||||
RefreshSizes();
|
||||
_draggingObject.SetParent(_reorderableList.Content, false);
|
||||
_draggingObject.SetSiblingIndex(_fromIndex);
|
||||
|
||||
|
||||
var args = new ReorderableList.ReorderableListEventStruct
|
||||
{
|
||||
DroppedObject = _draggingObject.gameObject,
|
||||
IsAClone = _reorderableList.CloneDraggedObject,
|
||||
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
||||
FromList = _reorderableList,
|
||||
FromIndex = _fromIndex,
|
||||
ToList = _reorderableList,
|
||||
ToIndex = _fromIndex
|
||||
};
|
||||
|
||||
|
||||
_reorderableList.OnElementAdded.Invoke(args);
|
||||
|
||||
if (!isValid) throw new Exception("Transfer is already Cancelled.");
|
||||
|
||||
}
|
||||
|
||||
//Delete fake element
|
||||
if (_fakeElement != null)
|
||||
Destroy(_fakeElement.gameObject);
|
||||
}
|
||||
|
||||
private void RefreshSizes()
|
||||
{
|
||||
Vector2 size = _draggingObjectOriginalSize;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 916e98f1b982a9a4082fcc45c87b66c5
|
||||
timeCreated: 1446072130
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
fileFormatVersion: 2
|
||||
guid: 916e98f1b982a9a4082fcc45c87b66c5
|
||||
timeCreated: 1492560112
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
|
@ -57,9 +57,12 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
protected override void OnRectTransformDimensionsChange()
|
||||
{
|
||||
var tmpRect = curveForText[curveForText.length - 1];
|
||||
tmpRect.time = rectTrans.rect.width;
|
||||
curveForText.MoveKey(curveForText.length - 1, tmpRect);
|
||||
if (rectTrans)
|
||||
{
|
||||
Keyframe tmpRect = curveForText[curveForText.length - 1];
|
||||
tmpRect.time = rectTrans.rect.width;
|
||||
curveForText.MoveKey(curveForText.length - 1, tmpRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue