Which looks like it will do the trick, I imported it to my assets. But can’t seem to access it. I think it’s working because I can compile the example scene, but can’t figure out how to use it. Bit of a nube, to using packages, so it could be pretty basic (a stupid mistake) but lost.
basically I’m trying to figure out how to give it a country code ISO and get the flag image back.
or a big part of my problem is the result CountryFlagEntery.Flag returns the whole sprite when I just wanter one flag.
What I was doing is putting the flag on as a texture on an object, after a bunch of research I found out that a Sprite sheet, won’t work as a texture or a least not the way I want, it returns the whole sheet.
So I had to create a new texture and then ‘render’ the sprite to that texture.
Texture2D CreateReadableTexture(Sprite sprite)
{
// Create a new readable Texture2D with the sprite's dimensions
Texture2D readableTexture = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height, TextureFormat.RGBA32, false);
// Get the source texture (sprite sheet)
Texture2D sourceTexture = sprite.texture;
// Create a temporary RenderTexture
RenderTexture rt = RenderTexture.GetTemporary(sourceTexture.width, sourceTexture.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear);
// Copy the source texture to the RenderTexture
Graphics.Blit(sourceTexture, rt);
// Store the current active RenderTexture
RenderTexture previous = RenderTexture.active;
// Set the current RenderTexture to our temporary texture
RenderTexture.active = rt;
// Read the pixels from the specific area of the sprite
readableTexture.ReadPixels(sprite.rect, 0, 0);
readableTexture.Apply();
// Restore the active RenderTexture
RenderTexture.active = previous;
// Release the temporary RenderTexture
RenderTexture.ReleaseTemporary(rt);
return readableTexture;
}
because I didn’t go to no fancy comp.Sci university school or nothing. I didn’t understand namespace.
so for people like me.
namespace gives you a way to compartmentalize your code. l
adding:
namespace CountryFlags
{
public class CountryFlag_MyMethod : MonoBehaviour
{
Debug.Log("I'm doing stuff with the CountyFlag");
}
}
Then to access that method.
public CountryFlagEntry FlagEntry { get; private set; }
// and
CountryFlagEntry currentFlag = CountryFlags.Flags.Search(query).FirstOrDefault();
// note the dot.. why someone couldn't nicely explain that to me is curious. and Save me 45 minutes of googling! HAhhahah!