Minor fixes and additions
Updates to resolve reports in Issue #80 --HG-- branch : develop_5.3pull/413/head
parent
3e0d105646
commit
f0ba3cfae5
|
@ -7,8 +7,8 @@ using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
[AddComponentMenu("UI/BoxSlider", 35)]
|
|
||||||
[RequireComponent(typeof(RectTransform))]
|
[RequireComponent(typeof(RectTransform))]
|
||||||
|
[AddComponentMenu("UI/Extensions/BoxSlider")]
|
||||||
public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement
|
public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement
|
||||||
{
|
{
|
||||||
public enum Direction
|
public enum Direction
|
||||||
|
@ -30,15 +30,15 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float m_MinValue = 0;
|
private float m_MinValue = 0;
|
||||||
public float MinValue { get { return m_MinValue; } set { if (SetStruct(ref m_MinValue, value)) { Set(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
|
public float MinValue { get { return m_MinValue; } set { if (SetStruct(ref m_MinValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float m_MaxValue = 1;
|
private float m_MaxValue = 1;
|
||||||
public float MaxValue { get { return m_MaxValue; } set { if (SetStruct(ref m_MaxValue, value)) { Set(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
|
public float MaxValue { get { return m_MaxValue; } set { if (SetStruct(ref m_MaxValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private bool m_WholeNumbers = false;
|
private bool m_WholeNumbers = false;
|
||||||
public bool WholeNumbers { get { return m_WholeNumbers; } set { if (SetStruct(ref m_WholeNumbers, value)) { Set(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
|
public bool WholeNumbers { get { return m_WholeNumbers; } set { if (SetStruct(ref m_WholeNumbers, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float m_ValueX = 1f;
|
private float m_ValueX = 1f;
|
||||||
|
@ -52,7 +52,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Set(value);
|
SetX(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,9 +109,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
// Private fields
|
// Private fields
|
||||||
|
|
||||||
//private Image m_FillImage;
|
|
||||||
//private Transform m_FillTransform;
|
|
||||||
//private RectTransform m_FillContainerRect;
|
|
||||||
private Transform m_HandleTransform;
|
private Transform m_HandleTransform;
|
||||||
private RectTransform m_HandleContainerRect;
|
private RectTransform m_HandleContainerRect;
|
||||||
|
|
||||||
|
@ -137,7 +134,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
m_MaxValue = Mathf.Round(m_MaxValue);
|
m_MaxValue = Mathf.Round(m_MaxValue);
|
||||||
}
|
}
|
||||||
UpdateCachedReferences();
|
UpdateCachedReferences();
|
||||||
Set(m_ValueX, false);
|
SetX(m_ValueX, false);
|
||||||
SetY(m_ValueY, false);
|
SetY(m_ValueY, false);
|
||||||
// Update rects since other things might affect them even if value didn't change.
|
// Update rects since other things might affect them even if value didn't change.
|
||||||
UpdateVisuals();
|
UpdateVisuals();
|
||||||
|
@ -189,7 +186,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
UpdateCachedReferences();
|
UpdateCachedReferences();
|
||||||
Set(m_ValueX, false);
|
SetX(m_ValueX, false);
|
||||||
SetY(m_ValueY, false);
|
SetY(m_ValueY, false);
|
||||||
// Update rects since they need to be initialized correctly.
|
// Update rects since they need to be initialized correctly.
|
||||||
UpdateVisuals();
|
UpdateVisuals();
|
||||||
|
@ -217,12 +214,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the valueUpdate the visible Image.
|
// Set the valueUpdate the visible Image.
|
||||||
void Set(float input)
|
void SetX(float input)
|
||||||
{
|
{
|
||||||
Set(input, true);
|
SetX(input, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set(float input, bool sendCallback)
|
void SetX(float input, bool sendCallback)
|
||||||
{
|
{
|
||||||
// Clamp the input
|
// Clamp the input
|
||||||
float newValue = Mathf.Clamp(input, MinValue, MaxValue);
|
float newValue = Mathf.Clamp(input, MinValue, MaxValue);
|
||||||
|
@ -320,14 +317,14 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool MayDrag(PointerEventData eventData)
|
private bool CanDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
return IsActive() && IsInteractable() && eventData.button == PointerEventData.InputButton.Left;
|
return IsActive() && IsInteractable() && eventData.button == PointerEventData.InputButton.Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnPointerDown(PointerEventData eventData)
|
public override void OnPointerDown(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
if (!MayDrag(eventData))
|
if (!CanDrag(eventData))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
base.OnPointerDown(eventData);
|
base.OnPointerDown(eventData);
|
||||||
|
@ -349,85 +346,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
public virtual void OnDrag(PointerEventData eventData)
|
public virtual void OnDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
if (!MayDrag(eventData))
|
if (!CanDrag(eventData))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UpdateDrag(eventData, eventData.pressEventCamera);
|
UpdateDrag(eventData, eventData.pressEventCamera);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public override void OnMove(AxisEventData eventData)
|
|
||||||
//{
|
|
||||||
// if (!IsActive() || !IsInteractable())
|
|
||||||
// {
|
|
||||||
// base.OnMove(eventData);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// switch (eventData.moveDir)
|
|
||||||
// {
|
|
||||||
// case MoveDirection.Left:
|
|
||||||
// if (axis == Axis.Horizontal && FindSelectableOnLeft() == null) {
|
|
||||||
// Set(reverseValue ? value + stepSize : value - stepSize);
|
|
||||||
// SetY (reverseValue ? valueY + stepSize : valueY - stepSize);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// base.OnMove(eventData);
|
|
||||||
// break;
|
|
||||||
// case MoveDirection.Right:
|
|
||||||
// if (axis == Axis.Horizontal && FindSelectableOnRight() == null) {
|
|
||||||
// Set(reverseValue ? value - stepSize : value + stepSize);
|
|
||||||
// SetY(reverseValue ? valueY - stepSize : valueY + stepSize);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// base.OnMove(eventData);
|
|
||||||
// break;
|
|
||||||
// case MoveDirection.Up:
|
|
||||||
// if (axis == Axis.Vertical && FindSelectableOnUp() == null) {
|
|
||||||
// Set(reverseValue ? value - stepSize : value + stepSize);
|
|
||||||
// SetY(reverseValue ? valueY - stepSize : valueY + stepSize);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// base.OnMove(eventData);
|
|
||||||
// break;
|
|
||||||
// case MoveDirection.Down:
|
|
||||||
// if (axis == Axis.Vertical && FindSelectableOnDown() == null) {
|
|
||||||
// Set(reverseValue ? value + stepSize : value - stepSize);
|
|
||||||
// SetY(reverseValue ? valueY + stepSize : valueY - stepSize);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// base.OnMove(eventData);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public override Selectable FindSelectableOnLeft()
|
|
||||||
//{
|
|
||||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Horizontal)
|
|
||||||
// return null;
|
|
||||||
// return base.FindSelectableOnLeft();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public override Selectable FindSelectableOnRight()
|
|
||||||
//{
|
|
||||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Horizontal)
|
|
||||||
// return null;
|
|
||||||
// return base.FindSelectableOnRight();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public override Selectable FindSelectableOnUp()
|
|
||||||
//{
|
|
||||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Vertical)
|
|
||||||
// return null;
|
|
||||||
// return base.FindSelectableOnUp();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public override Selectable FindSelectableOnDown()
|
|
||||||
//{
|
|
||||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Vertical)
|
|
||||||
// return null;
|
|
||||||
// return base.FindSelectableOnDown();
|
|
||||||
//}
|
|
||||||
|
|
||||||
public virtual void OnInitializePotentialDrag(PointerEventData eventData)
|
public virtual void OnInitializePotentialDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
eventData.useDragThreshold = false;
|
eventData.useDragThreshold = false;
|
||||||
|
|
|
@ -14,10 +14,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
isVertical = false;
|
isVertical = false;
|
||||||
|
childAnchorPoint = new Vector2(0, 0.5f);
|
||||||
DistributePages();
|
DistributePages();
|
||||||
if(MaskArea) CalculateVisible();
|
if(MaskArea) CalculateVisible();
|
||||||
_lerp = false;
|
_lerp = false;
|
||||||
_currentPage = StartingScreen - 1;
|
_currentPage = StartingScreen;
|
||||||
SetScrollContainerPosition();
|
SetScrollContainerPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +52,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//used for changing between screen resolutions
|
|
||||||
private void DistributePages()
|
private void DistributePages()
|
||||||
{
|
{
|
||||||
_screens = _screensContainer.childCount;
|
_screens = _screensContainer.childCount;
|
||||||
|
_scroll_rect.horizontalNormalizedPosition = 0;
|
||||||
|
|
||||||
int _offset = 0;
|
int _offset = 0;
|
||||||
float _dimension = 0;
|
float _dimension = 0;
|
||||||
|
@ -69,9 +70,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
currentXPosition = _offset + (int)(i * pageStepValue);
|
currentXPosition = _offset + (int)(i * pageStepValue);
|
||||||
child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height);
|
child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height);
|
||||||
child.anchoredPosition = new Vector2(currentXPosition, 0f);
|
child.anchoredPosition = new Vector2(currentXPosition, 0f);
|
||||||
child.anchorMin = new Vector2(0f, child.anchorMin.y);
|
child.anchorMin = child.anchorMax = child.pivot = childAnchorPoint;
|
||||||
child.anchorMax = new Vector2(0f, child.anchorMax.y);
|
|
||||||
child.pivot = new Vector2(0f, child.pivot.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dimension = currentXPosition + _offset * -1;
|
_dimension = currentXPosition + _offset * -1;
|
||||||
|
@ -129,6 +128,16 @@ namespace UnityEngine.UI.Extensions
|
||||||
_scroll_rect.horizontalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
_scroll_rect.horizontalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// used for changing / updating between screen resolutions
|
||||||
|
/// </summary>
|
||||||
|
public void UpdateLayout()
|
||||||
|
{
|
||||||
|
_lerp = false;
|
||||||
|
DistributePages();
|
||||||
|
SetScrollContainerPosition();
|
||||||
|
}
|
||||||
|
|
||||||
#region Interfaces
|
#region Interfaces
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Release screen to swipe
|
/// Release screen to swipe
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
internal float _scrollStartPosition;
|
internal float _scrollStartPosition;
|
||||||
internal float _childSize;
|
internal float _childSize;
|
||||||
private float _childPos;
|
private float _childPos;
|
||||||
|
internal Vector2 childAnchorPoint;
|
||||||
internal ScrollRect _scroll_rect;
|
internal ScrollRect _scroll_rect;
|
||||||
internal Vector3 _lerp_target;
|
internal Vector3 _lerp_target;
|
||||||
internal bool _lerp;
|
internal bool _lerp;
|
||||||
|
@ -22,7 +23,8 @@ namespace UnityEngine.UI.Extensions
|
||||||
[Tooltip("The currently active page")]
|
[Tooltip("The currently active page")]
|
||||||
internal int _currentPage;
|
internal int _currentPage;
|
||||||
internal int _previousPage;
|
internal int _previousPage;
|
||||||
|
internal int HalfNoVisibleItems;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class SelectionChangeStartEvent : UnityEvent { }
|
public class SelectionChangeStartEvent : UnityEvent { }
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
@ -30,38 +32,42 @@ namespace UnityEngine.UI.Extensions
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class SelectionChangeEndEvent : UnityEvent { }
|
public class SelectionChangeEndEvent : UnityEvent { }
|
||||||
|
|
||||||
[Tooltip("The visible bounds area, controls which items are visible/enabled. *Note Should use a RectMask. (optional)")]
|
[Tooltip("The screen / page to start the control on\n*Note, this is a 0 indexed array")]
|
||||||
public RectTransform MaskArea;
|
|
||||||
[Tooltip("Pixel size to buffer arround Mask Area. (optional)")]
|
|
||||||
public float MaskBuffer = 1;
|
|
||||||
public int HalfNoVisibleItems;
|
|
||||||
|
|
||||||
[Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")]
|
|
||||||
public GameObject Pagination;
|
|
||||||
|
|
||||||
[Tooltip("Button to go to the next page. (optional)")]
|
|
||||||
public GameObject NextButton;
|
|
||||||
[Tooltip("Button to go to the previous page. (optional)")]
|
|
||||||
public GameObject PrevButton;
|
|
||||||
[Tooltip("Transition speed between pages. (optional)")]
|
|
||||||
public float transitionSpeed = 7.5f;
|
|
||||||
|
|
||||||
[Tooltip("Fast Swipe makes swiping page next / previous (optional)")]
|
|
||||||
public Boolean UseFastSwipe = false;
|
|
||||||
[Tooltip("How far swipe has to travel to initiate a page change (optional)")]
|
|
||||||
public int FastSwipeThreshold = 100;
|
|
||||||
[Tooltip("Speed at which the ScrollRect will keep scrolling before slowing down and stopping (optional)")]
|
|
||||||
public int SwipeVelocityThreshold = 200;
|
|
||||||
|
|
||||||
[Tooltip("The screen / page to start the control on")]
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
public int StartingScreen = 1;
|
public int StartingScreen = 0;
|
||||||
|
|
||||||
[Tooltip("The distance between two pages based on page height, by default pages are next to each other")]
|
[Tooltip("The distance between two pages based on page height, by default pages are next to each other")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Range(1, 8)]
|
[Range(1, 8)]
|
||||||
public float PageStep = 1;
|
public float PageStep = 1;
|
||||||
|
|
||||||
|
[Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")]
|
||||||
|
public GameObject Pagination;
|
||||||
|
|
||||||
|
[Tooltip("Button to go to the next page. (optional)")]
|
||||||
|
public GameObject NextButton;
|
||||||
|
|
||||||
|
[Tooltip("Button to go to the previous page. (optional)")]
|
||||||
|
public GameObject PrevButton;
|
||||||
|
|
||||||
|
[Tooltip("Transition speed between pages. (optional)")]
|
||||||
|
public float transitionSpeed = 7.5f;
|
||||||
|
|
||||||
|
[Tooltip("Fast Swipe makes swiping page next / previous (optional)")]
|
||||||
|
public Boolean UseFastSwipe = false;
|
||||||
|
|
||||||
|
[Tooltip("How far swipe has to travel to initiate a page change (optional)")]
|
||||||
|
public int FastSwipeThreshold = 100;
|
||||||
|
|
||||||
|
[Tooltip("Speed at which the ScrollRect will keep scrolling before slowing down and stopping (optional)")]
|
||||||
|
public int SwipeVelocityThreshold = 200;
|
||||||
|
|
||||||
|
[Tooltip("The visible bounds area, controls which items are visible/enabled. *Note Should use a RectMask. (optional)")]
|
||||||
|
public RectTransform MaskArea;
|
||||||
|
|
||||||
|
[Tooltip("Pixel size to buffer arround Mask Area. (optional)")]
|
||||||
|
public float MaskBuffer = 1;
|
||||||
|
|
||||||
public int CurrentPage
|
public int CurrentPage
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -80,6 +86,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Tooltip("Scroll Snap children. (optional)\nEither place objects in the scene as children OR\nPrefabs in this array, NOT BOTH")]
|
||||||
|
public GameObject[] ChildObjects;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private SelectionChangeStartEvent m_OnSelectionChangeStartEvent = new SelectionChangeStartEvent();
|
private SelectionChangeStartEvent m_OnSelectionChangeStartEvent = new SelectionChangeStartEvent();
|
||||||
public SelectionChangeStartEvent OnSelectionChangeStartEvent { get { return m_OnSelectionChangeStartEvent; } set { m_OnSelectionChangeStartEvent = value; } }
|
public SelectionChangeStartEvent OnSelectionChangeStartEvent { get { return m_OnSelectionChangeStartEvent; } set { m_OnSelectionChangeStartEvent = value; } }
|
||||||
|
@ -92,7 +101,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
private SelectionChangeEndEvent m_OnSelectionChangeEndEvent = new SelectionChangeEndEvent();
|
private SelectionChangeEndEvent m_OnSelectionChangeEndEvent = new SelectionChangeEndEvent();
|
||||||
public SelectionChangeEndEvent OnSelectionChangeEndEvent { get { return m_OnSelectionChangeEndEvent; } set { m_OnSelectionChangeEndEvent = value; } }
|
public SelectionChangeEndEvent OnSelectionChangeEndEvent { get { return m_OnSelectionChangeEndEvent; } set { m_OnSelectionChangeEndEvent = value; } }
|
||||||
|
|
||||||
public GameObject[] ChildObjects;
|
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Awake()
|
void Awake()
|
||||||
|
@ -104,6 +112,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
Debug.LogWarning("Warning, using scrollbars with the Scroll Snap controls is not advised as it causes unpredictable results");
|
Debug.LogWarning("Warning, using scrollbars with the Scroll Snap controls is not advised as it causes unpredictable results");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StartingScreen < 0)
|
||||||
|
{
|
||||||
|
StartingScreen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
_screensContainer = _scroll_rect.content;
|
_screensContainer = _scroll_rect.content;
|
||||||
if (ChildObjects != null && ChildObjects.Length > 0)
|
if (ChildObjects != null && ChildObjects.Length > 0)
|
||||||
{
|
{
|
||||||
|
@ -168,6 +181,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
internal void UpdateVisible()
|
internal void UpdateVisible()
|
||||||
{
|
{
|
||||||
|
//If there are no objects in the scene, exit
|
||||||
|
if (ChildObjects == null || ChildObjects.Length < 1 || _screensContainer.childCount < 1) return;
|
||||||
|
|
||||||
int BottomItem = _currentPage - HalfNoVisibleItems < 0 ? 0 : HalfNoVisibleItems;
|
int BottomItem = _currentPage - HalfNoVisibleItems < 0 ? 0 : HalfNoVisibleItems;
|
||||||
int TopItem = _screensContainer.childCount - _currentPage < HalfNoVisibleItems ? _screensContainer.childCount - _currentPage : HalfNoVisibleItems;
|
int TopItem = _screensContainer.childCount - _currentPage < HalfNoVisibleItems ? _screensContainer.childCount - _currentPage : HalfNoVisibleItems;
|
||||||
|
|
||||||
|
@ -267,14 +283,21 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
private void OnValidate()
|
private void OnValidate()
|
||||||
{
|
{
|
||||||
var childCount = ChildObjects == null ? _screensContainer.childCount : ChildObjects.Length;
|
if (_screensContainer || ChildObjects != null)
|
||||||
if (StartingScreen > childCount - 1)
|
|
||||||
{
|
{
|
||||||
StartingScreen = childCount - 1;
|
var childCount = ChildObjects == null ? _screensContainer.childCount : ChildObjects.Length;
|
||||||
|
if (StartingScreen > childCount - 1)
|
||||||
|
{
|
||||||
|
StartingScreen = childCount - 1;
|
||||||
|
}
|
||||||
|
if (StartingScreen < 0)
|
||||||
|
{
|
||||||
|
StartingScreen = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (StartingScreen < 0)
|
if (MaskBuffer <= 0)
|
||||||
{
|
{
|
||||||
StartingScreen = 0;
|
MaskBuffer = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
isVertical = true;
|
isVertical = true;
|
||||||
|
childAnchorPoint = new Vector2(0.5f,0);
|
||||||
DistributePages();
|
DistributePages();
|
||||||
if(MaskArea) CalculateVisible();
|
if(MaskArea) CalculateVisible();
|
||||||
_lerp = false;
|
_lerp = false;
|
||||||
_currentPage = StartingScreen - 1;
|
_currentPage = StartingScreen;
|
||||||
SetScrollContainerPosition();
|
SetScrollContainerPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +53,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//used for changing between screen resolutions
|
|
||||||
public void DistributePages()
|
public void DistributePages()
|
||||||
{
|
{
|
||||||
_screens = _screensContainer.childCount;
|
_screens = _screensContainer.childCount;
|
||||||
|
_scroll_rect.verticalNormalizedPosition = 0;
|
||||||
|
|
||||||
float _offset = 0;
|
float _offset = 0;
|
||||||
float _dimension = 0;
|
float _dimension = 0;
|
||||||
|
@ -69,9 +70,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
currentYPosition = _offset + i * pageStepValue;
|
currentYPosition = _offset + i * pageStepValue;
|
||||||
child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height);
|
child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height);
|
||||||
child.anchoredPosition = new Vector2(0f, currentYPosition);
|
child.anchoredPosition = new Vector2(0f, currentYPosition);
|
||||||
child.anchorMin = new Vector2(child.anchorMin.x, 0f);
|
child.anchorMin = child.anchorMax = child.pivot = childAnchorPoint;
|
||||||
child.anchorMax = new Vector2(child.anchorMax.x, 0f);
|
|
||||||
child.pivot = new Vector2(child.pivot.x, 0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dimension = currentYPosition + _offset * -1;
|
_dimension = currentYPosition + _offset * -1;
|
||||||
|
@ -130,6 +129,15 @@ namespace UnityEngine.UI.Extensions
|
||||||
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// used for changing / updating between screen resolutions
|
||||||
|
/// </summary>
|
||||||
|
public void UpdateLayout()
|
||||||
|
{
|
||||||
|
_lerp = false;
|
||||||
|
DistributePages();
|
||||||
|
SetScrollContainerPosition();
|
||||||
|
}
|
||||||
#region Interfaces
|
#region Interfaces
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Release screen to swipe
|
/// Release screen to swipe
|
||||||
|
|
|
@ -130,7 +130,7 @@ namespace UnityEngine.UI
|
||||||
protected override void OnDidApplyAnimationProperties()
|
protected override void OnDidApplyAnimationProperties()
|
||||||
{
|
{
|
||||||
// Check if isOn has been changed by the animation.
|
// Check if isOn has been changed by the animation.
|
||||||
// Unfortunately there is no way to check if we don�t have a graphic.
|
// Unfortunately there is no way to check if we don't have a graphic.
|
||||||
if (graphic != null)
|
if (graphic != null)
|
||||||
{
|
{
|
||||||
bool oldValue = !Mathf.Approximately(graphic.canvasRenderer.GetColor().a, 0);
|
bool oldValue = !Mathf.Approximately(graphic.canvasRenderer.GetColor().a, 0);
|
||||||
|
@ -194,7 +194,7 @@ namespace UnityEngine.UI
|
||||||
m_IsOn = value;
|
m_IsOn = value;
|
||||||
if (m_Group != null && IsActive())
|
if (m_Group != null && IsActive())
|
||||||
{
|
{
|
||||||
if (m_IsOn || (!m_Group.AnyTogglesOn() && !m_Group.allowSwitchOff))
|
if (m_IsOn || (!m_Group.AnyTogglesOn() && !m_Group.AllowSwitchOff))
|
||||||
{
|
{
|
||||||
m_IsOn = true;
|
m_IsOn = true;
|
||||||
m_Group.NotifyToggleOn(this);
|
m_Group.NotifyToggleOn(this);
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private bool m_AllowSwitchOff = false;
|
private bool m_AllowSwitchOff = false;
|
||||||
public bool allowSwitchOff { get { return m_AllowSwitchOff; } set { m_AllowSwitchOff = value; } }
|
public bool AllowSwitchOff { get { return m_AllowSwitchOff; } set { m_AllowSwitchOff = value; } }
|
||||||
|
|
||||||
private List<ExtensionsToggle> m_Toggles = new List<ExtensionsToggle>();
|
private List<ExtensionsToggle> m_Toggles = new List<ExtensionsToggle>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue