コード例 #1
0
 public override void Execute(StateMachine obj)
 {
     Debug.Log("Execute: " + this.GetType().Name + "  Time: " + Time.time);
     obj.controller.HealNow();
     if (obj.environment.enabled)
     {
         obj.ChangeState(obj.previousState);
     }
     else
     {
         obj.ChangeState(DeadState.GetInstance());
     }
 }
コード例 #2
0
        public override void OnUpdate(StateMachine machine, GameObject gameObject)
        {
            var agent = gameObject.GetComponent <NavMeshAgent> ();

            if (agent == null)
            {
                return;
            }

            var resourceGatherer = gameObject.GetComponent <ResourceGatherer> ();
            var dist             = Vector3.Distance(agent.transform.position, agent.destination);

            if (dist <= resourceGatherer.reachDistance)
            {
                var agentContainer  = gameObject.GetComponent <ResourceContainer> ();
                var targetContainer = resourceGatherer.LastDiscoveredWarehouse.GetComponent <ResourceContainer> ();

                if (agentContainer == null || targetContainer == null)
                {
                    machine.ChangeState(GoHomeState.Instance);
                    return;
                }

                resourceGatherer.ResourceBuffer += resourceGatherer.unloadSpeed * Time.deltaTime;

                if (resourceGatherer.ResourceBuffer >= 1.0)
                {
                    var integerAmount = Mathf.FloorToInt(resourceGatherer.ResourceBuffer);
                    resourceGatherer.ResourceBuffer -= Mathf.Floor(resourceGatherer.ResourceBuffer);
                    Transaction.Perform(agentContainer, targetContainer, resourceGatherer.currentResourceType, integerAmount);
                }

                if (agentContainer.Count(resourceGatherer.currentResourceType) == 0)
                {
                    machine.ChangeState(GatherResourcesState.Instance);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// 检查条件是否满足
 /// </summary>
 public void CheckState(StateMachine stateMachine)
 {
     foreach (var trigger in triggerList)
     {
         // 判断条件是否满足
         if (trigger.Predicate(stateMachine))
         {
             // 从映射表中取出状态编号
             Enum stateID = transitions[trigger.TriggerID];
             // 切换状态
             stateMachine.ChangeState(stateID);
             return;
         }
     }
 }
コード例 #4
0
ファイル: GoHomeState.cs プロジェクト: dgarcia202/grassworld
        public override void OnUpdate(StateMachine machine, GameObject gameObject)
        {
            var agent = gameObject.GetComponent <NavMeshAgent> ();

            if (agent == null)
            {
                return;
            }

            var dist = Vector3.Distance(agent.transform.position, agent.destination);

            if (dist <= 1.5f)
            {
                machine.ChangeState(GatherResourcesState.Instance);
            }
        }
コード例 #5
0
        public override void Execute(StateMachine obj)
        {
            AgentState s = obj.controller.GetState();

               // s.AttackTarget = GameObject.Find("AttTarget");

            GameObject t = obj.FindClosestEnemy();
            float d = Vector3.Distance(obj.agent.transform.position, t.transform.position);

            Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position);
            if (d > 20)
            {

                obj.ChangeState(RoamState.GetInstance());
            }
        }
コード例 #6
0
ファイル: ChaseState.cs プロジェクト: valentincr/MCP20132014
 public override void Execute(StateMachine obj)
 {
     GameObject t = obj.FindClosestEnemy();
     float d = Vector3.Distance(obj.agent.transform.position, t.transform.position);
     if (obj.controller.GetState().AttackTarget == null || obj.controller.GetState().CurrentAttackType == -1)
     {
         obj.controller.SetAttack(AgentAttack.MEDIUM_RANGE);
         obj.controller.SetAttackTarget(t);
     }
     if (d < obj.controller.GetState().attackTypes[obj.controller.GetState().CurrentAttackType].range/2.0f)
     {
         obj.controller.GetState().Moving = false;
     }
     else if (d>30)
     {
         obj.controller.SetAttackTarget(null);
         obj.controller.SetAttack(-1);
         obj.ChangeState(InitialState.GetInstance());
     }
 }
コード例 #7
0
ファイル: RoamState.cs プロジェクト: valentincr/MCP20132014
        public override void Execute(StateMachine obj)
        {
            AgentState s = obj.controller.GetState();

            if (s.CurrentPath != null && s.CurrentPath.IsDone())
            {
                obj.controller.GetState().Moving = true;
            }

               // s.AttackTarget = GameObject.Find("AttTarget");

            GameObject t = obj.FindClosestEnemy();
            obj.controller.SetMovementTarget(t.transform);

            float d = Vector3.Distance(obj.agent.transform.position, t.transform.position);

            Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position);
            if (d <= 20 )
            {
                int layer = 1 << 9;
                if (!Physics.Raycast(obj.agent.transform.position, (t.transform.position-obj.agent.transform.position)/d,d,layer))
                    obj.ChangeState(ChaseState.GetInstance());
            }
        }
コード例 #8
0
        private void StatesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            State selectedState = (State)statesDropDown.SelectedItem;

            sm.ChangeState(selectedState);
        }
コード例 #9
0
 protected void GoToNextState(string typeName)
 {
     StateMachine.ChangeState(typeName);
 }
コード例 #10
0
 private void Start()
 {
     stateMachine.ChangeState(GetFirstState());
 }
コード例 #11
0
 protected void ChangeState(State <T> newState)
 {
     parent.ChangeState(newState);
 }