Пример #1
0
		public void displayRangeOfUnit(Unit u, Vector2 mousePosition)
        {
            clearRangeDisplay();

            if (overlayNodes == null)
				overlayNodes = new List<Node>();
            
			List<Node> reach = nodesWithinEnduranceValue(closestMostValidNode(mousePosition), u.getCurrentWater());
            List<Node> range = NodesInRangeOfNodes(reach, u.getMinAttackRange(), u.getMaxAttackRange());
            
            HashSet<Node> inReach = new HashSet<Node>();
			inReach.UnionWith(reach);
			HashSet<Node> inRange = new HashSet<Node>();
			inRange.UnionWith(range);
			inRange.RemoveWhere(inReach.Contains);

			foreach (Node n in inReach)
			{
				//make slightly smaller to show square off
				Node q = new Node(transform.gameObject, nodeImg, n.getPos(), n.getGridPos(), Node.randWalkState(), radii * 1.75f);
				q.setColor(new Color(0, 0.5f, 0, 0.75f));

				overlayNodes.Add(q);
			}
            
			foreach (Node n in inRange)
			{
				//make slightly smaller to show square off
				Node q = new Node(transform.gameObject, nodeImg, n.getPos(), n.getGridPos(), Node.randWalkState(), radii * 1.75f);
				q.setColor(new Color(0, 0, 0.5f, 0.75f));

				overlayNodes.Add(q);
			}
		}
Пример #2
0
        public void ShowPath(Queue<Node> Path)
        {
            Node[] PathCopy = Path.ToArray();
            if (PathCopy.Length == 0)
                return;

            //If we were displaying a path, reset the colors.
            if (manualStartNode != null)
                manualStartNode.resetColor();
            if (manualEndNode != null)
                manualEndNode.resetColor();

            //Set the colors for the start and end nodes.
            manualStartNode = PathCopy[0];
            manualEndNode = PathCopy[PathCopy.Length - 1];
            manualEndNode.setColor(Node.endColor);
            manualStartNode.setColor(Node.startColor);

            //Recycle garbage path renderers if necessary.
            if (pathDrawer != null)
            {
                UnityEngine.Object.Destroy(pathDrawer);
            }

            pathDrawer = new GameObject("Path");

            //Set up the line renderer for the path.
            // We loop back once, so have double nodes + 1.
            LineRenderer drawer = pathDrawer.AddComponent<LineRenderer>();
            drawer.SetWidth(0.3f, 0.3f);
            drawer.SetColors(Color.green, Color.green);
            drawer.SetVertexCount(PathCopy.Length * 2 + 1);
            // Need this otherwise the width is wrong on first edge.
            drawer.SetPosition(0, PathCopy[0].getPos());

            for (int i = 0; i < PathCopy.Length; i++)
                drawer.SetPosition(i + 1, PathCopy[i].getPos());
            for (int i = PathCopy.Length - 1, j = PathCopy.Length + 1; i >= 0; i--, j++)
                drawer.SetPosition(j, PathCopy[i].getPos());
        }