This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Attaching this script to an element of a scroll view will make it possible to center on it by clicking on it.
/// </summary>
[AddComponentMenu("NGUI/Interaction/Center Scroll View on Click")]
public class UICenterOnClick : MonoBehaviour
{
void OnClick ()
{
UICenterOnChild center = NGUITools.FindInParents<UICenterOnChild>(gameObject);
UIPanel panel = NGUITools.FindInParents<UIPanel>(gameObject);
if (center != null)
{
if (center.enabled)
center.CenterOn(transform);
}
else if (panel != null && panel.clipping != UIDrawCall.Clipping.None)
{
UIScrollView sv = panel.GetComponent<UIScrollView>();
Vector3 offset = -panel.cachedTransform.InverseTransformPoint(transform.position);
if (!sv.canMoveHorizontally) offset.x = panel.cachedTransform.localPosition.x;
if (!sv.canMoveVertically) offset.y = panel.cachedTransform.localPosition.y;
SpringPanel.Begin(panel.cachedGameObject, offset, 6f);
}
}
}