/// <summary> /// 移动到指定位置 /// </summary> public void MoveByBezier(Vector3 position, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float dValRate, float duration, object paramObj) { cachePositon = position;//缓存起始坐标 this.dValRate = dValRate; durationTime = duration; Hashtable tweenParams = new Hashtable(cacheBezierTweenHashParam); tweenParams["from"] = dValRate; tweenParams["to"] = 1f; float maxDuration = duration; if (dValRate > 0) { maxDuration = maxDuration - dValRate * maxDuration; if (maxDuration < 0) { maxDuration = 0; } } tweenParams["time"] = maxDuration; cacheBezierPositon = new Vector3[4]; cacheBezierPositon[0] = p0; cacheBezierPositon[1] = p1; cacheBezierPositon[2] = p2; cacheBezierPositon[3] = p3; Vector3 beginPosition = cachePositon + MapUtil.CalculateTargetBezierPoint(dValRate, cacheBezierPositon[0], cacheBezierPositon[1], cacheBezierPositon[2], cacheBezierPositon[3]); transform.position = beginPosition; tweenParams["onstart"] = "OnBezierTweenStart"; if (paramObj != null) { tweenParams["onstartparams"] = paramObj; } tweenParams["onupdate"] = "OnBezierTweenUpdate"; if (paramObj != null) { tweenParams["onupdateparams"] = paramObj; } tweenParams["oncomplete"] = "OnBezierTweenComplete"; if (paramObj != null) { tweenParams["oncompleteparams"] = paramObj; } iTween.ValueTo(gameObject, tweenParams); runningDuration = 0f; }
private void DoOnBezierTweenUpdate(object param) { //Debug.Log("DoOnBezierTweenUpdate : " + param); //float t = tween.GetClampPercentage(); float t = Convert.ToSingle(param); Vector3 beginPosition = cachePositon + MapUtil.CalculateTargetBezierPoint(t, cacheBezierPositon[0], cacheBezierPositon[1], cacheBezierPositon[2], cacheBezierPositon[3]); transform.position = beginPosition; t = t + 0.01f; if (t > 1f) { t = 1f; } //SetAnimDirWithPos(nextPos,transform); if (tweenUpdateCallback != null) // just 优化 { runningDuration = -Time.unscaledDeltaTime; if (runningDuration <= 0f) { Vector3 nextPos = cachePositon + MapUtil.CalculateTargetBezierPoint(t, cacheBezierPositon[0], cacheBezierPositon[1], cacheBezierPositon[2], cacheBezierPositon[3]); runningDuration = updateInterval; //Quaternion quaternion = Quaternion.Euler(0, 0, MAP_ANGLE); //Vector3 dir2 = quaternion * (nextPos - transform.position); //Quaternion quaternion = Quaternion.Euler(0, 0, MAP_ANGLE); //float angel = 0; ////Vector3 dir2 = nextPos - transform.position; //Vector3 nextXProject = Vector3.ProjectOnPlane(nextPos, Vector3.forward); //Vector3 curXProject = Vector3.ProjectOnPlane(transform.position, Vector3.forward); //Quaternion quaternion = Quaternion.Euler(90, 0, -45); //if (nextXProject - curXProject != Vector3.zero) //{ // Vector3 myResutl = quaternion * (nextXProject - curXProject); // //tweenUpdateCallback(param, nextPos,transform.position, dir2, angel); // tweenUpdateCallback(param, myResutl, angel); //} tweenUpdateCallback(param, nextPos, transform.position, t); } } }