Updated with transtions and allowing to change children pivots
parent
204bc7bdd1
commit
6e1f1afca5
|
@ -17,7 +17,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
internal float _scrollStartPosition;
|
internal float _scrollStartPosition;
|
||||||
internal float _childSize;
|
internal float _childSize;
|
||||||
private float _childPos, _maskSize;
|
private float _childPos, _maskSize;
|
||||||
internal Vector2 _childAnchorPoint;
|
[SerializeField] internal Vector2 _childAnchorPoint = new Vector2(0.5f, 0);
|
||||||
internal ScrollRect _scroll_rect;
|
internal ScrollRect _scroll_rect;
|
||||||
internal Vector3 _lerp_target;
|
internal Vector3 _lerp_target;
|
||||||
internal bool _lerp;
|
internal bool _lerp;
|
||||||
|
@ -256,6 +256,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
childRect.rotation = _screensContainer.rotation;
|
childRect.rotation = _screensContainer.rotation;
|
||||||
childRect.localScale = _screensContainer.localScale;
|
childRect.localScale = _screensContainer.localScale;
|
||||||
childRect.position = _screensContainer.position;
|
childRect.position = _screensContainer.position;
|
||||||
|
child.GetComponent<Button>().onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
ChangePage(i);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
child.transform.SetParent(_screensContainer.transform);
|
child.transform.SetParent(_screensContainer.transform);
|
||||||
|
@ -648,10 +653,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Transition Effects
|
#region Transition Effects
|
||||||
|
private Vector2 GetDisplacementFromCenter(Transform _child)
|
||||||
private Vector2 GetDisplacementFromCenter(int index)
|
|
||||||
{
|
{
|
||||||
return _screensContainer.GetChild(index).GetComponent<Transform>().position - _scroll_rect.viewport.transform.position;
|
return _child.position - _scroll_rect.viewport.transform.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleTransitionEffects()
|
private void HandleTransitionEffects()
|
||||||
|
@ -660,9 +664,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
for (int i = 0; i < _screensContainer.childCount; i++)
|
for (int i = 0; i < _screensContainer.childCount; i++)
|
||||||
{
|
{
|
||||||
Vector2 displacement = GetDisplacementFromCenter(i);
|
Transform _child = _screensContainer.GetChild(i);
|
||||||
|
Vector2 displacement = GetDisplacementFromCenter(_child);
|
||||||
float d = (_scroll_rect.horizontal ? displacement.x : displacement.y);
|
float d = (_scroll_rect.horizontal ? displacement.x : displacement.y);
|
||||||
onTransitionEffects.Invoke(_screensContainer.GetChild(i).gameObject, d);
|
onTransitionEffects.Invoke(_child.gameObject, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,14 @@ namespace UnityEngine.UI.Extensions
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
_isVertical = true;
|
_isVertical = true;
|
||||||
_childAnchorPoint = new Vector2(0.5f,0);
|
|
||||||
_currentPage = StartingScreen;
|
_currentPage = StartingScreen;
|
||||||
panelDimensions = gameObject.GetComponent<RectTransform>().rect;
|
panelDimensions = gameObject.GetComponent<RectTransform>().rect;
|
||||||
UpdateLayout();
|
UpdateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
|
base.Update();
|
||||||
updated = false;
|
updated = false;
|
||||||
|
|
||||||
if (!_lerp && _scroll_rect.velocity == Vector2.zero)
|
if (!_lerp && _scroll_rect.velocity == Vector2.zero)
|
||||||
|
@ -89,8 +89,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent<RectTransform>();
|
RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent<RectTransform>();
|
||||||
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.anchorMin = child.anchorMax = child.pivot = _childAnchorPoint;
|
child.anchorMin = child.anchorMax = child.pivot = _childAnchorPoint;
|
||||||
|
child.anchoredPosition = new Vector2(0f, currentYPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
_dimension = currentYPosition + _offset * -1;
|
_dimension = currentYPosition + _offset * -1;
|
||||||
|
|
Loading…
Reference in New Issue