Added Start and End move events to the HSS & VSS controls

--HG--
branch : develop_5.3
release
Simon Jackson 2016-11-15 18:09:13 +00:00
parent 2de76cf7a3
commit 1730965a44
2 changed files with 89 additions and 24 deletions

View File

@ -3,6 +3,7 @@
/// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
using System;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
@ -26,6 +27,11 @@ namespace UnityEngine.UI.Extensions
private Vector3 _lerp_target;
private bool _lerp;
[Serializable]
public class SelectionChangeStartEvent : UnityEvent { }
[Serializable]
public class SelectionChangeEndEvent : UnityEvent { }
[Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")]
public GameObject Pagination;
@ -62,7 +68,13 @@ namespace UnityEngine.UI.Extensions
}
}
[SerializeField]
private SelectionChangeStartEvent m_OnSelectionChangeStartEvent = new SelectionChangeStartEvent();
public SelectionChangeStartEvent OnSelectionChangeStartEvent { get { return m_OnSelectionChangeStartEvent; } set { m_OnSelectionChangeStartEvent = value; } }
[SerializeField]
private SelectionChangeEndEvent m_OnSelectionChangeEndEvent = new SelectionChangeEndEvent();
public SelectionChangeEndEvent OnSelectionChangeEndEvent { get { return m_OnSelectionChangeEndEvent; } set { m_OnSelectionChangeEndEvent = value; } }
// Use this for initialization
void Start()
@ -97,9 +109,11 @@ namespace UnityEngine.UI.Extensions
if (_lerp)
{
_screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * Time.deltaTime);
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.005f)
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 1f)
{
_lerp = false;
EndScreenChange();
}
//change the info bullets at the bottom of the screen. Just for visual effect
@ -123,6 +137,8 @@ namespace UnityEngine.UI.Extensions
{
if (_currentScreen < _screens - 1)
{
StartScreenChange();
_currentScreen++;
_lerp = true;
_lerp_target = _positions[_currentScreen];
@ -136,6 +152,8 @@ namespace UnityEngine.UI.Extensions
{
if (_currentScreen > 0)
{
StartScreenChange();
_currentScreen--;
_lerp = true;
_lerp_target = _positions[_currentScreen];
@ -153,10 +171,13 @@ namespace UnityEngine.UI.Extensions
{
if (screenIndex <= _screens - 1 && screenIndex >= 0)
{
_lerp = true;
_lerp_target = _positions[screenIndex];
StartScreenChange();
ChangeBulletsInfo(screenIndex);
_lerp = true;
_currentScreen = screenIndex;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen);
}
}
@ -166,9 +187,10 @@ namespace UnityEngine.UI.Extensions
if (_currentScreen < _screens - 1)
{
_lerp = true;
_lerp_target = _positions[_currentScreen + 1];
_currentScreen++;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen + 1);
ChangeBulletsInfo(_currentScreen);
}
}
@ -178,9 +200,10 @@ namespace UnityEngine.UI.Extensions
if (_currentScreen > 0)
{
_lerp = true;
_lerp_target = _positions[_currentScreen - 1];
_currentScreen--;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen - 1);
ChangeBulletsInfo(_currentScreen);
}
}
@ -334,11 +357,20 @@ namespace UnityEngine.UI.Extensions
_scroll_rect.horizontalNormalizedPosition = (float)(_currentScreen) / (_screens - 1);
}
private void StartScreenChange()
{
OnSelectionChangeStartEvent.Invoke();
}
private void EndScreenChange()
{
OnSelectionChangeEndEvent.Invoke();
}
#region Interfaces
public void OnBeginDrag(PointerEventData eventData)
{
if (!_fastSwipeTimer) StartScreenChange();
_startPosition = _screensContainer.localPosition;
_fastSwipeCounter = 0;
_fastSwipeTimer = true;
@ -398,7 +430,5 @@ namespace UnityEngine.UI.Extensions
}
}
#endregion
}
}

View File

@ -3,6 +3,7 @@
/// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
using System;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
@ -25,6 +26,11 @@ namespace UnityEngine.UI.Extensions
private Vector3 _lerp_target;
private bool _lerp;
[Serializable]
public class SelectionChangeStartEvent : UnityEvent { }
[Serializable]
public class SelectionChangeEndEvent : UnityEvent { }
[Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")]
public GameObject Pagination;
@ -61,6 +67,14 @@ namespace UnityEngine.UI.Extensions
}
}
[SerializeField]
private SelectionChangeStartEvent m_OnSelectionChangeStartEvent = new SelectionChangeStartEvent();
public SelectionChangeStartEvent OnSelectionChangeStartEvent { get { return m_OnSelectionChangeStartEvent; } set { m_OnSelectionChangeStartEvent = value; } }
[SerializeField]
private SelectionChangeEndEvent m_OnSelectionChangeEndEvent = new SelectionChangeEndEvent();
public SelectionChangeEndEvent OnSelectionChangeEndEvent { get { return m_OnSelectionChangeEndEvent; } set { m_OnSelectionChangeEndEvent = value; } }
// Use this for initialization
void Start()
{
@ -94,9 +108,10 @@ namespace UnityEngine.UI.Extensions
if (_lerp)
{
_screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * Time.deltaTime);
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.005f)
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 1f)
{
_lerp = false;
EndScreenChange();
}
//change the info bullets at the bottom of the screen. Just for visual effect
@ -121,8 +136,10 @@ namespace UnityEngine.UI.Extensions
{
if (_currentScreen < _screens - 1)
{
_currentScreen++;
StartScreenChange();
_lerp = true;
_currentScreen++;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen);
@ -134,8 +151,10 @@ namespace UnityEngine.UI.Extensions
{
if (_currentScreen > 0)
{
_currentScreen--;
StartScreenChange();
_lerp = true;
_currentScreen--;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen);
@ -151,10 +170,13 @@ namespace UnityEngine.UI.Extensions
{
if (screenIndex <= _screens - 1 && screenIndex >= 0)
{
_lerp = true;
_lerp_target = _positions[screenIndex];
StartScreenChange();
ChangeBulletsInfo(screenIndex);
_lerp = true;
_currentScreen = screenIndex;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen);
}
}
@ -164,9 +186,10 @@ namespace UnityEngine.UI.Extensions
if (_currentScreen < _screens - 1)
{
_lerp = true;
_lerp_target = _positions[_currentScreen + 1];
_currentScreen++;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen + 1);
ChangeBulletsInfo(_currentScreen);
}
}
@ -176,9 +199,10 @@ namespace UnityEngine.UI.Extensions
if (_currentScreen > 0)
{
_lerp = true;
_lerp_target = _positions[_currentScreen - 1];
_currentScreen--;
_lerp_target = _positions[_currentScreen];
ChangeBulletsInfo(_currentScreen - 1);
ChangeBulletsInfo(_currentScreen);
}
}
@ -331,9 +355,20 @@ namespace UnityEngine.UI.Extensions
_scroll_rect.verticalNormalizedPosition = (float)(_currentScreen) / (_screens - 1);
}
private void StartScreenChange()
{
OnSelectionChangeStartEvent.Invoke();
}
private void EndScreenChange()
{
OnSelectionChangeEndEvent.Invoke();
}
#region Interfaces
public void OnBeginDrag(PointerEventData eventData)
{
if (!_fastSwipeTimer) StartScreenChange();
_startPosition = _screensContainer.localPosition;
_fastSwipeCounter = 0;
_fastSwipeTimer = true;