Beispiel #1
0
 public void CheckTarget()
 {
     AStarNode currentNode = new AStarNode(m_planer.GetNode(), m_planer.Direction, 0, null);
     if (currentNode.EqualWithRandomRotation(m_target))
     {
       m_target = null;
     }
 }
Beispiel #2
0
    void UpdateDirection(AStarNode node, ref List<AStarNode> adj, ref List<AStarNode> check, int index)
    {
        AStarNode newNode;
        WayStatus[] directions = GraphTagMachine.GetDirections(node.node);

        if (directions[index] == WayStatus.Unavailable || directions[index] == WayStatus.Hidden)
          return;
        index=GraphTagMachine.GetDirection(node.node, index);

        if (directions[index]==WayStatus.Free)
        {
          newNode = new AStarNode(node.node.GetNodeByDirection(index), index, node.distance + 1 + 0.01f * Mathf.Abs((node.direction + 6 - index) % 6), node);
          if(!newNode.EqualWithRandomRotation(Target))
        newNode.distance += newNode.node.NodeValue(m_planer.EntityValue);
        }
        else if (directions[index] == WayStatus.Blocked)
        {
          newNode = new AStarNode(node.node, node.node.GetHitDirection(index), node.distance + 1 + 0.01f * Mathf.Abs((node.direction + 6 - index) % 6), node);
          newNode.prevDirection = index;
        }
        else
        {
          return;
        }

        int foundIndex = check.BinarySearch(newNode);
        bool found = false;
        AStarNode existNode;
        if (foundIndex >= 0)
        {
          found = true;
          existNode = check[foundIndex];
          if (existNode.distance > newNode.distance)
          {
        existNode.previous.children[index] = null;
        existNode.distance = newNode.distance;
        existNode.previous = node;

        for (int i = 0; i < 6; i++)
        {
          if (existNode.children[i] != null)
            UpdateDirection(existNode, ref  adj, ref check, i);
        }
        node.children[index] = existNode;
        return;
          }
        }
        foundIndex = adj.BinarySearch(newNode);
        if (foundIndex >= 0)
        {
          found = true;
          existNode = adj[foundIndex];
          if (existNode.distance > newNode.distance)
          {
        existNode.previous.children[index] = null;
        existNode.distance = newNode.distance;
        existNode.previous = node;
        node.children[index] = existNode;
        return;
          }
        }
        if (found == false && node.distance < m_maxDistance * 1.2f)
        {
          node.children[index] = newNode;
          adj.Insert(~foundIndex, newNode);
        }
    }