Exemple #1
0
 void Start()
 {
     traits    = GetComponent <Traits>();
     agent     = GetComponent <NavMeshAgent>();
     stats     = GetComponent <status>();
     sightings = GetComponentInChildren <InSight>();
 }
Exemple #2
0
    override protected void Start()
    {
        root          = new Sequence();
        seqDeath      = new Sequence();
        seqChase      = new Sequence();
        seqAttack     = new Sequence();
        selMove       = new Selector();
        selChase      = new Selector();
        patrol        = new Patrol(this);
        isDead        = new IsDead(this);
        death         = new Death(this);
        inSight       = new InSight(this);
        chase         = new Chase(this);
        isDamaged     = new IsDamaged(this);
        inAttackRange = new InAttackRange(this);
        attack        = new Attack(this);

        base.Start();
        Init();
        StartCoroutine("BehaviorProcess");
    }
Exemple #3
0
    public List <T> Run(T start, Satisfies satisfies, GetNeighbours getNeighbours, GetCost getcost, Heuristic heuristic, InSight inSight, int watchDong = 500)
    {
        Dictionary <T, float> cost    = new Dictionary <T, float>();
        Dictionary <T, T>     parents = new Dictionary <T, T>();
        PriorityQueue <T>     pending = new PriorityQueue <T>();
        HashSet <T>           visited = new HashSet <T>();

        pending.Enqueue(start, 0);
        cost.Add(start, 0);
        while (!pending.IsEmpty)
        {
            T current = pending.Dequeue();
            watchDong--;
            if (watchDong <= 0)
            {
                return(new List <T>());
            }
            if (satisfies(current))
            {
                return(ConstructPath(current, parents));
            }
            visited.Add(current);
            List <T> neighbours = getNeighbours(current);
            for (int i = 0; i < neighbours.Count; i++)
            {
                T node = neighbours[i];
                if (visited.Contains(node))
                {
                    continue;
                }
                T currParent;
                if (parents.ContainsKey(current) && inSight(parents[current], node))
                {
                    currParent = parents[current];
                }
                else
                {
                    currParent = current;
                }
                float nodeCost  = getcost(currParent, node);
                float totalCost = cost[currParent] + nodeCost;
                if (cost.ContainsKey(node) && cost[node] < totalCost)
                {
                    continue;
                }
                cost[node]    = totalCost;
                parents[node] = currParent;
                pending.Enqueue(node, totalCost + heuristic(node));
            }
        }
        return(new List <T>());
    }