最近再做一个小的项目,只要使用的是DOTween 动画。 但是感到DOTween 在某些方面不如 NGUI的Twenn 比较好用 所以就模仿了一下

在此,请各位大神指点一下

DOTween 模仿NGUI Tween-LMLPHPDOTween 模仿NGUI Tween-LMLPHP

DOTween 模仿NGUI Tween-LMLPHP

public class HCTweenScale :DoTweener {

    public Vector3 formScale;
public Vector3 toScale;
public float animTime = 1f;
Transform tr;
Transform myTransform {
get {
if (tr == null)
tr = transform;
return tr;
}
set {
tr = value;
}
} Vector3 Scale {
get{
return myTransform.localScale;
}
}
public override void PlayForward() {
StyleFunction(formScale, toScale);
}
public override void PlayReverse() {
StyleFunction(toScale, formScale);
} void StyleFunction(Vector3 from, Vector3 to) {
switch (style) {
case Style.Once:
One(from, to);
break;
case Style.Loop:
Loop(from, to);
break;
case Style.Repeatedly:
Repeatedly(from, to);
break;
case Style.PingPong:
PingPong(from, to);
break;
}
}
void One(Vector3 from, Vector3 to) {
myTransform.localScale = from;
myTransform.DOScale(to, animTime).OnComplete(() => OnComplete());
}
void Repeatedly(Vector3 from, Vector3 to) {
myTransform.localScale = from;
myTransform.DOScale(to, animTime).OnComplete(() => myTransform.DOScale(from, animTime));
}
void Loop(Vector3 from, Vector3 to) {
myTransform.localScale = from;
myTransform.DOScale(to, animTime).OnComplete(() => Loop(from,to));
}
void PingPong(Vector3 from, Vector3 to) {
myTransform.DOScale(to, animTime).OnComplete(() => PingPong(to, from));
} protected override void StartValue() {
formScale = Scale;
}
protected override void EndValue() {
toScale = Scale;
}
}

DOTween 模仿NGUI Tween-LMLPHP

public class HCTweenPosition : DoTweener{
public Vector3 Form;
public Vector3 To;
public float MoveTime=1f;
Transform my;
Transform myTransform {
get {
if (my == null)
my = transform;
return my;
}
}
Vector3 position {
get {
return myTransform.position;
}
}
public override void PlayForward() {
StyleFunction(this.Form, this.To);
}
public override void PlayReverse() {
StyleFunction(this.To, this.Form);
}
void StyleFunction(Vector3 From, Vector3 To) {
switch (style) {
case Style.Once:
One(From, To);
break;
case Style.Loop:
Loop(From, To);
break;
case Style.Repeatedly:
Repeatedly(From, To);
break;
case Style.PingPong:
PingPong(From, To);
break;
}
}
void One(Vector3 From, Vector3 To) {
myTransform.position = From;
myTransform.DOMove(To, MoveTime).OnComplete(() => OnComplete());
}
void Repeatedly(Vector3 From,Vector3 To) {
myTransform.position = From;
myTransform.DOMove(To, MoveTime).OnComplete(() => myTransform.DOMove(Form, MoveTime));
}
void Loop(Vector3 From, Vector3 To) {
myTransform.position = From;
myTransform.DOMove(To, MoveTime).OnComplete(() => Loop(Form, To));
}
void PingPong(Vector3 From, Vector3 To) {
myTransform.DOMove(To, MoveTime).OnComplete(() => PingPong(To, From));
}
protected override void StartValue() {
Form = this.position;
}
protected override void EndValue() {
To = this.position;
}
}

DOTween 模仿NGUI Tween-LMLPHP

public class HCTweenAlpha :DoTweenerAlpha {
public float StartAlpha;
public float EndAlpha;
public float durtion = 1f;
tk2dBaseSprite _sprite;
tk2dBaseSprite sprite {
get {
if (_sprite == null) {
_sprite = gameObject.GetComponent<tk2dBaseSprite>();
}
return _sprite;
}
set {
_sprite = value;
}
}
public float GetAlpha {
get {
return sprite.color.a;
}
} bool Forward = true;
public override void PlayForward() {
Forward = true;
StyleFunction(StartAlpha, EndAlpha, durtion, style);
}
public override void PlayReverse() {
Forward = false;
StyleFunction(EndAlpha, StartAlpha, durtion, style);
} void StyleFunction(float fromAlpha, float toAlpha,float animTime, DoTweener.Style style) {
if (sprite == null) {
Des();
return;
}
// SetChildAlpha(fromAlpha, toAlpha, animTime, style);
switch (style) {
case Style.Once:
One(fromAlpha, toAlpha, animTime);
break;
case Style.Loop:
Loop(fromAlpha, toAlpha, animTime);
break;
case Style.Repeatedly:
Repeatedly(fromAlpha, toAlpha, animTime);
break;
case Style.PingPong:
PingPong(fromAlpha, toAlpha, animTime);
break;
}
} //float notAlpha;
//public override void SetAlpha(float startalpha, float alpha,float animTime, DoTweener.Style style) {
// if (notAlpha == null)
// notAlpha = GetAlpha;
// if (alpha >= notAlpha)
// alpha = notAlpha;
// if (startalpha > notAlpha)
// startalpha = notAlpha; // StyleFunction(startalpha, alpha, animTime, style);
//}
void One(float fromAlpha, float toAlpha,float time) {
sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, fromAlpha);
DOTween.ToAlpha(() => sprite.color, x => sprite.color = x, toAlpha, time).OnComplete(() => OnComplete());
}
void Repeatedly(float fromAlpha, float toAlpha, float time) {
sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, fromAlpha);
DOTween.ToAlpha(() => sprite.color, x => sprite.color = x, toAlpha, time).OnComplete(() => DOTween.ToAlpha(() => sprite.color, x => sprite.color = x, fromAlpha, time));
}
void Loop(float fromAlpha, float toAlpha, float time) {
sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, fromAlpha);
DOTween.ToAlpha(() => sprite.color, x => sprite.color = x, EndAlpha, time).OnComplete(() => Loop(fromAlpha, toAlpha, time));
}
void PingPong(float fromAlpha, float toAlpha, float time) {
DOTween.ToAlpha(() => sprite.color, x => sprite.color = x, toAlpha, time).OnComplete(() => PingPong(toAlpha, fromAlpha, time));
} protected override void StartValue() {
if (sprite) {
StartAlpha = sprite.color.a;
EndAlpha = sprite.color.a;
return;
}
} void Des() {
Destroy(GetComponent<HCTweenAlpha>(), 1f);
HCTweenTextAlpha text = gameObject.AddComponent<HCTweenTextAlpha>();
text.StartAlpha = this.StartAlpha;
text.EndAlpha = this.EndAlpha;
text.durtion = this.durtion;
text.style = this.style;
text.IsStartRun = this.IsStartRun;
if (Forward)
text.PlayForward();
else
text.PlayReverse(); }
}
  tween.OnComplete = () => {
Debug.Log("这里是 回调");
}

基于某些原因 twenn 的动画方式没有写 如果各位需要 请自行添加

下面附上链接

链接:http://pan.baidu.com/s/1c0dlWkC 密码:iaue

05-08 15:51