Reapplying fixes after having to do a reset, whoops

pull/413/head
Simon (Darkside) Jackson 2018-05-31 16:55:39 +01:00
parent 4e6f14118f
commit d3fc02c475
2 changed files with 39 additions and 31 deletions

View File

@ -51,15 +51,11 @@ namespace UnityEngine.UI.Extensions
private Vector2 _currentVector; private Vector2 _currentVector;
private Quaternion _initRotation; private Quaternion _initRotation;
private bool _canDrag = false; private bool _canDrag = false;
[SerializeField] private bool _screenSpaceOverlay;
private bool experimental = false;
private RectTransform m_HandleRect;
protected override void Awake() protected override void Awake()
{ {
m_HandleRect = GetComponent<RectTransform>(); _screenSpaceOverlay = GetComponentInParent<Canvas>().rootCanvas.renderMode == RenderMode.ScreenSpaceOverlay;
} }
public override void OnPointerUp(PointerEventData eventData) public override void OnPointerUp(PointerEventData eventData)
@ -83,13 +79,13 @@ namespace UnityEngine.UI.Extensions
base.OnPointerDown(eventData); base.OnPointerDown(eventData);
_initRotation = transform.rotation; _initRotation = transform.rotation;
if (experimental) if (_screenSpaceOverlay)
{ {
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out _currentVector); _currentVector = eventData.position - (Vector2)transform.position;
} }
else else
{ {
_currentVector = eventData.position - (Vector2)transform.position; _currentVector = eventData.position - (Vector2)Camera.main.WorldToScreenPoint(transform.position);
} }
_initAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg; _initAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
} }
@ -102,14 +98,14 @@ namespace UnityEngine.UI.Extensions
return; return;
} }
if (experimental) if (_screenSpaceOverlay)
{ {
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out _currentVector); _currentVector = eventData.position - (Vector2)transform.position;
} }
else else
{ {
_currentVector = eventData.position - (Vector2)transform.position; _currentVector = eventData.position - (Vector2)Camera.main.WorldToScreenPoint(transform.position);
} }
_currentAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg; _currentAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
Quaternion addRotation = Quaternion.AngleAxis(_currentAngle - _initAngle, this.transform.forward); Quaternion addRotation = Quaternion.AngleAxis(_currentAngle - _initAngle, this.transform.forward);

View File

@ -94,11 +94,19 @@ namespace UnityEngine.UI.Extensions
if (_isInfinate) if (_isInfinate)
{ {
//Work out which infinite window we are in //Work out which infinite window we are in
_infiniteWindow = value / _screensContainer.childCount; float infWindow = (float)value / (float)_screensContainer.childCount;
if (infWindow < 0)
{
_infiniteWindow = (int)(Math.Floor(infWindow));
}
else
{
_infiniteWindow = value / _screensContainer.childCount;
}
//Invert the value if negative and differentiate from Window 0 //Invert the value if negative and differentiate from Window 0
_infiniteWindow = value < 0 ? (-_infiniteWindow) + 1 : _infiniteWindow; _infiniteWindow = value < 0 ? (-_infiniteWindow) : _infiniteWindow;
//Multiplying values by zero doesn't help, so start at Window 1
//_infiniteWindow += 1;
//Calculate the page within the child count range //Calculate the page within the child count range
value = value % _screensContainer.childCount; value = value % _screensContainer.childCount;
if (value < 0) if (value < 0)
@ -369,6 +377,7 @@ namespace UnityEngine.UI.Extensions
if (_isVertical) if (_isVertical)
{ {
_infiniteOffset = _screensContainer.localPosition.y < 0 ? -_screensContainer.sizeDelta.y * _infiniteWindow : _screensContainer.sizeDelta.y * _infiniteWindow; _infiniteOffset = _screensContainer.localPosition.y < 0 ? -_screensContainer.sizeDelta.y * _infiniteWindow : _screensContainer.sizeDelta.y * _infiniteWindow;
_infiniteOffset = _infiniteOffset == 0 ? 0 : _infiniteOffset < 0 ? _infiniteOffset - _childSize * _infiniteWindow : _infiniteOffset + _childSize * _infiniteWindow;
target.y = _childPos + _scrollStartPosition + _infiniteOffset; target.y = _childPos + _scrollStartPosition + _infiniteOffset;
} }
else else
@ -449,19 +458,22 @@ namespace UnityEngine.UI.Extensions
{ {
Debug.LogError("ScrollRect has to be unidirectional, only use either Horizontal or Vertical on the ScrollRect, NOT both."); Debug.LogError("ScrollRect has to be unidirectional, only use either Horizontal or Vertical on the ScrollRect, NOT both.");
} }
var ScrollRectContent = gameObject.GetComponent<ScrollRect>().content;
var children = gameObject.GetComponent<ScrollRect>().content.childCount; if (ScrollRectContent != null)
if (children != 0 || ChildObjects != null)
{ {
var childCount = ChildObjects == null || ChildObjects.Length == 0 ? children : ChildObjects.Length; var children = ScrollRectContent.childCount;
if (StartingScreen > childCount - 1) if (children != 0 || ChildObjects != null)
{ {
StartingScreen = childCount - 1; var childCount = ChildObjects == null || ChildObjects.Length == 0 ? children : ChildObjects.Length;
} if (StartingScreen > childCount - 1)
{
StartingScreen = childCount - 1;
}
if (StartingScreen < 0) if (StartingScreen < 0)
{ {
StartingScreen = 0; StartingScreen = 0;
}
} }
} }