コード例 #1
0
        public vFSMState TransitTo(vIFSMBehaviourController fsmBehaviour)
        {
            var       val        = true;
            vFSMState returState = null;

            for (int i = 0; i < decisions.Count; i++)
            {
                bool value = decisions[i].Validate(fsmBehaviour);

                if (!value)
                {
                    val = false;
                }
            }
            if (val && trueState)
            {
                returState = useTruState && !muteTrue ? trueState : null;
            }
            else if (!val && falseState)
            {
                returState = useFalseState && !muteFalse ? falseState : null;
            }

            if (transitionTimers == null)
            {
                transitionTimers = new Dictionary <vIFSMBehaviourController, float>();
            }
            if (!transitionTimers.ContainsKey(fsmBehaviour))
            {
                transitionTimers.Add(fsmBehaviour, 0f);
            }

            if (transitionTimers[fsmBehaviour] < transitionDelay && returState)
            {
                transitionTimers[fsmBehaviour] += Time.deltaTime;
                if (fsmBehaviour.debugMode)
                {
                    fsmBehaviour.SendDebug("<color=green>" + parentState.name + " Delay " + (transitionDelay - transitionTimers[fsmBehaviour]).ToString("00") + " To Enter in " + returState.Name + "</color>", parentState);
                }
                return(null);
            }
            else
            {
                transitionTimers[fsmBehaviour] = 0;
                if (fsmBehaviour.debugMode && returState)
                {
                    fsmBehaviour.SendDebug("<color=yellow>" + parentState.name + " Transited to " + returState.name + "</color>", parentState);
                }
            }
            return(returState);
        }
コード例 #2
0
ファイル: vAICheckDamage.cs プロジェクト: nerodroid/dog_game
        protected virtual bool HasDamage(vIFSMBehaviourController fsmBehaviour)
        {
            if (fsmBehaviour.aiController == null)
            {
                return(false);
            }
            var hasDamage = (fsmBehaviour.aiController.receivedDamage.isValid) && (damageTypeToCheck.Count == 0 || damageTypeToCheck.Contains(fsmBehaviour.aiController.receivedDamage.lasType));

            if (fsmBehaviour.debugMode)
            {
                fsmBehaviour.SendDebug(Name + " " + (fsmBehaviour.aiController.receivedDamage.isValid) + " " + fsmBehaviour.aiController.receivedDamage.lastSender, this);
            }

            return(hasDamage);
        }
コード例 #3
0
        protected virtual void DoPatrolWaypoints(vIFSMBehaviourController fsmBehaviour)
        {
            if (fsmBehaviour == null)
            {
                return;
            }
            if (fsmBehaviour.aiController.isDead)
            {
                return;
            }

            if (fsmBehaviour.aiController.waypointArea != null && fsmBehaviour.aiController.waypointArea.waypoints.Count > 0)
            {
                if (fsmBehaviour.aiController.targetWaypoint == null || !fsmBehaviour.aiController.targetWaypoint.isValid)
                {
                    fsmBehaviour.aiController.NextWayPoint();
                }
                else
                {
                    if (Vector3.Distance(fsmBehaviour.aiController.transform.position, fsmBehaviour.aiController.targetWaypoint.position) <
                        fsmBehaviour.aiController.stopingDistance + fsmBehaviour.aiController.targetWaypoint.areaRadius + fsmBehaviour.aiController.changeWaypointDistance &&
                        fsmBehaviour.aiController.targetWaypoint.CanEnter(fsmBehaviour.aiController.transform) &&
                        !fsmBehaviour.aiController.targetWaypoint.IsOnWay(fsmBehaviour.aiController.transform))
                    {
                        fsmBehaviour.aiController.targetWaypoint.Enter(fsmBehaviour.aiController.transform);
                    }
                    else if (Vector3.Distance(fsmBehaviour.aiController.transform.position, fsmBehaviour.aiController.targetWaypoint.position) <
                             fsmBehaviour.aiController.stopingDistance + fsmBehaviour.aiController.targetWaypoint.areaRadius &&
                             (!fsmBehaviour.aiController.targetWaypoint.CanEnter(fsmBehaviour.aiController.transform) ||
                              !fsmBehaviour.aiController.targetWaypoint.isValid))
                    {
                        fsmBehaviour.aiController.NextWayPoint();
                    }

                    if (fsmBehaviour.aiController.targetWaypoint != null &&
                        fsmBehaviour.aiController.targetWaypoint.IsOnWay(fsmBehaviour.aiController.transform) &&
                        Vector3.Distance(fsmBehaviour.aiController.transform.position, fsmBehaviour.aiController.targetWaypoint.position) <=
                        fsmBehaviour.aiController.targetWaypoint.areaRadius + fsmBehaviour.aiController.changeWaypointDistance)
                    {
                        if (fsmBehaviour.aiController.remainingDistance <= (fsmBehaviour.aiController.stopingDistance + fsmBehaviour.aiController.changeWaypointDistance) || fsmBehaviour.aiController.isInDestination)
                        {
                            var timer = fsmBehaviour.GetTimer("Patrol");
                            if (timer >= fsmBehaviour.aiController.targetWaypoint.timeToStay || !fsmBehaviour.aiController.targetWaypoint.isValid)
                            {
                                fsmBehaviour.aiController.targetWaypoint.Exit(fsmBehaviour.aiController.transform);
                                fsmBehaviour.aiController.visitedWaypoints.Clear();
                                fsmBehaviour.aiController.NextWayPoint();
                                if (debugMode)
                                {
                                    Debug.Log("Sort new Waypoint");
                                }
                                fsmBehaviour.aiController.Stop();
                                fsmBehaviour.SetTimer("Patrol", 0);
                            }
                            else if (timer < fsmBehaviour.aiController.targetWaypoint.timeToStay)
                            {
                                if (debugMode)
                                {
                                    Debug.Log("Stay");
                                }
                                if (fsmBehaviour.aiController.targetWaypoint.rotateTo)
                                {
                                    fsmBehaviour.aiController.Stop();
                                    fsmBehaviour.aiController.RotateTo(fsmBehaviour.aiController.targetWaypoint.transform.forward);
                                }
                                else
                                {
                                    fsmBehaviour.aiController.Stop();
                                }

                                fsmBehaviour.SetTimer("Patrol", timer + Time.deltaTime);
                            }
                        }
                    }
                    else
                    {
                        fsmBehaviour.aiController.SetSpeed(patrolSpeed);
                        fsmBehaviour.aiController.MoveTo(fsmBehaviour.aiController.targetWaypoint.position);
                        if (debugMode)
                        {
                            Debug.Log("Go to new Waypoint");
                        }
                    }
                }
            }
            else if (fsmBehaviour.aiController.selfStartingPoint)
            {
                if (fsmBehaviour.debugMode)
                {
                    fsmBehaviour.SendDebug("MoveTo SelfStartPosition", this);
                }
                fsmBehaviour.aiController.MoveTo(fsmBehaviour.aiController.selfStartPosition);
            }
            else if (fsmBehaviour.aiController.customStartPoint)
            {
                if (fsmBehaviour.debugMode)
                {
                    fsmBehaviour.SendDebug("MoveTo CustomStartPosition", this);
                }
                fsmBehaviour.aiController.MoveTo(fsmBehaviour.aiController.customStartPosition);
            }
            else
            {
                if (fsmBehaviour.debugMode)
                {
                    fsmBehaviour.SendDebug("Stop Patrolling", this);
                }
                fsmBehaviour.aiController.Stop();
            }
        }