public void AddTargetToBeTracked(GameObject newTarget) { if (!this.targetsTracking.Contains(newTarget)) { // Add the target to the list of targets. this.targetsTracking.Add(newTarget); // Instantiate the new arrow for that target. GameObject newArrow = Instantiate(arrowPrefab) as GameObject; // Set the arrow to be a child of the compass. newArrow.transform.SetParent(this.transform); newArrow.transform.localPosition = Vector3.zero; CompassArrow compassArrow = newArrow.GetComponent <CompassArrow>(); // Set the arrow's target. compassArrow.SetTarget(newTarget); // Add the arrow to the list of arrows. this.arrows.Add(newArrow); } }
public override void DrawOn2DControlTopDownView(MapObjectHoverData hoverData) { List <CompassArrow> arrows = Enumerable.Range(0, 4).ToList().ConvertAll(index => new CompassArrow(16384 * index)); List <List <(float x, float z)> > triPoints = new List <List <(float x, float z)> >(); foreach (CompassArrow arrow in arrows) { triPoints.Add(new List <(float x, float z)>() { arrow.ArrowHeadPoint, arrow.ArrowHeadCornerLeft, arrow.ArrowHeadCornerRight }); triPoints.Add(new List <(float x, float z)>() { arrow.ArrowHeadInnerCornerRight, arrow.ArrowHeadInnerCornerLeft, arrow.ArrowBaseLeft }); triPoints.Add(new List <(float x, float z)>() { arrow.ArrowBaseLeft, arrow.ArrowBaseRight, arrow.ArrowHeadInnerCornerRight }); triPoints.Add(new List <(float x, float z)>() { arrow.ArrowBaseRight, arrow.ArrowBaseLeft, (MapConfig.CompassCenterX, MapConfig.CompassCenterZ) }); } List <List <(float x, float z)> > triPointsForControl = triPoints.ConvertAll(tri => tri.ConvertAll( vertex => RotatePoint(vertex.x, vertex.z))); List <(float x, float z)> outlinePoints = arrows.ConvertAll(arrow => arrow.GetOutlinePoints()).SelectMany(points => points).ToList(); List <(float x, float z)> outlinePointsForControl = outlinePoints.ConvertAll(point => RotatePoint(point.x, point.z)); GL.BindTexture(TextureTarget.Texture2D, -1); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); // Draw polygon GL.Color4(Color.R, Color.G, Color.B, OpacityByte); GL.Begin(PrimitiveType.Triangles); foreach (List <(float x, float z)> tri in triPointsForControl) { foreach ((float x, float z) in tri) { GL.Vertex2(x, z); } } GL.End(); // Draw outline if (LineWidth != 0) { GL.Color4(LineColor.R, LineColor.G, LineColor.B, (byte)255); GL.LineWidth(LineWidth); GL.Begin(PrimitiveType.LineLoop); foreach ((float x, float z) in outlinePointsForControl) { GL.Vertex2(x, z); } GL.End(); } // Draw direction labels if (MapConfig.CompassShowDirectionText != 0) { List <int> directionTexs = new List <int>() { _texZP, _texXP, _texZM, _texXM }; for (int i = 0; i < arrows.Count; i++) { CompassArrow arrow = arrows[i]; int tex = directionTexs[i]; (float x, float z)textPosition = arrow.DirectionTextPosition; textPosition = RotatePoint(textPosition.x, textPosition.z); PointF loc = new PointF(textPosition.x, textPosition.z); SizeF size = new SizeF((int)MapConfig.CompassDirectionTextSize, (int)MapConfig.CompassDirectionTextSize); // Place and rotate texture to correct location on control GL.LoadIdentity(); GL.Translate(new Vector3(loc.X, loc.Y, 0)); GL.Color4(1.0, 1.0, 1.0, 1.0); // Start drawing texture GL.BindTexture(TextureTarget.Texture2D, tex); GL.Begin(PrimitiveType.Quads); // Set drawing coordinates GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-size.Width / 2, size.Height / 2); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(size.Width / 2, size.Height / 2); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(size.Width / 2, -size.Height / 2); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-size.Width / 2, -size.Height / 2); GL.End(); } } // Draw angle labels if (MapConfig.CompassShowAngleText != 0) { List <int> angleTexs = MapConfig.CompassAngleTextSigned != 0 ? new List <int>() { _tex0, _tex16384, _texM32768, _texM16384 } : new List <int>() { _tex0, _tex16384, _tex32768, _tex49152 }; for (int i = 0; i < arrows.Count; i++) { CompassArrow arrow = arrows[i]; int tex = angleTexs[i]; (float x, float z)textPosition = arrow.AngleTextPosition; textPosition = RotatePoint(textPosition.x, textPosition.z); PointF loc = new PointF(textPosition.x, textPosition.z); SizeF size = new SizeF((int)MapConfig.CompassAngleTextSize, (int)MapConfig.CompassAngleTextSize); // Place and rotate texture to correct location on control GL.LoadIdentity(); GL.Translate(new Vector3(loc.X, loc.Y, 0)); GL.Color4(1.0, 1.0, 1.0, 1.0); // Start drawing texture GL.BindTexture(TextureTarget.Texture2D, tex); GL.Begin(PrimitiveType.Quads); // Set drawing coordinates GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-size.Width / 2, size.Height / 2); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(size.Width / 2, size.Height / 2); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(size.Width / 2, -size.Height / 2); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-size.Width / 2, -size.Height / 2); GL.End(); } } GL.Color4(1, 1, 1, 1.0f); }