コード例 #1
0
        private bool ExistsObstacle(NodeBehaviour targetNode)
        {
            Vector3 direction = targetNode.transform.position - transform.position;

            if (Physics.Raycast(transform.position, direction, BoardBehaviour.SPACING, obstacleLayer))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public void FindNeighbors(NodeBehaviour[] nodes)
        {
            for (int i = 0; i < BoardBehaviour.directions.Length; i++)
            {
                NodeBehaviour neighbor = Array.Find(nodes, n => n.transform.localPosition == transform.localPosition + BoardBehaviour.directions[i]);

                if (neighbor != null)
                {
                    if (!ExistsObstacle(neighbor))
                    {
                        nodeNeighbor.Add(neighbor);
                    }
                }
            }
        }
コード例 #3
0
        private void LinkToNode(NodeBehaviour targetNode)
        {
            if (linkPrefab != null)
            {
                GameObject newLink = Instantiate(linkPrefab, transform);
                newLink.GetComponent <LinkBehaviour>().DrawLink(transform.position, targetNode.transform.position);

                if (!linkedNodes.Contains(targetNode))
                {
                    linkedNodes.Add(targetNode);
                }

                if (!targetNode.linkedNodes.Contains(this))
                {
                    targetNode.linkedNodes.Add(this);
                }
            }
        }