下载iTween后主要用到其中的两个脚本,iTween和iTweenPath脚本,其他的资源建议删除
对于角色的移动和视角的效果
//物体从屏幕外移动到起始点//
public static void PlayerMoveAndScaleAnim(GameObject go, float changeTime, iTween.EaseType moveType,
GameObject callBackObj = null, string methodName = "", bool isPlayScale = true, float y = -2000, float z = -2000){
Vector3 startPos = go.transform.position;
go.transform.localPosition = new Vector3(startPos.x, startPos.y, z);
//播放由大到小的效果//
if(isPlayScale){
Vector3 startScale = go.transform.localScale;
go.transform.localScale = new Vector3(50, 50, 1);
iTween.ScaleTo(go,iTween.Hash("scale",startScale,"time",changeTime, "easetype",moveType));
}
//移动//
if(callBackObj != null){
iTween.MoveTo(go,iTween.Hash("position",startPos,"time",changeTime, "oncomplete", methodName,
"oncompletetarget", callBackObj, "easetype",iTween.EaseType.linear));
}
else {
iTween.MoveTo(go,iTween.Hash("position",startPos,"time",changeTime,"easetype",iTween.EaseType.linear));
}
}
对于角色的移动函数
public static void PlayMoveToAnim(GameObject go, Vector3 desPos, float time, GameObject callBackObj, string callBackMethod, float delayTime = 0.0f, UnityEngine.Object callBackParam = null){
if(callBackParam != null){
iTween.MoveTo(go,iTween.Hash("position",desPos,"time",time, "oncomplete", callBackMethod,
"oncompletetarget", callBackObj, "oncompleteparams", callBackParam, "delay", delayTime, "easetype", iTween.EaseType.linear));
}
else {
iTween.MoveTo(go,iTween.Hash("position",desPos,"time",time, "oncomplete", callBackMethod,
"oncompletetarget", callBackObj , "delay", delayTime, "easetype", iTween.EaseType.linear));
}
}
关于NGUI的淡入淡出的操作方法
/**封装淡入淡出方法--**/
public static void PlayTweenAlpha(GameObject go, float alphaFrom, float alphaTo, EventDelegate.Callback method, float time){
TweenAlpha tween = go.GetComponent<TweenAlpha>();
tween.from = alphaFrom;
tween.to = alphaTo;
Debug.LogError("PlayTweenAlpha for " + go.name);
TweenAlpha.Begin<TweenAlpha>(go, time);
if (tween.onFinished != null)
{
Debug.LogError("add onFinished callback " + method.ToString());
EventDelegate.Add(tween.onFinished, method);
}
}