Beispiel #1
0
        /// <summary>
        /// 从创建器复制数据
        /// </summary>
        /// <param name="simulator">创建器</param>
        public void CopyFromSimulator(Class_TrajectoryCreator simulator)
        {
            MoveType = simulator.MoveType;
            if (simulator.VelocityOrTimeSpend == null)
            {
                switch (MoveType)
                {
                case EnumTrajectoryMoveType.Velocity:
                    VelocityOrTimeSpend = Const_Trajectory.DefaultVelocity;
                    break;

                case EnumTrajectoryMoveType.SpentTime:
                    VelocityOrTimeSpend = Const_Trajectory.DefaultTimeSpand;
                    break;

                default:
                    throw new Exception();
                }
            }
            else
            {
                VelocityOrTimeSpend = simulator.VelocityOrTimeSpend;
            }
            Radius             = simulator.Radius != null ? simulator.Radius : Const_Trajectory.DefaultRadius;
            TrajectoryRotation = simulator.TrajectoryRotation != null ? simulator.TrajectoryRotation : Const_Trajectory.DefaultTrajectoryRotation;
            ProjectileRotation = simulator.ProjectileRotation != null ? simulator.ProjectileRotation : Const_Trajectory.DefaultProjectileRotation;
            ImpactEffect       = simulator.ImpactEffect;
            TargetObject       = simulator.TargetObject;
            AlwaysFaceTarget   = simulator.AlwaysFaceTarget;
            LifeTime           = simulator.LifeTime;
            TimeOfLostControl  = simulator.TimeOfLostControl;
            LaunchPos          = simulator.transform.position;
            mOriginalPos       = LaunchPos;
            mCreateTime        = Time.fixedTime;
        }
        /// <summary>
        /// 投射物移动
        /// </summary>
        /// <param name="moveType">移动类型</param>
        /// <param name="velocityOrPosCurve">速度或位置曲线</param>
        /// <param name="trajectoryRotationCurve">轨迹旋转曲线</param>
        /// <param name="radiusCurve">半径曲线</param>
        /// <param name="projectilerRotationCurve">投射物旋转曲线</param>
        /// <param name="time">移动时间</param>
        /// <param name="originalPos">投影点坐标</param>
        /// <param name="projectilePos">投射物坐标</param>
        /// <param name="launchPos">发射点坐标</param>
        /// <param name="targetPos">目标点坐标</param>
        /// <param name="alwaysFaceTarget">锁定投射物朝向到目标</param>
        /// <param name="lostControlTime">失控定时</param>
        public static bool Move(EnumTrajectoryMoveType moveType, AnimationCurve velocityOrPosCurve, AnimationCurve trajectoryRotationCurve, AnimationCurve radiusCurve, AnimationCurve projectilerRotationCurve, float time, ref Vector3 originalPos, ref Vector3 projectilePos, out Quaternion projectileRotation, Vector3 launchPos, Vector3 targetPos, bool alwaysFaceTarget, float lostControlTime)
        {
            bool hit;

            if (moveType == EnumTrajectoryMoveType.SpentTime || lostControlTime < 0 || time <= lostControlTime)
            {
                switch (moveType)
                {
                case EnumTrajectoryMoveType.Velocity:
                    hit = Move_Velocity(velocityOrPosCurve, time, ref originalPos, launchPos, targetPos);
                    break;

                case EnumTrajectoryMoveType.SpentTime:
                    hit = Move_SpentTime(velocityOrPosCurve, time, ref originalPos, launchPos, targetPos);
                    break;

                default:
                    throw new Exception();
                }
                if (hit)
                {
                    projectileRotation = new Quaternion();
                    return(true);
                }
                Move_UpdateProjectilePosAndRotation(trajectoryRotationCurve, radiusCurve, projectilerRotationCurve, time, originalPos, out projectilePos, out projectileRotation, launchPos, targetPos, alwaysFaceTarget);
            }
            else
            {
                Vector3 templaunchPos = projectilePos;
                hit = Move_Velocity(velocityOrPosCurve, time, ref projectilePos, templaunchPos, targetPos);
                if (hit)
                {
                    projectileRotation = new Quaternion();
                    return(true);
                }
                projectileRotation = Move_UpdateProjectileRotation(projectilerRotationCurve, time, projectilePos, launchPos, targetPos, alwaysFaceTarget);
            }
            return(false);
        }