Minor VSS/HSS bugfixes and enhancements, resolving #114

pull/413/head
Simon Jackson 2017-03-12 15:18:36 +00:00
parent ec31c8b5d6
commit f89702ddc6
3 changed files with 72 additions and 41 deletions

View File

@ -37,6 +37,7 @@ namespace UnityEngine.UI.Extensions
_screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * Time.deltaTime); _screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * Time.deltaTime);
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.1f) if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.1f)
{ {
_screensContainer.localPosition = _lerp_target;
_lerp = false; _lerp = false;
EndScreenChange(); EndScreenChange();
} }
@ -192,6 +193,16 @@ namespace UnityEngine.UI.Extensions
} }
} }
private void OnEnable()
{
InitialiseChildObjects();
DistributePages();
if (MaskArea) UpdateVisible();
if(JumpOnEnable) SetScrollContainerPosition();
GoToScreen(StartingScreen);
}
#region Interfaces #region Interfaces
/// <summary> /// <summary>
/// Release screen to swipe /// Release screen to swipe

View File

@ -90,6 +90,9 @@ namespace UnityEngine.UI.Extensions
} }
} }
[Tooltip("By default the container will lerp to the start when enabled in the scene, this option overrides this and forces it to simply jump without lerping")]
public bool JumpOnEnable = false;
[Tooltip("(Experimental)\nBy default, child array objects will use the parent transform\nHowever you can disable this for some interesting effects")] [Tooltip("(Experimental)\nBy default, child array objects will use the parent transform\nHowever you can disable this for some interesting effects")]
public bool UseParentTransform = true; public bool UseParentTransform = true;
@ -127,6 +130,18 @@ namespace UnityEngine.UI.Extensions
} }
_screensContainer = _scroll_rect.content; _screensContainer = _scroll_rect.content;
InitialiseChildObjects();
if (NextButton)
NextButton.GetComponent<Button>().onClick.AddListener(() => { NextScreen(); });
if (PrevButton)
PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); });
}
internal void InitialiseChildObjects()
{
if (ChildObjects != null && ChildObjects.Length > 0) if (ChildObjects != null && ChildObjects.Length > 0)
{ {
if (_screensContainer.transform.childCount > 0) if (_screensContainer.transform.childCount > 0)
@ -141,12 +156,6 @@ namespace UnityEngine.UI.Extensions
{ {
InitialiseChildObjectsFromScene(); InitialiseChildObjectsFromScene();
} }
if (NextButton)
NextButton.GetComponent<Button>().onClick.AddListener(() => { NextScreen(); });
if (PrevButton)
PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); });
} }
internal void InitialiseChildObjectsFromScene() internal void InitialiseChildObjectsFromScene()

View File

@ -37,6 +37,7 @@ namespace UnityEngine.UI.Extensions
_screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * Time.deltaTime); _screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, transitionSpeed * Time.deltaTime);
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.1f) if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.1f)
{ {
_screensContainer.localPosition = _lerp_target;
_lerp = false; _lerp = false;
EndScreenChange(); EndScreenChange();
} }
@ -192,6 +193,16 @@ namespace UnityEngine.UI.Extensions
} }
} }
private void OnEnable()
{
InitialiseChildObjects();
DistributePages();
if (MaskArea) UpdateVisible();
if (JumpOnEnable) SetScrollContainerPosition();
GoToScreen(StartingScreen);
}
#region Interfaces #region Interfaces
/// <summary> /// <summary>
/// Release screen to swipe /// Release screen to swipe