public void RestrictWithinBounds(bool instant, Bounds b) { Vector3 constraint = mPanel.CalculateConstrainOffset(b.min, b.max); if (constraint.magnitude > 0.005f) { if (!instant && dragEffect == DragEffect.MomentumAndSpring) { // Spring back into place constraint.Scale(scale); PagingSpringPanel.Begin(mPanel.gameObject, constraint, 13f); } else { // Jump back into place MoveRelative(constraint); } mMomentum = Vector3.zero; mScroll = 0f; } else { // Remove the spring as it's no longer needed DisableSpring(); } }
/// <summary> /// Disable spring panel /// </summary> void DisableSpring() { PagingSpringPanel sp = GetComponent <PagingSpringPanel>(); if (sp != null) { sp.enabled = false; } }
/// <summary> /// Start the tweening process. /// </summary> static public PagingSpringPanel Begin(GameObject go, Vector3 pos, float strength) { PagingSpringPanel sp = go.GetComponent <PagingSpringPanel>(); if (sp == null) { sp = go.AddComponent <PagingSpringPanel>(); } sp.target = pos; sp.strength = strength; sp.mLastPos = Vector3.zero; sp.mThreshold = 0.5f; if (!sp.enabled) { sp.enabled = true; } return(sp); }