OT源代码的分析,OrtHello 迟早攻破你 (十二)第7个例子,ortHello的动作类OTTween(未完)
2011-12-16 11:22
357 查看
-,-其实首先说明一点OTTween我觉得不够完美,甚至比不上iTween -。-
不过既然是自带的 速度还是可以的
特别注明一点,OT的动作是通过 点号 . 连接起来的
下面来看看代码:
public class CStar7_1 : MonoBehaviour
{
OTTween tween;
void OnMouseEnter()
{
if (tween!=null && tween.isRunning)
tween.Stop();
tween = new OTTween(GetComponent<OTSprite>(), 1f, OTEasing.ElasticOut).
Tween("size", new Vector2(80, 80)).
Tween("tintColor", new Color(0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f), OTEasing.StrongOut);
}
void OnMouseExit()
{
if (tween!=null && tween.isRunning)
tween.Stop();
tween = new OTTween(GetComponent<OTSprite>(), 1.5f, OTEasing.ElasticOut).
Tween("size", new Vector2(50, 50)).
Tween("tintColor", new Color(0.5f,0.5f,0.5f), OTEasing.StrongIn);
}
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
public class CStar7_2 : MonoBehaviour
{
OTTween runningTween = null;
OTTween tween = null;
void OnMouseEnter()
{
if ((tween!=null && tween.isRunning) || runningTween != null)
return;
tween = new OTTween(GetComponent<OTSprite>(), 2f, OTEasing.Linear).
Tween("size", new Vector2(250, 250)).
Tween("alpha", 1 , 0 , OTEasing.Linear);
tween.onTweenFinish = TweenFinish;
new OTTween(GetComponent<OTSprite>(), 1f, OTEasing.Linear).
Tween("tintColor", new Color(0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f), OTEasing.StrongOut);
}
void TweenFinish(OTTween tween)
{
if (tween != runningTween)
{
runningTween = new OTTween(GetComponent<OTSprite>(), .5f, OTEasing.Linear).
Tween("size", new Vector2(1, 1), new Vector2(50, 50)).
Tween("alpha", 0, 1, OTEasing.Linear);
new OTTween(GetComponent<OTSprite>(), .1f, OTEasing.Linear).
Tween("tintColor", new Color(0.3f, 0.3f, 0.3f), OTEasing.StrongOut);
runningTween.onTweenFinish = TweenFinish;
}
else
runningTween = null;
}
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
public class CExample7 : MonoBehaviour
{
int mode = 0;
float time = 0;
int easeIdx = 0;
OTEase[] easings = new OTEase[]
{
OTEasing.ElasticOut,
OTEasing.BounceOut,
OTEasing.StrongOut,
OTEasing.StrongIn,
OTEasing.BackOut,
OTEasing.BackIn,
OTEasing.SineOut,
OTEasing.Linear,
};
// Update is called once per frame
void Update () {
if (time == 0)
GameObject.Find("text-21").GetComponent<TextMesh>().text = "Next easing will be : " + easings[easeIdx].GetType().ToString();
time += Time.deltaTime;
if (time > 3)
{
MoveStars();
time = 0;
}
}
void MoveStars()
{
int idx = 1;
GameObject g = GameObject.Find("stars-"+idx);
while (g!=null)
{
new OTTween(g.transform,1.5f,easings[easeIdx]).TweenAdd("position",new Vector3((mode==0)?400:-400,0,0));
g = GameObject.Find("stars-" + (++idx));
}
mode = 1 - mode;
if (mode == 0)
{
easeIdx++;
if (easeIdx == easings.Length)
easeIdx = 0;
}
}
}
不过既然是自带的 速度还是可以的
特别注明一点,OT的动作是通过 点号 . 连接起来的
下面来看看代码:
public class CStar7_1 : MonoBehaviour
{
OTTween tween;
void OnMouseEnter()
{
if (tween!=null && tween.isRunning)
tween.Stop();
tween = new OTTween(GetComponent<OTSprite>(), 1f, OTEasing.ElasticOut).
Tween("size", new Vector2(80, 80)).
Tween("tintColor", new Color(0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f), OTEasing.StrongOut);
}
void OnMouseExit()
{
if (tween!=null && tween.isRunning)
tween.Stop();
tween = new OTTween(GetComponent<OTSprite>(), 1.5f, OTEasing.ElasticOut).
Tween("size", new Vector2(50, 50)).
Tween("tintColor", new Color(0.5f,0.5f,0.5f), OTEasing.StrongIn);
}
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
public class CStar7_2 : MonoBehaviour
{
OTTween runningTween = null;
OTTween tween = null;
void OnMouseEnter()
{
if ((tween!=null && tween.isRunning) || runningTween != null)
return;
tween = new OTTween(GetComponent<OTSprite>(), 2f, OTEasing.Linear).
Tween("size", new Vector2(250, 250)).
Tween("alpha", 1 , 0 , OTEasing.Linear);
tween.onTweenFinish = TweenFinish;
new OTTween(GetComponent<OTSprite>(), 1f, OTEasing.Linear).
Tween("tintColor", new Color(0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f, 0.5f + Random.value * 0.5f), OTEasing.StrongOut);
}
void TweenFinish(OTTween tween)
{
if (tween != runningTween)
{
runningTween = new OTTween(GetComponent<OTSprite>(), .5f, OTEasing.Linear).
Tween("size", new Vector2(1, 1), new Vector2(50, 50)).
Tween("alpha", 0, 1, OTEasing.Linear);
new OTTween(GetComponent<OTSprite>(), .1f, OTEasing.Linear).
Tween("tintColor", new Color(0.3f, 0.3f, 0.3f), OTEasing.StrongOut);
runningTween.onTweenFinish = TweenFinish;
}
else
runningTween = null;
}
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
public class CExample7 : MonoBehaviour
{
int mode = 0;
float time = 0;
int easeIdx = 0;
OTEase[] easings = new OTEase[]
{
OTEasing.ElasticOut,
OTEasing.BounceOut,
OTEasing.StrongOut,
OTEasing.StrongIn,
OTEasing.BackOut,
OTEasing.BackIn,
OTEasing.SineOut,
OTEasing.Linear,
};
// Update is called once per frame
void Update () {
if (time == 0)
GameObject.Find("text-21").GetComponent<TextMesh>().text = "Next easing will be : " + easings[easeIdx].GetType().ToString();
time += Time.deltaTime;
if (time > 3)
{
MoveStars();
time = 0;
}
}
void MoveStars()
{
int idx = 1;
GameObject g = GameObject.Find("stars-"+idx);
while (g!=null)
{
new OTTween(g.transform,1.5f,easings[easeIdx]).TweenAdd("position",new Vector3((mode==0)?400:-400,0,0));
g = GameObject.Find("stars-" + (++idx));
}
mode = 1 - mode;
if (mode == 0)
{
easeIdx++;
if (easeIdx == easings.Length)
easeIdx = 0;
}
}
}
相关文章推荐
- OT源代码的分析,OrtHello 迟早攻破你 (十)第5个例子,用代码来创建物体(未完)
- OT源代码的分析,OrtHello 迟早攻破你 (十一)第6个例子,物理引擎和ortHello的结合(未完)
- OT源代码的分析,OrtHello 迟早攻破你 (十三)ortHello的代码执行顺序
- OT源代码的分析,OrtHello 迟早攻破你 (九)第4个例子,镜头缩放,路径运动
- OT源代码的分析,OrtHello 迟早攻破你 (八)第3个例子,碰撞检测和动画
- OT源代码的分析,OrtHello 迟早攻破你 (七)第2个例子,碰撞和简单运动
- OT源代码的分析,OrtHello 迟早攻破你 (五)默认的五种材质 和OTView
- OT源代码的分析,OrtHello 迟早攻破你 (五)OTContainer相关
- OT源代码的分析,OrtHello 迟早攻破你 (六)重要的OTSprite
- OT源代码的分析,OrtHello 迟早攻破你 (二)OT的基本属性和基本流程
- OT源代码的分析,OrtHello 迟早攻破你 (三)OTObjectType 和OTMatRef 和OTObject
- OT源代码的分析,OrtHello 迟早攻破你 (一)OTTween类参透
- OT源代码的分析,OrtHello 迟早攻破你 (四)OTController
- Adapter 模式的小例子以及分析
- 大数据日志分析小例子
- Samurai框架分析--未完待续
- 关于出现 Protel 99 SE 'Format '%x' invalid or incompatible with argument' 的分析 以及补丁安装方法
- 对餐馆例子中的manager联邦成员的代码分析
- 使用UInput模拟系统键盘鼠标动作 UInput driver分析
- OGRE 1.7 例子程序分析