- Home /
How to get game icon via code?
Something like, Application.productIcon.
I want to do something like
Texture2D myTexture2D = Application.productIcon;
In player settings, the Default Icon field IS a Texture2D, I just don't know how to get it through code.
Thanks.
Answer by NoCandyIncluded · Jun 01, 2019 at 04:19 AM
Try importing the texture you're using as the icon into the Assets of the editor. Then in code, make a field, public Texture2D tex; Go back into the editor, and in your script component you should be able to select any Texture2D in your assets.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class teas : MonoBehaviour
{
public Texture2D tex;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Not sure if I'm understanding you correctly. I know I can get any Texture2D in my assets, what I want is to get specifically the Texture2D used as the game's icon programmatically, not manually. So whatever the game icon is, or whatever I change it to, the Texture2D in code will automatically update accordingly. This is for a tool kit I'm making where I want an image to be, by default, the icon your using for your game.
For example:
DefaultImage = Application.Icon;
Answer by Bunny83 · Jun 01, 2019 at 09:36 AM
You should have mentioned that you're looking for an editor script solution because at runtime / in a build you can't access the applications icon as Texture2d since depending on the platform the icon might have a different format and usually is not part of the game assets.
However in the editor you should be able to use PlayerSettings.GetPlatformIcons to get the associated PlatformIcons that has been setup for a particular target platform. Each PlatformIcon has a GetTexture (and GetTextures) method.
No, I don't want an editor script. The only reason I think I can get the icon at runtime, is that in player settings there IS a Texture2D variable for the icon which is used to set it. I'm thinking THAT is possible to grab at runtime. I know some other settings are.
Why should Unity include a texture that is ultimately used only outside the game (as native resource, as ico resource, ...) in your game assets? Of course it's a Texture2D inside the editor since any image resource is just a Texture2D. However that means it's automatically part of the asset database. Furthermore the assetdatabase only includes assets in a build that are actually referenced by a scene (directly or indirectly) or placed in a resources folder. The application icons are just referenced by the editor settings and used by the build process.
Your answer
