|
Hi, I have a texture that is 256x64. I need to render from 0,0 to 63,63 in this texture (A 64x64 sub-rect). How can I do this using GUI.Box()? I've tried specifying a GUIStyle that sets contentOffset to (0,0) and fixedWidth/fixedHeight to 64,64 but this didn't work. Thanks.
(comments are locked)
|
|
Take a look at Graphics.DrawTexture. http://unity3d.com/support/documentation/ScriptReference/Graphics.DrawTexture.html You can specify a material and, with so, UV coordinates. This way you can draw only a portion of your texture inside OnGUI calls. You must end up with something like it:
Where
is your sourceRect (texture portion that you want to draw). The Graphics class is only available in Unity Pro.
May 31 '10 at 09:34 PM
qJake
(comments are locked)
|
|
I think you can use GUI.DrawTexture, e.g. (C#): That will still scale the texture, it will just crop if the aspect ratio of the new dimensions don't match. This won't work.
May 31 '10 at 09:33 PM
qJake
As specified in the question, the aspect ratio does not match. However, this centers the texture on the other axis, so is not applicable. I'll edit above to remove the problem.
Jun 01 '10 at 03:26 AM
Molix
(comments are locked)
|
|
There are several ways, copy only that part of the texture to a new texture using GetPixels (or something like that I dont remember pretty well now). another one is render to texture from another camera only that part of the texture (which I think is kinda hacky) I would use the 1rst one I suggested you.
(comments are locked)
|
|
Naruse was correct, although I will flesh out his answer a bit: Use Texture2D.GetPixels to get the area of pixels you want. Then, create a new Texture2D object, and call Texture2D.SetPixels to write the extracted section of pixels to the new texture object. Then, call
(comments are locked)
|
|
My question would be. Do I gain something from having all my textures in a single, let's say, png file then do this to create subtextures to apply? Or it is better if the textures are split by the artist?
(comments are locked)
|
