Beispiel #1
0
    private void Start()
    {
        // 委派 指定 方法
        soldierAction  = soldierA.Defence;
        soldierAction += soldierB.Walk;
        soldierAction -= soldierA.Defence;
        soldierAction += soldierA.Walk;
        soldierAction += soldierA.Attack;

        soldierAdd = soldierA.AddHp;

        // 匿名函式 Lambda
        soldierAction += () => Debug.Log("所有動作執行結束。");
        soldierAdd    += (x) =>
        {
            x = 10;
            Debug.Log(x);
        };

        soldierAction += () =>
        {
            Debug.Log("測試1");
            Debug.Log("測試2");
            Debug.Log("測試3");
        };

        // 執行委派
        soldierAction();
        soldierAdd(999);
    }
Beispiel #2
0
    void Update()
    {
        if (!isFirstZocMoveDone)
        {
            charController.SimpleMove(new Vector3(0, 0, 0));

            zocMoveCount--;

            if (zocMoveCount == 0)
            {
                isFirstZocMoveDone = true;
            }
        }

        if (isStopping)
        {
            SoldierAction curAct = gameObject.GetComponent <SoldierAction>();

            if (curAct != null)
            {
                Destroy(curAct);
            }
            else
            {
                //removingCurActCounter++;

                //if (removingCurActCounter >= 5)
                //{

                //removingCurActCounter = 0;

                charController.enabled = false;

                body.SetActiveRecursively(false);

                Renderer[] rends = gameObject.GetComponentsInChildren <Renderer>();

                for (int i = 0; i < rends.Length; i++)
                {
                    rends[i].enabled = false;
                }

                gameObject.active = false;

                isStopping = false;

                //}
            }
        }

        DecAnimCounters();

        voiceBusyTimeCounter -= Time.deltaTime;
        voiceBusyTimeCounter  = Mathf.Clamp(voiceBusyTimeCounter, 0, 1000);

        voiceLengthCounter = MathfPlus.DecByDeltatimeToZero(voiceLengthCounter);

        time_UpdatePlayerInCriticSitu_Counter = MathfPlus.DecByDeltatimeToZero(time_UpdatePlayerInCriticSitu_Counter);
        time_PlayerInCriticSitu_Counter       = MathfPlus.DecByDeltatimeToZero(time_PlayerInCriticSitu_Counter);
        forceAttackPlayerTimeCounter          = MathfPlus.DecByDeltatimeToZero(forceAttackPlayerTimeCounter);

        if (needsToUpdatePlayerCriticSitu)
        {
            UpdatePlayerCriticState();
        }

        bool isSlowlyUpdated = false;

        if (needsToSlowlyUpdatePlayerCriticSitu)
        {
            SlowlyUpdatePlayerCriticState();
            isSlowlyUpdated = true;
        }

        if (time_PlayerInCriticSitu_Counter > 0)
        {
            if (!isSlowlyUpdated)
            {
                SlowlyUpdatePlayerCriticState();
            }
        }
        else
        {
            SetPlayerIsInCriticSitu(false);
        }

        needsToUpdatePlayerCriticSitu       = false;
        needsToSlowlyUpdatePlayerCriticSitu = false;

        if (isDamageRecievedInThisRun)
        {
            if (Time.time > recievedDamageTime)
            {
                isDamageRecievedInThisRun = false;
                damagesRecieved.Clear();
                firstDamage = null;
            }
        }

        gentlyGetUnderFootSurfaceMaterial_TimeCounter = MathfPlus.DecByDeltatimeToZero(gentlyGetUnderFootSurfaceMaterial_TimeCounter);
    }
 void SetCurrentAction(SoldierAction _act)
 {
     currentAction = _act;
 }
Beispiel #4
0
 void Awake()
 {
     if (!fireAction)
     {
         fireAction = gameObject.AddComponent<SoldierAction>();
         fireAction.characterAnimation = characterAnimation;
         fireAction.animationName = "fire";
         fireAction.character = character2D;
         fireAction.actionCommandControl = actionCommandControl;
         fireAction.canChangeFace = true;
         fireAction.canMove = false;
         fireAction.init();
     }
     fireAction.commandValue = UnitActionCommand.fireCommand;
     if (!action1)
         action1 = gameObject.AddComponent<SoldierAction>();
     if (!action2)
         action2 = gameObject.AddComponent<SoldierAction>();
     action1.commandValue = UnitActionCommand.action1Command;
     action2.commandValue = UnitActionCommand.action2Command;
     actionCommandControl.addCommandChangedReciver(OnCommand);
 }
Beispiel #5
0
    //更新动画
    void Update()
    {
        UnitActionCommand lActionCommand = actionCommandControl.getCommand();
        if (life.isAlive())
        {
            if (actionCommandControl.updateFace())
                UpdateFaceShow();

            //if (nowAction && (lActionCommand.command & nowAction.commandValue) == 0)
            if (nowAction && !nowAction.inActing)
            {
                nowAction = null;
            }
            if (nowAction)
            {
                nowAction.processCommand(lActionCommand);
            }
            else if (lActionCommand.Fire)
            {
                nowAction = fireAction;
            }
            else if (lActionCommand.Action1)
            {
                nowAction = action1;
            }
            else if (lActionCommand.Action2)
            {
                nowAction = action2;
            }
            else
            {
                ////设置动画 动作
                //if (lActionCommand.Fire)
                //{
                //    characterAnimation.CrossFade("fire", 0.2f);
                //}
                //else
                //{
                if (lActionCommand.GoForward)
                {
                    characterAnimation.CrossFade("run", 0.1f);
                }
                else
                {
                    characterAnimation.CrossFade("stand", 0.2f);
                }

                //}

                if (lActionCommand.Jump && lActionCommand.FaceDown)
                {
                    boardDetector.down();
                }
                else
                    boardDetector.recover();

            }

        }
        else
            nowAction = null;

        character2D.update2D(lActionCommand, actionCommandControl.getFaceValue(), life.isAlive());
    }