Jump to content

How to use KSP Icons?


Recommended Posts

I haven't seen a way to reference these texture objects directly in code, as I looked at that for something myself a while ago. I reverted to drawing my own for that project.

Although a quick search of the object browser now shows the VesselLabels object has a Texture2D called flightOverlayIconsMap which sounds promising. Maybe try loking at the contents of that object

Link to comment
Share on other sites

I haven't seen a way to reference these texture objects directly in code, as I looked at that for something myself a while ago. I reverted to drawing my own for that project.

Although a quick search of the object browser now shows the VesselLabels object has a Texture2D called flightOverlayIconsMap which sounds promising. Maybe try loking at the contents of that object

It's basically the same, but I now have a new question - how to use ReadPixels() function from flightOverlayIconsMap?

Link to comment
Share on other sites

So two ways, depending on what you are trying to do..

1) use the Texture2D.EncodeToPNG() function to get a byte array and then save the file so you can look at the asset

2) use the Texture2D.GetPixels(int x, int y, int blockWidth, int blockHeight) to get an array of the pixel colors for the square you want

The second way could mean that you read the icons dynamically in game and reuse them, but if Squad change the sprite sheet you need to recode all your position values

Link to comment
Share on other sites

I know it has something to do about MapView. but I don't know the function to get the icon.

The texture is exposed as MapView.OrbitIconsMap.

I don't know if there is a function to draw them individually or get the texture coordinates for an icon, but it's pretty easy to make yourself. It's a grid of 5 x 5 icons (not all spots filled) so texture coordinates are some multiple of 0.2 in either direction and width/height are also 0.2.

Link to comment
Share on other sites

You should get an array of colors, which you can then write back to a texture using setpixels, or use the EncodeToPNG which gives you a byte array you can save to a file.

Are you trying to redraw the icons in memory while the game runs or are you trying to get the icons to then create textures you can use?

Sorry I'm slow to respond I have a lot on at the moment.

Link to comment
Share on other sites

You should get an array of colors, which you can then write back to a texture using setpixels, or use the EncodeToPNG which gives you a byte array you can save to a file.

Are you trying to redraw the icons in memory while the game runs or are you trying to get the icons to then create textures you can use?

Sorry I'm slow to respond I have a lot on at the moment.

I want to get a texture from the spritesheet which is located at MapView.OrbitIconsMap. What I've tried was MapView.OrbitIconsMap.EncodeToPNG() but it returned the full spritesheet.

Link to comment
Share on other sites

  • 3 weeks later...

Sorry for not getting back to this, was swamped by other work and missed this post. I've had a bit more of a play around and I don't think you can get the Squad Textures in game directly. Each time I have gotten to the point of the last step would give you access I get an error like the below.

UnityException: Texture 'OrbitIcons' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
at (wrapper managed-to-native) UnityEngine.Texture2D:EncodeToPNG ()

Which makes sense from a game perspective it's protecting its Intellectual Property.

Thats about the limit of my knowledge

Link to comment
Share on other sites

If you just want to use the icons, it's easy enough. Saving them as something else would need one more step -- Graphics.Blit of that to a RenderTexture and then saving that RenderTexture. :)


public static Texture2D GetGizmoTexture()
{
// This clever method at getting at the stock texture asset originates in Enhanced Navball.
ManeuverGizmo maneuverGizmo = MapView.ManeuverNodePrefab.GetComponent<ManeuverGizmo>();
ManeuverGizmoHandle maneuverGizmoHandle = maneuverGizmo.handleNormal;
Transform gizmoTransform = maneuverGizmoHandle.flag;
Renderer gizmoRenderer = gizmoTransform.renderer;
return (Texture2D)gizmoRenderer.sharedMaterial.mainTexture;
}

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...