Пример #1
0
    public override void UpdateAct()
    {
        base.UpdateAct();

        if (setSoldierExactPos)
        {
            Vector3 newPos = Vector3.Lerp(controlledSoldier.position, machineGun.standPosTr.position, Time.deltaTime * 8);
            controlledSoldier.position = new Vector3(newPos.x, controlledSoldier.position.y, newPos.z);
        }

StartSteps:

        #region Start01
        if (step == ActMachineGunStep.Start01)
        {
            //if (IsSoldOnPos(machineGun.standPosTr.position))
            //{
            //    step = ActMachineGunStep.FirstSoldierRotation01;
            //    goto StartSteps;
            //}
            //else
            //{

            step = ActMachineGunStep.GoingToPos01;
            goto StartSteps;

            //}
        }
        #endregion

        #region GoingToPos01

        if (step == ActMachineGunStep.GoingToPos01)
        {
            movementAct = controlledSoldier.gameObject.AddComponent <SoldierAction_Movement>();
            movementAct.Init(controlledSoldier);
            movementAct.InitDefaultParams(currentMovementType);
            movementAct.Init_PosToFindPath(machineGun.standPosTr.position);
            movementAct.initialEnemies = initialEnemies;

            movementAct.SetNextActAnimToCrossfade(anim_SoldierOnMachineGun_Mid);
            movementAct.SetEndingRotNormal(machineGun.transform.forward);

            movementAct.StartAct();

            step = ActMachineGunStep.GoingToPos02;
        }
        #endregion

        #region GoingToPos02
        if (step == ActMachineGunStep.GoingToPos02)
        {
            if (needsToBeFinished)
            {
                step = ActMachineGunStep.Finishing_MovementAct01;
                goto StartSteps;
            }

            if (movementAct.finishReport == FinishReportEnum.FinishedOK)
            {
                Destroy(movementAct);

                step = ActMachineGunStep.WaitForFirstAnim;
                goto StartSteps;
            }
        }
        #endregion

        #region WaitForFirstAnim
        if (step == ActMachineGunStep.WaitForFirstAnim)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            if (soldInfo.IsFullyInNewMainAnim())
            {
                step = ActMachineGunStep.UsingMachineGun01_Init;
            }
        }
        #endregion

        #region UsingMachineGun01_Init
        if (step == ActMachineGunStep.UsingMachineGun01_Init)
        {
            machineGun.SetControllingSoldier(controlledSoldier.gameObject);

            setSoldierExactPos = true;

            StartAnims();

            machineGunShootCounter = machineGun.shootSpeed;

            ResetShootDuration();
            ResetIdleTime();

            step = ActMachineGunStep.UsingMachineGun02_Restart;
        }
        #endregion

        #region UsingMachineGun02_Restart
        if (step == ActMachineGunStep.UsingMachineGun02_Restart)
        {
            ReselectTarget();
            ResetLockTargetTime();
            ResetRecheckTargetTime();

            step = ActMachineGunStep.UsingMachineGun03_Using;
        }
        #endregion

        #region UsingMachineGun03_Using
        if (step == ActMachineGunStep.UsingMachineGun03_Using)
        {
            if (needsToBeFinished)
            {
                step = ActMachineGunStep.Finishing_UsingMachineGun01;
                goto EndSteps;
            }

            lockTargetCounter = MathfPlus.DecByDeltatimeToZero(lockTargetCounter);

            recheckTargetCounter = MathfPlus.DecByDeltatimeToZero(recheckTargetCounter);

            if (lockTargetCounter == 0)
            {
                step = ActMachineGunStep.UsingMachineGun02_Restart;
                return;
            }

            if (recheckTargetCounter == 0)
            {
                ResetRecheckTargetTime();

                if (!mapLogic.IsCharacterOkAsTarget(gameObject, target.character, machineGun.raycastStartTr.position, machineGun.transform.rotation, range, -maxAngle, maxAngle, out target))
                {
                    ReselectTarget();
                }
            }

            if (!isIdle)
            {
                shootDurationCounter = MathfPlus.DecByDeltatimeToZero(shootDurationCounter);

                if (shootDurationCounter == 0)
                {
                    ResetShootDuration();
                    isIdle = true;
                }
            }
            else
            {
                idleTimeCounter = MathfPlus.DecByDeltatimeToZero(idleTimeCounter);

                if (idleTimeCounter == 0)
                {
                    ResetIdleTime();
                    isIdle = false;
                }
            }

            bool needsToShoot = false;

            if (mapLogic.IsCharacterTotallyFightable(target.character))
            {
                if (GentlySetAngleToTarget())
                {
                    if (!isIdle)
                    {
                        needsToShoot = true;
                    }
                }
            }

            if (needsToShoot)
            {
                //machineGunShootCounter = MathfPlus.DecByDeltatimeToZero(machineGunShootCounter);

                //if (machineGunShootCounter == 0)
                //{
                //    machineGunShootCounter = machineGun.shootSpeed;
                if (machineGun.gun.IsReady())
                {
                    Vector3 targetFirePos;

                    List <Transform> okPoses;

                    if (target.isCharacterHitted)
                    {
                        okPoses = target.characterHittedPoses;
                    }
                    else
                    {
                        okPoses = target.haloHittedPoses;
                    }

                    if (okPoses.Count > 0)
                    {
                        targetFirePos = okPoses[Random.Range(0, okPoses.Count)].position;

                        machineGun.gun.TryFire(machineGun.shootPosTr.position, targetFirePos);

                        //Vector3 bulletDir = targetFirePos - machineGun.shootPosTr.position;

                        //GameObject bulObj = GameObject.Instantiate(machineGun.bullet.gameObject, machineGun.shootPosTr.position, Quaternion.LookRotation(bulletDir)) as GameObject;
                        //Bullet bul = bulObj.GetComponent<Bullet>();
                        //bul.InitBulletProp(bulletDir, gameObject);

                        ////soundPlay.PlaySound_FX(fireSound);
                    }
                }
                //}
            }

            SetActiveAnims();

            SetMachineGunRotatingObjectAngle();
        }
        #endregion

        #region Finishing_MovementAct01
        if (step == ActMachineGunStep.Finishing_MovementAct01)
        {
            movementAct.SetNeedsToBeFinished(evenStopMovingForFinish);
            step = ActMachineGunStep.Finishing_MovementAct02;
            goto EndSteps;
        }
        #endregion

        #region Finishing_MovementAct02
        if (step == ActMachineGunStep.Finishing_MovementAct02)
        {
            //<Alpha>
            if (needsToBeFinished)
            {
                movementAct.SetNeedsToBeFinished(evenStopMovingForFinish);
            }
            //</Alpha>

            if (movementAct.status == ActionStatusEnum.Finished)
            {
                SetFinished(false);
                return;
            }
        }
        #endregion

        #region Finishing_UsingMachineGun01
        if (step == ActMachineGunStep.Finishing_UsingMachineGun01)
        {
            machineGun.SetControllingSoldier(null);
            step = ActMachineGunStep.Finishing_UsingMachineGun02;
        }
        #endregion

        #region Finishing_UsingMachineGun02
        if (step == ActMachineGunStep.Finishing_UsingMachineGun02)
        {
            float endWeightSpeed = machineGun.endRotateTimeCoef;

            midWeight += Time.deltaTime * endWeightSpeed;
            midWeight  = Mathf.Clamp01(midWeight);

            leftWeight -= Time.deltaTime * endWeightSpeed;
            leftWeight  = Mathf.Clamp01(leftWeight);


            rightWeight -= Time.deltaTime * endWeightSpeed;
            rightWeight  = Mathf.Clamp01(rightWeight);

            if (midWeight == 1
                &&
                leftWeight == 0
                &&
                rightWeight == 0)
            {
                EndAnims();
                SetFinished(true);
                return;
            }
        }
        #endregion

        EndSteps :;
    }
Пример #2
0
    public override void StartAct()
    {
        base.StartAct();

        step = ActMachineGunStep.Start01;
    }