Skip to content

Instantly share code, notes, and snippets.

@kimsama
Last active February 4, 2016 03:14
Show Gist options
  • Select an option

  • Save kimsama/109f481552375a9f20c1 to your computer and use it in GitHub Desktop.

Select an option

Save kimsama/109f481552375a9f20c1 to your computer and use it in GitHub Desktop.
Various NGUI and its EventTrigger usage on script side.
// with tweening animation...
TweenAlpha transition = TweenAlpha.Begin(FadeOut.gameObject, this.fadeInTime, duration);
transition.from = 0f;
transition.ResetToBeginning();
EventDelegate.Add(transition.onFinished, OnFinished, true);
void OnFinished()
{
// called at the end of alpha tweening animation.
}
// A simple dragging.
// add or retrieve UIEventTrigger
UIEventTrigger eventTrigger = gameObject.GetComponent<UIEventTrigger>();
eventTrigger.onDragEnd.Add(new EventDelegate(OnDragEnd));
...
void OnDragEnd()
{
// get delta distances with the dragging.
float delta = UICamera.currentTouch.totalDelta.x;
// ignore the dragging less than 10
if (Mathf.Abs(delta) < 10f)
return;
// do something
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment