Drawing Circles or Circle Textures on Texture2D objects

Hi, I am working on a game that takes place in space and I have a circular radar image that I am using and I want to be able to draw a red line for the boundary of space. I found that there are 2 ways to do this, but neither of them really work:

  1. Use the SetPixel command - This overwrites the texture within unity and I don’t know how to “refresh” the texture.
  2. Use something like Gui.DrawTexture(new Circle… - This does not exist, but something like it sure would be convenient. Even if I could do this with an image that is just a circle that I draw myself in Paint.Net or whatever that would be fine except the boundary size will be different with different kinds of maps that we use. So, I theoretically could just have a number of pre-drawn textures for the boundaries, but I would rather do it automatically.

If anyone knows how to do this, I would really appreciate the help / advice.

Let me explain how I am trying to do the 1st method.

I set a number of settings within Unity to be able to edit the image:

  1. Select the Texture itself in Unity.
  2. Set the Texture Type to “Advanced”
  3. Check the “Read/Write Enabled” checkbox
  4. Set the “Texture Format” to “ARGB 32 bit”

Then, I use the SetPixel(s) command(s) in a script that draws a circle for you wherever you like onto a Texture2D image. So far, so good.

!(http://www.morningstarproductions.org/Unity/with boundary.png)

However, when I start moving the ship, I obviously want the boundary on the radar to move also since the boundary is either closer to me or farther away. The player’s location should represent the center of the screen. But, as you can see, it gives me problems:

!(http://www.morningstarproductions.org/Unity/messed up.png)

I have looked into doing using the TextAsset type to use “LoadImage”, but I am unsure how that works or if that is even the right approach at this point since I know being able to do a command similar to DrawTexture

Thanks,
OldMonk

You’d have to re-draw the circle onto a new copy of the texture. Either that or erase the original circle first, but that can cause problems. At the risk of sounding like an ad, personally I’d use Vectrosity, which is good for drawing circles and radar blips, and is much faster than constantly re-uploading new textures.

–Eric

Yes, I understand that I would have to redraw the circle onto the new copy of the texture, but how would I do that? Would you try using the LoadImage command or is there a special command that draws 2D circles on Vectrosity?

Probably I’d keep a clean copy of the texture, then copy that to the new texture and draw the circle into that. This is pretty slow, mostly because of having to do texture.Apply() every time. In Vectrosity you could do this:

var segments = 30;
var radius = 50.0;
var origin = Vector2(100, 100);
private var circleLine : VectorLine;

function Start () {
	circleLine = VectorLine ("Circle", new Vector2[segments*2], Color.red, null, 1.0);
	Vector.MakeCircleInLine (circleLine, origin, radius, segments);
	Vector.DrawLine (circleLine);
}

Then later you can change the radius and origin and re-draw the circle as necessary. Additionally, if you don’t need to change the radius, you can move the line using circleLine.vectorObject.transform.position and not have to re-draw anything, so it’s just as fast as moving any other gameobject around.

–Eric

Ok, yeah I think I will give Vectrosity a shot. Will the $15 version include this functionality you described?

Yes; also all updates are free (and automatic if you buy from the Unity Asset Store).

–Eric