Пример #1
0
        /// <summary>
        ///     Check our pathfinding overrides with the layers
        ///     within a node generated during the grid creation
        /// </summary>
        /// <param name="layer">        The layer we are searching for equality         </param>
        /// <param name="canClearNode"> Whether we can inherently clear this node       </param>
        /// <param name="cost">         The costs that we are deriving from the layer   </param>
        /// <param name="isBlocked">    Determines whether or not we are blocked here   </param>
        /// <remarks>
        ///     Checks our layer overrides to determine costs and traversability
        /// </remarks>
        void checkNodeLayerOverride(int layer, bool canClearNode, out float cost, out bool isBlocked)
        {
            isBlocked = !canClearNode;
            cost      = 0.0f;
            bool overrideNode = false;

            // if our path is overriding what we can use
            foreach (NodeLayerCosts nlc in Parameters.OverrideCosts)
            {
                if (Utilities_PF.IsLayerMatch(layer: layer, compareAgainst: nlc.Layer))
                {
                    cost += nlc.Cost;
                    if (nlc.isBlocked)
                    {
                        isBlocked = true; return;
                    }
                    else
                    {
                        overrideNode = true;
                    }
                }
            }

            // we have overriden the nodes original blockage
            if (overrideNode)
            {
                isBlocked = false;
            }
        }
        /// <summary>
        ///     Will check if the layer is attached to the node
        /// </summary>
        /// <returns>
        ///     A boolean if the layer exists on the node
        /// </returns>
        internal bool CheckForLayer(NodeLayerCosts exCost)
        {
            // Need to search the layers not the f*****g costs
            foreach (int layer in Layers)
            {
                if (Utilities_PF.IsLayerMatch(layer, exCost.Layer))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        /// <summary>
        ///     Lets determine what we are hitting
        ///     fills the reference node with relevant costs
        ///     and type information
        /// </summary>
        /// <param name="hits"> The raycast hits the node encountered   </param>
        /// <param name="node"> The node to update                      </param>
        void DetermineNodeTypeHit(RaycastHit[] hits, ref Node node)
        {
            NodeType nodeType = NodeType.Open;

            node.hitCount = hits.Length;

            // we have no hits, leave me alone
            if (hits.Length < 1)
            {
                node.nodeType = nodeType;
                return;
            }

            int checks = 0;

            // Go through all the node type hits
            for (int i = 0; i < hits.Length; i++)
            {
                //nodeType = NodeType.Blocked;
                var checkHit = hits[i];

                checkGameObjectGrid(checkHit);

                //  First check if we are on a terrain node
                if (checkHit.collider.GetType() == typeof(TerrainCollider))        // if we hit the terrain
                {
                    nodeType         = NodeType.Terrain;
                    node.isOnTerrain = true;
                }
                else
                {
                    nodeType = NodeType.Blocked;    // We have hit something other than terrain with all of our hits
                }


                // prioritize the nodetype
                if (nodeType < node.nodeType)
                {
                    node.nodeType = nodeType;
                }

                // Add each layer this node touches
                var layer = checkHit.transform.gameObject.layer;
                if (!node.Layers.Contains(layer))
                {
                    node.Layers.Add(layer);
                }

                // Costs check
                foreach (NodeLayerCosts costs in LayerCosts)
                {
                    if (Utilities_PF.IsLayerMatch(layer: layer, compareAgainst: costs.Layer))
                    {
                        checks++;
                        node.Costs.Add(costs);
                        if (!costs.isBlocked)
                        {
                            nodeType = node.isOnTerrain ? NodeType.Terrain : NodeType.Open;   // Override if we have already determined this was a hit
                        }
                    }
                }

                // Make sure we did not hit anything outside of costs to override node type
                if (checks > 0 && checks == hits.Length)
                {
                    node.nodeType = nodeType;
                }
                else
                {
                    // If there is on collider that is on the terrain
                    if (checks == hits.Length - 1 && node.isOnTerrain)
                    {
                        node.nodeType = NodeType.Terrain;
                    }
                }
            }
        }