Exemplo n.º 1
0
 //通用运动驱动函数
 public void Move(float current_time, float speed_rate, float delta_time)      //接口方法
 {
     if (TimeRate(current_time) > 1.001f || current_time > EndTime)
     {
         return;
     }
     else
     {
         lastFrameTime = current_time;
     }
     if (CurrentMotion == MotionType.MoveOnly)
     {
         //匀速直线运动
         ParentTrans.Translate(SpeedVector * delta_time * speed_rate, Space.Self);
     }
     else if (CurrentMotion == MotionType.WorldMove)
     {
         //在世界坐标内移动
         ParentTrans.Translate(SpeedVector * delta_time * speed_rate, Space.World);
     }
     else if (CurrentMotion == MotionType.AccelerateMove)
     {
         //匀加速直线运动
         ParentTrans.localPosition = StartPos + SpeedVector * (current_time - StartTime) * speed_rate +
                                     0.5f * AccelerateVec * ((current_time - StartTime) * speed_rate) * ((current_time - StartTime) * speed_rate);
     }
     else if (CurrentMotion == MotionType.RotateOnly)
     {
         //旋转运动
         ParentTrans.RotateAround(RotateCenter, RotateAxis, RotateSpeed * delta_time * speed_rate);
     }
     else if (CurrentMotion == MotionType.MoveRotateSingle)
     {
         //平移+旋转,围绕某一个
         if (SpeedVector != Vector3.zero)
         {
             EmptyObj.transform.Translate(SpeedVector * delta_time * SpeedRate, Space.World);
         }
         EmptyObj.transform.Rotate(RotateAxis * RotateSpeed * delta_time * SpeedRate, Space.Self);
     }
     else if (CurrentMotion == MotionType.MoveRotateEvery)
     {
         //平移+旋转,围绕各自
         if (SpeedVector != Vector3.zero)
         {
             EmptyObj.transform.Translate(SpeedVector * delta_time * SpeedRate, Space.World);
         }
         for (int i = 0; i < ChildList.Count; i++)
         {
             ChildList[i].Rotate(RotateAxis * RotateSpeed * delta_time * SpeedRate, Space.Self);
         }
     }
     else if (CurrentMotion == MotionType.RandomMotion)
     {
         //任意移动
         if (SpeedVector != Vector3.zero)
         {
             ParentTrans.position = StartPos + SpeedVector * (current_time - StartTime) * speed_rate;
         }
         if (AngleVector != Vector3.zero)
         {
             ParentTrans.eulerAngles = StartEurler + AngleVector * (current_time - StartTime) * speed_rate;
         }
     }
     else if (CurrentMotion == MotionType.VisualPath)
     {
         //可视化路径移动
         ParentTrans.position    = crSpline.Interp(TimeRate(current_time));
         ParentTrans.eulerAngles = crSpline.EulerAngleLerp(TimeRate(current_time), ref currentIndex, ref viewTimeRate);
     }
 }
Exemplo n.º 2
0
 //运动
 public void Move(float current_time, float speed_rate, float delta_time)
 {
     if (TimeRate(current_time) > 1.001f || current_time > EndTime)
     {
         return;
     }
     else
     {
         lastFrameTime = current_time;
     }
     if (CurrentMotion == CameraMotionType.Line)          //直线
     {
         CurrentCamera.transform.position = StartPos + SpeedVector * (current_time - StartTime) * speed_rate;
         if (HasSizeChange)
         {
             SetCameraPortValue(StartSize + SizeSpeed * (current_time - StartTime) * speed_rate);
         }
         if (needExcess)
         {
             if (TimeRate(current_time) <= 0.1f)
             {
                 CurrentCamera.transform.eulerAngles = Vector3.Lerp(diffVector[0], diffVector[1], TimeRate(current_time) * 10f);
             }
             else
             {
                 CurrentCamera.transform.LookAt(TargetTrans);
             }
         }
         else
         {
             CurrentCamera.transform.LookAt(TargetTrans);
         }
     }
     else if (CurrentMotion == CameraMotionType.Circular)  //圆弧
     {
         CurrentCamera.transform.RotateAround(RotateCenter, RotateAxis, RotateSpeed * delta_time * speed_rate);
         if (HasSizeChange)
         {
             SetCameraPortValue(StartSize + SizeSpeed * (current_time - StartTime) * speed_rate);
         }
         CurrentCamera.transform.LookAt(TargetTrans);
     }
     else  //可视化路径运动
     {
         CurrentCamera.transform.position = crSpline.Interp(TimeRate(current_time));
         if (TargetTrans != null)
         {
             if (needExcess)
             {
                 if (TimeRate(current_time) <= 0.1f)
                 {
                     CurrentCamera.transform.eulerAngles = Vector3.Lerp(diffVector[0], diffVector[1], TimeRate(current_time) * 10f);
                 }
                 else
                 {
                     CurrentCamera.transform.LookAt(TargetTrans);
                 }
             }
             else
             {
                 CurrentCamera.transform.LookAt(TargetTrans);
             }
             SetCameraPortValue(crSpline.ViewLerp(TimeRate(current_time)));
         }
         else
         {
             CurrentCamera.transform.eulerAngles = crSpline.EulerAngleLerp(TimeRate(current_time), ref currentIndex, ref viewTimeRate);
             //二分法查找算一次
             SetCameraPortValue(Mathf.Lerp(crSpline.cameraViewList[currentIndex], crSpline.cameraViewList[currentIndex + 1], viewTimeRate));
         }
     }
 }