Example #1
0
        /// <summary>
        /// Finds the nodes this gameobject overlaps, modifies their layer to the specified layer and returns all the nodes modified.
        /// </summary>
        /// <param name="nodeNetwork">NodeNetwork which will be modified</param>
        /// <param name="layer">The nodes their new layer</param>
        /// <returns>List of all modified nodes</returns>
        protected virtual List <Node> CreateCustomNodeNetwork(NodeNetwork nodeNetwork, int layer)
        {
            float spacing           = nodeNetwork.Spacing;
            int   innerNetworkSizeX = Mathf.Max(Mathf.RoundToInt(((transform.localScale.x)) / spacing), 1);
            int   innerNetworkSizeY = Mathf.Max(Mathf.RoundToInt(((transform.localScale.y)) / spacing), 1);

            Vector3     size              = new Vector3((transform.localScale.x), (transform.localScale.y), 0);
            Vector3     worldBottomLeft   = transform.position - (size / 2);
            List <Node> innerNetworkNodes = new List <Node>();

            for (int x = 0; x <= innerNetworkSizeX + 0; x++)
            {
                for (int y = 0; y <= innerNetworkSizeY; y++)
                {
                    Vector3 worldPosition = worldBottomLeft + new Vector3(x * spacing, y * spacing, nodeNetwork.transform.position.z);
                    Node    node          = nodeNetwork.GetNodeFromWorldPosition(worldPosition, int.MaxValue, true);
                    if (node.LayerValue == NodeNetwork.UnwalkableLayer)
                    {
                        continue;
                    }

                    if (!innerNetworkNodes.Contains(node) && node.WorldPosition.z >= transform.position.z)
                    {
                        nodeNetwork.MofidyNode(node, layer);
                        innerNetworkNodes.Add(node);
                    }
                }
            }
            return(innerNetworkNodes);
        }