Ejemplo n.º 1
0
 private void FixedUpdate()
 {
     if (!IsControlling.IsNull() && IsControlling.BoolData())
     {
         CamUpdate();
     }
     if (isFollowCam)
     {
         CamFollow();
     }
 }
Ejemplo n.º 2
0
        protected void Update()
        {
#if UNITY_EDITOR
            //调试所用代码
            if (Input.GetKeyDown(KeyCode.F1))
            {
                IsControlling.SetData(currentContext, !IsControlling.BoolData());
            }
            if (Input.GetKeyDown(KeyCode.F2))
            {
                ActiveBall("BallWood");
            }
            if (Input.GetKeyDown(KeyCode.F3))
            {
                ActiveBall("BallStone");
            }
            if (Input.GetKeyDown(KeyCode.F4))
            {
                ActiveBall("BallPaper");
            }
            if (Input.GetKeyDown(KeyCode.F5))
            {
                PlayLighting(true, true);
            }
            if (Input.GetKeyDown(KeyCode.F6))
            {
                ThrowPieces("BallWood");
            }
            if (Input.GetKeyDown(KeyCode.F7))
            {
                RecoverPieces("BallWood");
            }
            if (Input.GetKeyDown(KeyCode.F8))
            {
                ThrowPieces("BallPaper");
            }
#endif

            //闪电球
            if (lighing)
            {
                if (Ball_LightningSphere.transform.localEulerAngles.z > 360f)
                {
                    Ball_LightningSphere.transform.localEulerAngles = new Vector3(0, 0, 0);
                }
                if (Ball_LightningSphere2.transform.localEulerAngles.z > 360f)
                {
                    Ball_LightningSphere2.transform.localEulerAngles = new Vector3(0, 0, 0);
                }
                Ball_LightningSphere.transform.localEulerAngles  = new Vector3(-90, Ball_LightningSphere.transform.localEulerAngles.y - ballLightingRoateSpeed1 * Time.deltaTime, 0);
                Ball_LightningSphere2.transform.localEulerAngles = new Vector3(-90, Ball_LightningSphere2.transform.localEulerAngles.y + ballLightingRoateSpeed2 * Time.deltaTime, 0);

                //更换闪电球贴图
                if (secxx < 0.1f)
                {
                    secxx += Time.deltaTime;
                }
                else
                {
                    if (currentBallLightningSphereTexture >= 3)
                    {
                        currentBallLightningSphereTexture = 1;
                    }
                    else
                    {
                        currentBallLightningSphereTexture++;
                    }
                    switch (currentBallLightningSphereTexture)
                    {
                    case 1:
                        ballLightningSphereMaterial.mainTexture  = ballLightningSphere1;
                        ballLightningSphereMaterial2.mainTexture = ballLightningSphere2;
                        break;

                    case 2:
                        ballLightningSphereMaterial.mainTexture  = ballLightningSphere2;
                        ballLightningSphereMaterial2.mainTexture = ballLightningSphere3;
                        break;

                    case 3:
                        ballLightningSphereMaterial.mainTexture  = ballLightningSphere3;
                        ballLightningSphereMaterial2.mainTexture = ballLightningSphere1;
                        break;
                    }
                    secxx = 0;
                }
            }
            //闪电球 放大
            if (lighingBig)
            {
                if (lighingLightBigTick < ballLightBallBigSec)
                {
                    lighingLightBigTick += Time.deltaTime;

                    float v = ballLightningBallBigCurve.Evaluate(lighingLightBigTick / ballLightBallBigSec);

                    Ball_LightningSphere.transform.localScale  = new Vector3(v, v, v);
                    Ball_LightningSphere2.transform.localScale = new Vector3(v, v, v);
                }
                else
                {
                    Ball_LightningSphere.transform.localScale  = new Vector3(1f, 1f, 1f);
                    Ball_LightningSphere2.transform.localScale = new Vector3(1f, 1f, 1f);
                    lighingBig = false;
                }
            }
            //闪电light
            if (lighingLight)
            {
                lighingLightTick += Time.deltaTime;
                Ball_Light.color  = new Color(Ball_Light.color.r, Ball_Light.color.g,
                                              ballLightningCurve.Evaluate(lighingLightTick / ballLightSec));
                if (lighingLightTick > ballLightSec)
                {
                    lighingLightEndTick = 0;
                    lighingLightEnd     = true;
                    lighingLight        = false;
                }
            }
            //闪电light
            if (lighingLightEnd)
            {
                float v = ballLightningCurveEnd.Evaluate(lighingLightEndTick / ballLightEndSec);
                lighingLightEndTick += Time.deltaTime;
                Ball_Light.color     = new Color(v, v, v);
                if (lighingLightEndTick > ballLightEndSec)
                {
                    Ball_Lightning.SetActive(false);
                    lighingLightEnd = false;
                }
            }
            //平滑移动
            if (isBallSmoothMove)
            {
                if (currentBall != null)
                {
                    currentBall.transform.position = Vector3.SmoothDamp(currentBall.transform.position, ballSmoothMoveTarget, ref ballSmoothMoveVelocityTarget, ballSmoothMoveTime);
                    if (currentBall.transform.position == ballSmoothMoveTarget)
                    {
                        isBallSmoothMove = false;
                    }
                }
                else
                {
                    isBallSmoothMove = false;
                }
            }
            //球碎片回收
            if (piecesThrowedBalls.Count > 0)
            {
                CollectPiecesTick();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 推动
        /// </summary>
        public virtual void BallPush()
        {
            if (IsControlling.BoolData())
            {
                FinalPushForceVectorFB = Vector3.zero;
                FinalPushForceVectorLR = Vector3.zero;
                pushPositionLocal.x    = transform.position.x + PushForcePosition.x;
                pushPositionLocal.y    = transform.position.y + PushForcePosition.y;
                pushPositionLocal.z    = transform.position.z + PushForcePosition.z;

                //获取 ballsManager 的球推动类型。
                BallPushType currentBallPushType = PushType.Data <BallPushType>();
                if (currentBallPushType != BallPushType.None)
                {
                    if ((currentBallPushType & BallPushType.Forward) == BallPushType.Forward)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorFB = Quaternion.AngleAxis(-PushForceDownAngle, thisVector3Left.Vector3Data()) *
                                                     thisVector3Forward.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorFB = thisVector3Forward.Vector3Data() * PushForce;
                        }
                    }
                    else if ((currentBallPushType & BallPushType.Back) == BallPushType.Back)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorFB = Quaternion.AngleAxis(PushForceDownAngle, thisVector3Left.Vector3Data()) *
                                                     thisVector3Back.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorFB = thisVector3Back.Vector3Data() * PushForce;
                        }
                    }
                    if ((currentBallPushType & BallPushType.Left) == BallPushType.Left)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorLR = Quaternion.AngleAxis(PushForceDownAngle, thisVector3Forward.Vector3Data()) *
                                                     thisVector3Left.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorLR = thisVector3Left.Vector3Data() * PushForce;
                        }
                    }
                    else if ((currentBallPushType & BallPushType.Right) == BallPushType.Right)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorLR = Quaternion.AngleAxis(-PushForceDownAngle, thisVector3Forward.Vector3Data()) *
                                                     thisVector3Right.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorLR = thisVector3Right.Vector3Data() * PushForce;
                        }
                    }

                    if (FinalPushForceVectorFB != Vector3.zero)
                    {
                        Rigidbody.AddForceAtPosition(FinalPushForceVectorFB, pushPositionLocal, ForceMode);
                    }
                    if (FinalPushForceVectorLR != Vector3.zero)
                    {
                        Rigidbody.AddForceAtPosition(FinalPushForceVectorLR, pushPositionLocal, ForceMode);
                    }

                    //调试模式可以上下飞行
                    if (IsBallDebug.BoolData())
                    {
                        if ((currentBallPushType & BallPushType.Up) == BallPushType.Up) //上
                        {
                            Rigidbody.AddForce(Vector3.up * PushUpForce, ForceMode);
                        }
                        else if ((currentBallPushType & BallPushType.Down) == BallPushType.Down)    //下
                        {
                            Rigidbody.AddForce(Vector3.down * PushForce * 0.5f, ForceMode);
                        }
                    }
                }

                if (FallForce > 0 && (currentBallPushType & BallPushType.Up) != BallPushType.Up)
                {
                    Rigidbody.AddForce(Vector3.down * FallForce, ForceMode);
                }

                //Y轴移动最大速度(这个用来模拟下落空气阻力)
                if (MaxSpeedY > 0)
                {
                    float speedOut = Mathf.Abs(Rigidbody.velocity.y) - Mathf.Abs(MaxSpeedY);
                    if (speedOut > 0)
                    {
                        float force = (speedOut / MaxSpeedYCurrctRatio) * MaxSpeedYForceMax;
                        Rigidbody.AddForce((Rigidbody.velocity.y < 0 ? (Vector3.up) : Vector3.down) *
                                           (force + (Rigidbody.velocity.y < 0 ? FallForce : 0)),
                                           ForceMode);
                    }
                }

                //XZ轴移动最大速度(这个用来模拟移动空气阻力)
                if (MaxSpeedXZ > 0)
                {
                    float speedOutXZ = Mathf.Sqrt(Mathf.Pow(Rigidbody.velocity.x, 2) +
                                                  Mathf.Pow(Rigidbody.velocity.z, 2)) - Mathf.Abs(MaxSpeedXZ);
                    if (speedOutXZ > 0)
                    {
                        float force = (speedOutXZ / MaxSpeedXZCurrctRatio) * MaxSpeedXZForceMax;
                        pushVectorReverse.x = -Rigidbody.velocity.x;
                        pushVectorReverse.z = -Rigidbody.velocity.z;
                        Rigidbody.AddForce(pushVectorReverse * force, ForceMode);
                    }
                }
            }
        }