Created by Lee Dong-Myung(Toki-Labs)
XTween is Tweener library for unity using by code, It has powerful performance and easy to implement.
XTween is
- Can make tweener by few code (easy to learn and good readablity)
- Provide code hint. (You just start with "To" than You can use tweener)
- Easy to control event. (Support Anonymous Method)
- Support coroutine. (Easy to combine with other instruction)
- Support custom easing.
- Can make instance. This good at resuablity and time control.
- Less use of memory and cpu. (XTween is don't create MonoBehaviour each by tween)
- Support in editor mode(Not Play mode) and Available on all types of platforms
You can check example at XTween Example
Ps. Because it is still in the development stage(ALPHA), the interface can change frequently. At this stage, you can use it for testing purposes. After in BETA, You can use it stably.
// Shortcut type
gameObject.ToPosition2D(600f, 200f, 1f).Play();
// Universal type
XTween.To(gameObject, XHash.Position(600f, 200f), 1f).Play();
// Use with coroutine
StartCoroutine(CoroutineTween());
IEnumerator CoroutineTween()
{
yield return gameObject.ToPosition2D(600f, 200f, 1f).WaitForPlay();
//or
yield return XTween.To(gameObject, XHash.Position(600f, 200f), 1f).WaitForPlay();
}
Version(Alpha) 0.0.115 - XTween_0.0.115.unitypackage
Tweener comparison when moving 1000 gameObjects. set x, y, z and use elastic easing.
Garbage Alloc
Start
End
CPU Performance
XTween is similar with D Tween, but 2 times faster than i Tweener.
Gabage Alloc Time/Cost XTween D Tween L Tween I Tween Start 122B 0.6MB 406.4KB 4.7MB End 0B 0B 0B 169.9KB Update 0.8ms 0.8ms 1.2ms 1.7ms Total 122B/0.8ms 0.6MB/0.8ms 406.4KB/1.2ms 4.9MB/1.7ms XTween does not produce Garbage because it uses Pooling. and XTween is good performance at cpu.
Code Compare
Other Tweener Code
XTween Code
- Support property tween
- Support UI RectTransform
- Performance check & polishing effciency
- Support Easing Edit in UI Graph
- Stabilize Interface
- Decorator Combine with IXTween Interface
- Documentaion
- Specific examples
- Support visual editor
- Support path editor by GUI
gameObject.ToPosition2D(600f, 200f, 1f).Play();
//Universal type
XTween.To(gameObject, XHash.New.AddX(600f).AddY(200f).AddZ(100f), 1f).Play();
gameObject.ToScale2D(1f, 1.5f, 1f).Play();
//Universal type
XTween.To(gameObject, XHash.New.AddScaleX(1f).AddScaleY(1.5f).AddScaleZ(0.5f), 1f).Play();
gameObject.ToRotation3D(60f, -180f, -45f, 1f).Play();
//Universal type
XTween.To(gameObject, XHash.New.AddRotationZ(600f), 1f).Play();
//Position, Scale, Rotation tween in same time, same easing
gameObject.To(XHash.Position(0f,10f).AddScaleX(200f).AddRotationZ(60f), 1f).Play();
//Universal type
XTween.To(gameObject, XHash.New.AddX(600f).AddScaleX(200f).AddRotationZ(180f), 1f).Play();
XHash hash = XHash.Position(0f,0f).AddControlPointX(1000f).AddControlPointZ(-500f);
gameObject.To(hash, 1f).Play();
//Universal type
XTween.To(gameObject, hash, 1f).Play();
//Setter
XTween.ToValue(x=>camera3D.fieldOfView=x, 10f, 1f).Play();
//or Multi value type
XObjectHash hash = XObjectHash.New.Add("value0", 50f, 10f).Add("value1", 0f, 10f);
XTween.ToValueMulti(hash, UpdateValue, 1f).Play();
void UpdateValue(XObjectHash hash)
{
camera3D.fieldOfView = hash.Now("value0");
Debug.Log( hash.Now("value1") );
}
camera3D.ToProperty("fieldOfView", 6f, 1f).Play();
gameObject.ToPosition2D(600f, 200f, 1f)
.AddOnComplete(()=>Debug.Log("OnComplete")).Play();
void OnTweenEnd(GameObject tweenTarget)
{
Debug.Log(value);
}
Support use with coroutine
//Start tween
IEnumerator tweenCoroutine = CoroutineTween();
StartCoroutine(tweenCoroutine);
IEnumerator CoroutineTween()
{
yield return gameObject.ToPosition3D(200f, 50f, -1500f, 1f).WaitForPlay();
Debug.Log("On Complete First Tween");
//Start other tween start at 0.3sec
yield return gameObject.ToPosition2D(100f, 500f, 1f).WaitForPlay(0.3f);
Debug.Log("On Complete Second Tween");
}
//Stop tween;
StopCoroutine(tweenCoroutine);
XTween.SerialTweens
(
false,
gameObject.ToPosition2D(1000f, 300f, 1f),
gameObject.ToScale2D(200f, 200f, 1f)
).Play();
XTween.ParallelTweens
(
false,
gameObject.ToPosition2D(1000f, 300f, 1f),
gameObject.ToScale(200f, 200f, 1f)
).Play();
XHash hashButton = XHash.New.AddX(400f).AddY(-250f).AddWidth(800f).AddHeight(400f);
XTween.To(button, hashButton, 1f).Play();
//or when stretch type
XHash hashDropdown = XHash.New.AddLeft(2000f).AddRight(300f).AddTop(500f).AddBottom(400f);
XTween.To(dropdown, hashDropdown, 1f).Play();
XTween.ToColor(sprite, XColorHash.New.AddRed(0.56f).AddGreen(0.83f), 1f).Play();
//or when object has other type
XColorHash hash = XColorHash.New.AddRed(0.56f).AddGreen(0.83f);
XTween.ToColor<Image>(imageInstance, "color", hash, 1f).Play();
gameObject.ToPosition2D(600f, 200f, 1f, Ease.QuintOut).Play();
Customizable Easing, Support code hint for use of ease name, TopMenu -> Windows -> XTween Editor
XHash hash = XHash.Position(200f, 50f, -1500f)
.AddControlPointX(-1000f,550f).AddControlPointY(550f,-300f);
XTween.To(target3D, hash, 1f, Ease.Custom(EaseCustom.MyEasing)).Play();
IXTween tween = XTween.ToColor(sprite, XColorHash.New.AddRed(0.56f).AddGreen(0.83f), 1f);
//Delay Tweener
tween.SetDelay(tween, 1f/*Pre Delay*/, 1f/*Post Delay*/);
//Scale Tweener time
tween.SetScale(tween, 2f/*Scale tweener time*/);
//Repeat Tweener
tween.SetRepeat(tween, 3/*3 time repeat*/);
//Reverse Tweener
tween.SetReverse(tween);
tween.Play();
XTween is basically autodispose. when the tweener is completed or stopped. So, you should set to "Lock" for reuse tweener
//This Tweener will not dispose when stop or complete.
IXTween tween = gameObject.ToPosition2D(600f, 200f, 1f).SetLock().Play();
//When the tweener after completed or stopped. You can reuse this.
tween.Play(0f); //Replay
//When you are not using twin anymore. You should "Release" this tween.
tween.Release();
tween = null;
//Start
IXTween tween = gameObject.ToPosition2D(600f, 200f, 1f).Lock().Play();
//Stop at this position
tween.Stop();
//Resume
tween.Play();
//Move to 0.5sec and Stop
tween.GotoAndStop(0.5f);
//Move to 0.3sec and play;
tween.Play(0.3f);
//Position set to 0 and Stop
tween.Reset();
Lee Dong-Myung(Tok-Labs) is a software developer in Korea.
Blog: http://blog.toki-labs.com (Korean) Mail: [email protected]
This library is under the MIT License.
Some code is borrowed from BetweenAS3.