creating a mesh and generating it's specific uvs

Hi guys. I'll try and be concise. I'm trying to take a a piece of an image and make it into a 3d plane, and I don't know much about generating uvs in unity.

  • I'm building a gui in 3d using planes, textures, and raycast selection

  • we're getting ready for localization and language changes

  • I'd like to take all of the text in my hud and put it in a single texture, so i can make an english version, a french version, etc just by swapping out images.

  • to create the actually 3d hud components, I want to make an editor class where as i can open up the image with all of the text on it, drag select an area to select some text, and have unity create a plane with the uvs mapped to that location.

  • I have already created an editor tool to build a plane, from an image, with the same aspect ratio of that image, so I know a bit about editor extending.

  • I'm really curious here about if it's possible to

    1. display an image in the editor and read mouse clicks to get co-ordinates on that texture
    2. take that data, create a plane, turn that data into uv mapping co-ordinates for the plane, and scale the plane so that the aspect ratio of the plane matches the aspect ratio of the uv co-ordinates.

Basically the intention here would be to take a section of an image and turn it into a 3d plane.

Any advice would be delightful. Thanks guys!

I would look into this:

You might be able then to raycast to that texture and read out the coords from the raycast hit texture coordinate


in the OnGUI function of your editor:

  • create a new orthographic camera with a texture plane right in front of it.
  • call Handles.DrawCamera to create a render window on the editor gui.
  • create a ray using HandleUtility.GUIPointToWorldRay
  • using physics.raycast on mouse click to check for collision on the plane
  • read the texture coordinates of the raycast collisions with RaycastHit.textureCoord

then instantiate a plane and set it's uvs to match the coordinates from the clicks that you made.