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,33 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Makes it possible to animate alpha of the widget or a panel.
/// </summary>
[ExecuteInEditMode]
public class AnimatedAlpha : MonoBehaviour
{
[Range(0f, 1f)]
public float alpha = 1f;
UIWidget mWidget;
UIPanel mPanel;
void OnEnable ()
{
mWidget = GetComponent<UIWidget>();
mPanel = GetComponent<UIPanel>();
LateUpdate();
}
void LateUpdate ()
{
if (mWidget != null) mWidget.alpha = alpha;
if (mPanel != null) mPanel.alpha = alpha;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6f9aef6d5962d8849aa830ef46c7c993
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,22 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Makes it possible to animate a color of the widget.
/// </summary>
[ExecuteInEditMode]
[RequireComponent(typeof(UIWidget))]
public class AnimatedColor : MonoBehaviour
{
public Color color = Color.white;
UIWidget mWidget;
void OnEnable () { mWidget = GetComponent<UIWidget>(); LateUpdate(); }
void LateUpdate () { mWidget.color = color; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d2278f9af1633ae43a759ad6cdb74608
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,34 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Makes it possible to animate the widget's width and height using Unity's animations.
/// </summary>
[ExecuteInEditMode]
public class AnimatedWidget : MonoBehaviour
{
public float width = 1f;
public float height = 1f;
UIWidget mWidget;
void OnEnable ()
{
mWidget = GetComponent<UIWidget>();
LateUpdate();
}
void LateUpdate ()
{
if (mWidget != null)
{
mWidget.width = Mathf.RoundToInt(width);
mWidget.height = Mathf.RoundToInt(height);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 27adfee35dd94cb4a8d0cd2ed7d934be
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,146 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
using System.Collections.Generic;
/// <summary>
/// Spring-like motion -- the farther away the object is from the target, the stronger the pull.
/// </summary>
[AddComponentMenu("NGUI/Tween/Spring Position")]
public class SpringPosition : MonoBehaviour
{
static public SpringPosition current;
/// <summary>
/// Target position to tween to.
/// </summary>
public Vector3 target = Vector3.zero;
/// <summary>
/// Strength of the spring. The higher the value, the faster the movement.
/// </summary>
public float strength = 10f;
/// <summary>
/// Is the calculation done in world space or local space?
/// </summary>
public bool worldSpace = false;
/// <summary>
/// Whether the time scale will be ignored. Generally UI components should set it to 'true'.
/// </summary>
public bool ignoreTimeScale = false;
/// <summary>
/// Whether the parent scroll view will be updated as the object moves.
/// </summary>
public bool updateScrollView = false;
public delegate void OnFinished ();
/// <summary>
/// Delegate to trigger when the spring finishes.
/// </summary>
public OnFinished onFinished;
// Deprecated functionality
[SerializeField][HideInInspector] GameObject eventReceiver = null;
[SerializeField][HideInInspector] public string callWhenFinished;
Transform mTrans;
float mThreshold = 0f;
UIScrollView mSv;
/// <summary>
/// Cache the transform.
/// </summary>
void Start ()
{
mTrans = transform;
if (updateScrollView) mSv = NGUITools.FindInParents<UIScrollView>(gameObject);
}
/// <summary>
/// Advance toward the target position.
/// </summary>
void Update ()
{
float delta = ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime;
if (worldSpace)
{
if (mThreshold == 0f) mThreshold = (target - mTrans.position).sqrMagnitude * 0.001f;
mTrans.position = NGUIMath.SpringLerp(mTrans.position, target, strength, delta);
if (mThreshold >= (target - mTrans.position).sqrMagnitude)
{
mTrans.position = target;
NotifyListeners();
enabled = false;
}
}
else
{
if (mThreshold == 0f) mThreshold = (target - mTrans.localPosition).sqrMagnitude * 0.00001f;
mTrans.localPosition = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, delta);
if (mThreshold >= (target - mTrans.localPosition).sqrMagnitude)
{
mTrans.localPosition = target;
NotifyListeners();
enabled = false;
}
}
// Ensure that the scroll bars remain in sync
if (mSv != null) mSv.UpdateScrollbars(true);
}
/// <summary>
/// Notify all finished event listeners.
/// </summary>
void NotifyListeners ()
{
current = this;
if (onFinished != null) onFinished();
if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
current = null;
}
/// <summary>
/// Start the tweening process.
/// </summary>
static public SpringPosition Begin (GameObject go, Vector3 pos, float strength)
{
SpringPosition sp = go.GetComponent<SpringPosition>();
if (sp == null) sp = go.AddComponent<SpringPosition>();
sp.target = pos;
sp.strength = strength;
sp.onFinished = null;
if (!sp.enabled)
{
sp.mThreshold = 0f;
sp.enabled = true;
}
return sp;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9b07b9d136934c04b965f9adb7054484
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,102 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the object's alpha. Works with both UI widgets as well as renderers.
/// </summary>
[AddComponentMenu("NGUI/Tween/Tween Alpha")]
public class TweenAlpha : UITweener
{
[Range(0f, 1f)] public float from = 1f;
[Range(0f, 1f)] public float to = 1f;
bool mCached = false;
UIRect mRect;
Material mMat;
SpriteRenderer mSr;
[System.Obsolete("Use 'value' instead")]
public float alpha { get { return this.value; } set { this.value = value; } }
void Cache ()
{
mCached = true;
mRect = GetComponent<UIRect>();
mSr = GetComponent<SpriteRenderer>();
if (mRect == null && mSr == null)
{
Renderer ren = GetComponent<Renderer>();
if (ren != null) mMat = ren.sharedMaterial;
if (mMat == null) mRect = GetComponentInChildren<UIRect>();
}
}
/// <summary>
/// Tween's current value.
/// </summary>
public float value
{
get
{
if (!mCached) Cache();
if (mRect != null) return mRect.alpha;
if (mSr != null) return mSr.color.a;
return mMat != null ? mMat.color.a : 1f;
}
set
{
if (!mCached) Cache();
if (mRect != null)
{
mRect.alpha = value;
}
else if (mSr != null)
{
Color c = mSr.color;
c.a = value;
mSr.color = c;
}
else if (mMat != null)
{
Color c = mMat.color;
c.a = value;
mMat.color = c;
}
}
}
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished) { value = Mathf.Lerp(from, to, factor); }
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenAlpha Begin (GameObject go, float duration, float alpha)
{
TweenAlpha comp = UITweener.Begin<TweenAlpha>(go, duration);
comp.from = comp.value;
comp.to = alpha;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
public override void SetStartToCurrentValue () { from = value; }
public override void SetEndToCurrentValue () { to = value; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9e2747e3775af504da1a4d5a46c5a1ce
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,122 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the object's color.
/// </summary>
[AddComponentMenu("NGUI/Tween/Tween Color")]
public class TweenColor : UITweener
{
public Color from = Color.white;
public Color to = Color.white;
bool mCached = false;
UIWidget mWidget;
Material mMat;
Light mLight;
SpriteRenderer mSr;
void Cache ()
{
mCached = true;
mWidget = GetComponent<UIWidget>();
if (mWidget != null) return;
mSr = GetComponent<SpriteRenderer>();
if (mSr != null) return;
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
Renderer ren = renderer;
#else
Renderer ren = GetComponent<Renderer>();
#endif
if (ren != null)
{
mMat = ren.material;
return;
}
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
mLight = light;
#else
mLight = GetComponent<Light>();
#endif
if (mLight == null) mWidget = GetComponentInChildren<UIWidget>();
}
[System.Obsolete("Use 'value' instead")]
public Color color { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween's current value.
/// </summary>
public Color value
{
get
{
if (!mCached) Cache();
if (mWidget != null) return mWidget.color;
if (mMat != null) return mMat.color;
if (mSr != null) return mSr.color;
if (mLight != null) return mLight.color;
return Color.black;
}
set
{
if (!mCached) Cache();
if (mWidget != null) mWidget.color = value;
else if (mMat != null) mMat.color = value;
else if (mSr != null) mSr.color = value;
else if (mLight != null)
{
mLight.color = value;
mLight.enabled = (value.r + value.g + value.b) > 0.01f;
}
}
}
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished) { value = Color.Lerp(from, to, factor); }
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenColor Begin (GameObject go, float duration, Color color)
{
#if UNITY_EDITOR
if (!Application.isPlaying) return null;
#endif
TweenColor comp = UITweener.Begin<TweenColor>(go, duration);
comp.from = comp.value;
comp.to = color;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue () { from = value; }
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue () { to = value; }
[ContextMenu("Assume value of 'From'")]
void SetCurrentValueToStart () { value = from; }
[ContextMenu("Assume value of 'To'")]
void SetCurrentValueToEnd () { value = to; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cfa4a4a103e4fed43a7e9e9df4a6915c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,71 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the camera's field of view.
/// </summary>
[RequireComponent(typeof(Camera))]
[AddComponentMenu("NGUI/Tween/Tween Field of View")]
public class TweenFOV : UITweener
{
public float from = 45f;
public float to = 45f;
Camera mCam;
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
public Camera cachedCamera { get { if (mCam == null) mCam = camera; return mCam; } }
#else
public Camera cachedCamera { get { if (mCam == null) mCam = GetComponent<Camera>(); return mCam; } }
#endif
[System.Obsolete("Use 'value' instead")]
public float fov { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween's current value.
/// </summary>
public float value { get { return cachedCamera.fieldOfView; } set { cachedCamera.fieldOfView = value; } }
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished) { value = from * (1f - factor) + to * factor; }
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenFOV Begin (GameObject go, float duration, float to)
{
TweenFOV comp = UITweener.Begin<TweenFOV>(go, duration);
comp.from = comp.value;
comp.to = to;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue () { from = value; }
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue () { to = value; }
[ContextMenu("Assume value of 'From'")]
void SetCurrentValueToStart () { value = from; }
[ContextMenu("Assume value of 'To'")]
void SetCurrentValueToEnd () { value = to; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0153adb55685cee4d97c4ee2d52124e5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,82 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the widget's size.
/// </summary>
[RequireComponent(typeof(UIWidget))]
[AddComponentMenu("NGUI/Tween/Tween Height")]
public class TweenHeight : UITweener
{
public int from = 100;
public int to = 100;
public bool updateTable = false;
UIWidget mWidget;
UITable mTable;
public UIWidget cachedWidget { get { if (mWidget == null) mWidget = GetComponent<UIWidget>(); return mWidget; } }
[System.Obsolete("Use 'value' instead")]
public int height { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween's current value.
/// </summary>
public int value { get { return cachedWidget.height; } set { cachedWidget.height = value; } }
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished)
{
value = Mathf.RoundToInt(from * (1f - factor) + to * factor);
if (updateTable)
{
if (mTable == null)
{
mTable = NGUITools.FindInParents<UITable>(gameObject);
if (mTable == null) { updateTable = false; return; }
}
mTable.repositionNow = true;
}
}
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenHeight Begin (UIWidget widget, float duration, int height)
{
TweenHeight comp = UITweener.Begin<TweenHeight>(widget.gameObject, duration);
comp.from = widget.height;
comp.to = height;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue () { from = value; }
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue () { to = value; }
[ContextMenu("Assume value of 'From'")]
void SetCurrentValueToStart () { value = from; }
[ContextMenu("Assume value of 'To'")]
void SetCurrentValueToEnd () { value = to; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 66a6ab21c5f860946ade65b47cc0270b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -91
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,70 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the camera's orthographic size.
/// </summary>
[RequireComponent(typeof(Camera))]
[AddComponentMenu("NGUI/Tween/Tween Orthographic Size")]
public class TweenOrthoSize : UITweener
{
public float from = 1f;
public float to = 1f;
Camera mCam;
/// <summary>
/// Camera that's being tweened.
/// </summary>
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
public Camera cachedCamera { get { if (mCam == null) mCam = camera; return mCam; } }
#else
public Camera cachedCamera { get { if (mCam == null) mCam = GetComponent<Camera>(); return mCam; } }
#endif
[System.Obsolete("Use 'value' instead")]
public float orthoSize { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween's current value.
/// </summary>
public float value
{
get { return cachedCamera.orthographicSize; }
set { cachedCamera.orthographicSize = value; }
}
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished) { value = from * (1f - factor) + to * factor; }
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenOrthoSize Begin (GameObject go, float duration, float to)
{
TweenOrthoSize comp = UITweener.Begin<TweenOrthoSize>(go, duration);
comp.from = comp.value;
comp.to = to;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
public override void SetStartToCurrentValue () { from = value; }
public override void SetEndToCurrentValue () { to = value; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 365827806a6dd8b4583deeefe6e483c9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,110 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the object's position.
/// </summary>
[AddComponentMenu("NGUI/Tween/Tween Position")]
public class TweenPosition : UITweener
{
public Vector3 from;
public Vector3 to;
[HideInInspector]
public bool worldSpace = false;
Transform mTrans;
UIRect mRect;
public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } }
[System.Obsolete("Use 'value' instead")]
public Vector3 position { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween's current value.
/// </summary>
public Vector3 value
{
get
{
return worldSpace ? cachedTransform.position : cachedTransform.localPosition;
}
set
{
if (mRect == null || !mRect.isAnchored || worldSpace)
{
if (worldSpace) cachedTransform.position = value;
else cachedTransform.localPosition = value;
}
else
{
value -= cachedTransform.localPosition;
NGUIMath.MoveRect(mRect, value.x, value.y);
}
}
}
void Awake () { mRect = GetComponent<UIRect>(); }
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished) { value = from * (1f - factor) + to * factor; }
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenPosition Begin (GameObject go, float duration, Vector3 pos)
{
TweenPosition comp = UITweener.Begin<TweenPosition>(go, duration);
comp.from = comp.value;
comp.to = pos;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenPosition Begin (GameObject go, float duration, Vector3 pos, bool worldSpace)
{
TweenPosition comp = UITweener.Begin<TweenPosition>(go, duration);
comp.worldSpace = worldSpace;
comp.from = comp.value;
comp.to = pos;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue () { from = value; }
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue () { to = value; }
[ContextMenu("Assume value of 'From'")]
void SetCurrentValueToStart () { value = from; }
[ContextMenu("Assume value of 'To'")]
void SetCurrentValueToEnd () { value = to; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3d166255cacf07b4292b8402b3ddefc5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -95
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,74 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the object's rotation.
/// </summary>
[AddComponentMenu("NGUI/Tween/Tween Rotation")]
public class TweenRotation : UITweener
{
public Vector3 from;
public Vector3 to;
public bool quaternionLerp = false;
Transform mTrans;
public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } }
[System.Obsolete("Use 'value' instead")]
public Quaternion rotation { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween's current value.
/// </summary>
public Quaternion value { get { return cachedTransform.localRotation; } set { cachedTransform.localRotation = value; } }
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished)
{
value = quaternionLerp ? Quaternion.Slerp(Quaternion.Euler(from), Quaternion.Euler(to), factor) :
Quaternion.Euler(new Vector3(
Mathf.Lerp(from.x, to.x, factor),
Mathf.Lerp(from.y, to.y, factor),
Mathf.Lerp(from.z, to.z, factor)));
}
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenRotation Begin (GameObject go, float duration, Quaternion rot)
{
TweenRotation comp = UITweener.Begin<TweenRotation>(go, duration);
comp.from = comp.value.eulerAngles;
comp.to = rot.eulerAngles;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue () { from = value.eulerAngles; }
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue () { to = value.eulerAngles; }
[ContextMenu("Assume value of 'From'")]
void SetCurrentValueToStart () { value = Quaternion.Euler(from); }
[ContextMenu("Assume value of 'To'")]
void SetCurrentValueToEnd () { value = Quaternion.Euler(to); }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 04d1b7c9e9a19a24ab67123a43c6544b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -94
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,77 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the object's local scale.
/// </summary>
[AddComponentMenu("NGUI/Tween/Tween Scale")]
public class TweenScale : UITweener
{
public Vector3 from = Vector3.one;
public Vector3 to = Vector3.one;
public bool updateTable = false;
Transform mTrans;
UITable mTable;
public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } }
public Vector3 value { get { return cachedTransform.localScale; } set { cachedTransform.localScale = value; } }
[System.Obsolete("Use 'value' instead")]
public Vector3 scale { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished)
{
value = from * (1f - factor) + to * factor;
if (updateTable)
{
if (mTable == null)
{
mTable = NGUITools.FindInParents<UITable>(gameObject);
if (mTable == null) { updateTable = false; return; }
}
mTable.repositionNow = true;
}
}
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenScale Begin (GameObject go, float duration, Vector3 scale)
{
TweenScale comp = UITweener.Begin<TweenScale>(go, duration);
comp.from = comp.value;
comp.to = scale;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue () { from = value; }
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue () { to = value; }
[ContextMenu("Assume value of 'From'")]
void SetCurrentValueToStart () { value = from; }
[ContextMenu("Assume value of 'To'")]
void SetCurrentValueToEnd () { value = to; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 75e7459110b9666449485c40f25362a5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -93
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,81 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the object's position, rotation and scale.
/// </summary>
[AddComponentMenu("NGUI/Tween/Tween Transform")]
public class TweenTransform : UITweener
{
public Transform from;
public Transform to;
public bool parentWhenFinished = false;
Transform mTrans;
Vector3 mPos;
Quaternion mRot;
Vector3 mScale;
/// <summary>
/// Interpolate the position, scale, and rotation.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished)
{
if (to != null)
{
if (mTrans == null)
{
mTrans = transform;
mPos = mTrans.position;
mRot = mTrans.rotation;
mScale = mTrans.localScale;
}
if (from != null)
{
mTrans.position = from.position * (1f - factor) + to.position * factor;
mTrans.localScale = from.localScale * (1f - factor) + to.localScale * factor;
mTrans.rotation = Quaternion.Slerp(from.rotation, to.rotation, factor);
}
else
{
mTrans.position = mPos * (1f - factor) + to.position * factor;
mTrans.localScale = mScale * (1f - factor) + to.localScale * factor;
mTrans.rotation = Quaternion.Slerp(mRot, to.rotation, factor);
}
// Change the parent when finished, if requested
if (parentWhenFinished && isFinished) mTrans.parent = to;
}
}
/// <summary>
/// Start the tweening operation from the current position/rotation/scale to the target transform.
/// </summary>
static public TweenTransform Begin (GameObject go, float duration, Transform to) { return Begin(go, duration, null, to); }
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenTransform Begin (GameObject go, float duration, Transform from, Transform to)
{
TweenTransform comp = UITweener.Begin<TweenTransform>(go, duration);
comp.from = from;
comp.to = to;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1d805c79a1ab11643bfd9d91e10c195a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,92 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the audio source's volume.
/// </summary>
[RequireComponent(typeof(AudioSource))]
[AddComponentMenu("NGUI/Tween/Tween Volume")]
public class TweenVolume : UITweener
{
#if UNITY_3_5
public float from = 1f;
public float to = 1f;
#else
[Range(0f, 1f)] public float from = 1f;
[Range(0f, 1f)] public float to = 1f;
#endif
AudioSource mSource;
/// <summary>
/// Cached version of 'audio', as it's always faster to cache.
/// </summary>
public AudioSource audioSource
{
get
{
if (mSource == null)
{
mSource = GetComponent<AudioSource>();
if (mSource == null)
{
mSource = GetComponent<AudioSource>();
if (mSource == null)
{
Debug.LogError("TweenVolume needs an AudioSource to work with", this);
enabled = false;
}
}
}
return mSource;
}
}
[System.Obsolete("Use 'value' instead")]
public float volume { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Audio source's current volume.
/// </summary>
public float value
{
get
{
return audioSource != null ? mSource.volume : 0f;
}
set
{
if (audioSource != null) mSource.volume = value;
}
}
protected override void OnUpdate (float factor, bool isFinished)
{
value = from * (1f - factor) + to * factor;
mSource.enabled = (mSource.volume > 0.01f);
}
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenVolume Begin (GameObject go, float duration, float targetVolume)
{
TweenVolume comp = UITweener.Begin<TweenVolume>(go, duration);
comp.from = comp.value;
comp.to = targetVolume;
return comp;
}
public override void SetStartToCurrentValue () { from = value; }
public override void SetEndToCurrentValue () { to = value; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17aeef7ce6c142344959e650cab20151
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,82 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the widget's size.
/// </summary>
[RequireComponent(typeof(UIWidget))]
[AddComponentMenu("NGUI/Tween/Tween Width")]
public class TweenWidth : UITweener
{
public int from = 100;
public int to = 100;
public bool updateTable = false;
UIWidget mWidget;
UITable mTable;
public UIWidget cachedWidget { get { if (mWidget == null) mWidget = GetComponent<UIWidget>(); return mWidget; } }
[System.Obsolete("Use 'value' instead")]
public int width { get { return this.value; } set { this.value = value; } }
/// <summary>
/// Tween's current value.
/// </summary>
public int value { get { return cachedWidget.width; } set { cachedWidget.width = value; } }
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished)
{
value = Mathf.RoundToInt(from * (1f - factor) + to * factor);
if (updateTable)
{
if (mTable == null)
{
mTable = NGUITools.FindInParents<UITable>(gameObject);
if (mTable == null) { updateTable = false; return; }
}
mTable.repositionNow = true;
}
}
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenWidth Begin (UIWidget widget, float duration, int width)
{
TweenWidth comp = UITweener.Begin<TweenWidth>(widget.gameObject, duration);
comp.from = widget.width;
comp.to = width;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
[ContextMenu("Set 'From' to current value")]
public override void SetStartToCurrentValue () { from = value; }
[ContextMenu("Set 'To' to current value")]
public override void SetEndToCurrentValue () { to = value; }
[ContextMenu("Assume value of 'From'")]
void SetCurrentValueToStart () { value = from; }
[ContextMenu("Assume value of 'To'")]
void SetCurrentValueToEnd () { value = to; }
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0fe5d396737f89f4ea1534bc147cad2e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -92
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,470 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2014 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Base class for all tweening operations.
/// </summary>
public abstract class UITweener : MonoBehaviour
{
/// <summary>
/// Current tween that triggered the callback function.
/// </summary>
public int exeOrder = 0;
static public UITweener current;
public enum Method
{
Linear,
EaseIn,
EaseOut,
EaseInOut,
BounceIn,
BounceOut,
}
public enum Style
{
Once,
Loop,
PingPong,
}
/// <summary>
/// Tweening method used.
/// </summary>
[HideInInspector]
public Method method = Method.Linear;
/// <summary>
/// Does it play once? Does it loop?
/// </summary>
[HideInInspector]
public Style style = Style.Once;
/// <summary>
/// Optional curve to apply to the tween's time factor value.
/// </summary>
[HideInInspector]
public AnimationCurve animationCurve = new AnimationCurve (new Keyframe (0f, 0f, 0f, 1f), new Keyframe (1f, 1f, 1f, 0f));
/// <summary>
/// Whether the tween will ignore the timescale, making it work while the game is paused.
/// </summary>
[HideInInspector]
public bool ignoreTimeScale = true;
/// <summary>
/// How long will the tweener wait before starting the tween?
/// </summary>
[HideInInspector]
public float delay = 0f;
/// <summary>
/// How long is the duration of the tween?
/// </summary>
[HideInInspector]
public float duration = 1f;
/// <summary>
/// Whether the tweener will use steeper curves for ease in / out style interpolation.
/// </summary>
[HideInInspector]
public bool steeperCurves = false;
/// <summary>
/// Used by buttons and tween sequences. Group of '0' means not in a sequence.
/// </summary>
[HideInInspector]
public int tweenGroup = 0;
/// <summary>
/// Event delegates called when the animation finishes.
/// </summary>
[HideInInspector]
public List<EventDelegate> onFinished = new List<EventDelegate> ();
// Deprecated functionality, kept for backwards compatibility
[HideInInspector]
public GameObject eventReceiver;
[HideInInspector]
public string callWhenFinished;
public object onFinishCallback; // add by chenbin
bool mStarted = false;
float mStartTime = 0f;
float mDuration = 0f;
float mAmountPerDelta = 1000f;
float mFactor = 0f;
/// <summary>
/// Amount advanced per delta time.
/// </summary>
public float amountPerDelta {
get {
if (mDuration != duration) {
mDuration = duration;
mAmountPerDelta = Mathf.Abs ((duration > 0f) ? 1f / duration : 1000f);
}
return mAmountPerDelta;
}
}
/// <summary>
/// Tween factor, 0-1 range.
/// </summary>
public float tweenFactor { get { return mFactor; } set { mFactor = Mathf.Clamp01 (value); } }
/// <summary>
/// Direction that the tween is currently playing in.
/// </summary>
public AnimationOrTween.Direction direction { get { return mAmountPerDelta < 0f ? AnimationOrTween.Direction.Reverse : AnimationOrTween.Direction.Forward; } }
/// <summary>
/// This function is called by Unity when you add a component. Automatically set the starting values for convenience.
/// </summary>
public void Reset ()
{
if (!mStarted) {
SetStartToCurrentValue ();
SetEndToCurrentValue ();
}
}
/// <summary>
/// Update as soon as it's started so that there is no delay.
/// </summary>
protected virtual void Start ()
{
Update ();
}
/// <summary>
/// Update the tweening factor and call the virtual update function.
/// </summary>
void Update ()
{
float delta = ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime;
float time = ignoreTimeScale ? RealTime.time : Time.time;
if (!mStarted) {
mStarted = true;
mStartTime = time + delay;
}
if (time < mStartTime)
return;
// Advance the sampling factor
mFactor += amountPerDelta * delta;
// Loop style simply resets the play factor after it exceeds 1.
if (style == Style.Loop) {
if (mFactor > 1f) {
mFactor -= Mathf.Floor (mFactor);
}
} else if (style == Style.PingPong) {
// Ping-pong style reverses the direction
if (mFactor > 1f) {
mFactor = 1f - (mFactor - Mathf.Floor (mFactor));
mAmountPerDelta = -mAmountPerDelta;
} else if (mFactor < 0f) {
mFactor = -mFactor;
mFactor -= Mathf.Floor (mFactor);
mAmountPerDelta = -mAmountPerDelta;
}
}
// If the factor goes out of range and this is a one-time tweening operation, disable the script
if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f)) {
mFactor = Mathf.Clamp01 (mFactor);
Sample (mFactor, true);
// Disable this script unless the function calls above changed something
if (duration == 0f || (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f))
enabled = false;
current = this;
if (onFinished != null) {
mTemp = onFinished;
onFinished = new List<EventDelegate> ();
// Notify the listener delegates
EventDelegate.Execute (mTemp, gameObject);
// Re-add the previous persistent delegates
for (int i = 0; i < mTemp.Count; ++i)
EventDelegate.Add (onFinished, mTemp [i]);
mTemp = null;
}
// Deprecated legacy functionality support
if (eventReceiver != null && !string.IsNullOrEmpty (callWhenFinished))
eventReceiver.SendMessage (callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
Coolape.Utl.doCallback (onFinishCallback, this); // add by chenbin
current = null;
} else
Sample (mFactor, false);
}
List<EventDelegate> mTemp = null;
/// <summary>
/// Convenience function -- set a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public void SetOnFinished (EventDelegate.Callback del)
{
EventDelegate.Set (onFinished, del);
}
/// <summary>
/// Convenience function -- set a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public void SetOnFinished (EventDelegate del)
{
EventDelegate.Set (onFinished, del);
}
/// <summary>
/// Convenience function -- add a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public void AddOnFinished (EventDelegate.Callback del)
{
EventDelegate.Add (onFinished, del);
}
/// <summary>
/// Convenience function -- add a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public void AddOnFinished (EventDelegate del)
{
EventDelegate.Add (onFinished, del);
}
/// <summary>
/// Remove an OnFinished delegate. Will work even while iterating through the list when the tweener has finished its operation.
/// </summary>
public void RemoveOnFinished (EventDelegate del)
{
if (onFinished != null)
onFinished.Remove (del);
if (mTemp != null)
mTemp.Remove (del);
}
/// <summary>
/// Mark as not started when finished to enable delay on next play.
/// </summary>
void OnDisable ()
{
mStarted = false;
}
/// <summary>
/// Sample the tween at the specified factor.
/// </summary>
public void Sample (float factor, bool isFinished)
{
// Calculate the sampling value
float val = Mathf.Clamp01 (factor);
if (method == Method.EaseIn) {
val = 1f - Mathf.Sin (0.5f * Mathf.PI * (1f - val));
if (steeperCurves)
val *= val;
} else if (method == Method.EaseOut) {
val = Mathf.Sin (0.5f * Mathf.PI * val);
if (steeperCurves) {
val = 1f - val;
val = 1f - val * val;
}
} else if (method == Method.EaseInOut) {
const float pi2 = Mathf.PI * 2f;
val = val - Mathf.Sin (val * pi2) / pi2;
if (steeperCurves) {
val = val * 2f - 1f;
float sign = Mathf.Sign (val);
val = 1f - Mathf.Abs (val);
val = 1f - val * val;
val = sign * val * 0.5f + 0.5f;
}
} else if (method == Method.BounceIn) {
val = BounceLogic (val);
} else if (method == Method.BounceOut) {
val = 1f - BounceLogic (1f - val);
}
// Call the virtual update
OnUpdate ((animationCurve != null) ? animationCurve.Evaluate (val) : val, isFinished);
}
/// <summary>
/// Main Bounce logic to simplify the Sample function
/// </summary>
float BounceLogic (float val)
{
if (val < 0.363636f) { // 0.363636 = (1/ 2.75)
val = 7.5685f * val * val;
} else if (val < 0.727272f) { // 0.727272 = (2 / 2.75)
val = 7.5625f * (val -= 0.545454f) * val + 0.75f; // 0.545454f = (1.5 / 2.75)
} else if (val < 0.909090f) { // 0.909090 = (2.5 / 2.75)
val = 7.5625f * (val -= 0.818181f) * val + 0.9375f; // 0.818181 = (2.25 / 2.75)
} else {
val = 7.5625f * (val -= 0.9545454f) * val + 0.984375f; // 0.9545454 = (2.625 / 2.75)
}
return val;
}
/// <summary>
/// Play the tween.
/// </summary>
[System.Obsolete("Use PlayForward() instead")]
public void Play ()
{
Play (true);
}
/// <summary>
/// Play the tween forward.
/// </summary>
public void PlayForward ()
{
Play (true);
}
/// <summary>
/// Play the tween in reverse.
/// </summary>
public void PlayReverse ()
{
Play (false);
}
/// <summary>
/// Manually activate the tweening process, reversing it if necessary.
/// </summary>
public void Play (bool forward)
{
mAmountPerDelta = Mathf.Abs (amountPerDelta);
if (!forward)
mAmountPerDelta = -mAmountPerDelta;
enabled = true;
Update ();
}
/// <summary>
/// Manually reset the tweener's state to the beginning.
/// If the tween is playing forward, this means the tween's start.
/// If the tween is playing in reverse, this means the tween's end.
/// </summary>
public void ResetToBeginning ()
{
mStarted = false;
mFactor = (mAmountPerDelta < 0f) ? 1f : 0f;
Sample (mFactor, false);
}
/// <summary>
/// Manually start the tweening process, reversing its direction.
/// </summary>
public void Toggle ()
{
if (mFactor > 0f) {
mAmountPerDelta = -amountPerDelta;
} else {
mAmountPerDelta = Mathf.Abs (amountPerDelta);
}
enabled = true;
}
/// <summary>
/// Actual tweening logic should go here.
/// </summary>
abstract protected void OnUpdate (float factor, bool isFinished);
/// <summary>
/// Starts the tweening operation.
/// </summary>
static public T Begin<T> (GameObject go, float duration) where T : UITweener
{
T comp = go.GetComponent<T> ();
#if UNITY_FLASH
if ((object)comp == null) comp = (T)go.AddComponent<T>();
#else
if (comp == null)
comp = go.AddComponent<T> ();
#endif
comp.mStarted = false;
comp.duration = duration;
comp.mFactor = 0f;
comp.mAmountPerDelta = Mathf.Abs (comp.mAmountPerDelta);
comp.style = Style.Once;
comp.animationCurve = new AnimationCurve (new Keyframe (0f, 0f, 0f, 1f), new Keyframe (1f, 1f, 1f, 0f));
comp.eventReceiver = null;
comp.callWhenFinished = null;
comp.enabled = true;
if (duration <= 0f) {
comp.Sample (1f, true);
comp.enabled = false;
}
return comp;
}
/// <summary>
/// Set the 'from' value to the current one.
/// </summary>
public virtual void SetStartToCurrentValue ()
{
}
/// <summary>
/// Set the 'to' value to the current one.
/// </summary>
public virtual void SetEndToCurrentValue ()
{
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c96860f5597f2494abb42d29cdca0bcc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: