-
Notifications
You must be signed in to change notification settings - Fork 37
ImageUtils Class
Namespace: SMLHelper.V2.Utility
A collection of image loading utility functions that can create Unity objects from image files at runtime.
public static class ImageUtils
LoadTextureFromFile(string filePathToImage, TextureFormat) |
---|
LoadSpriteFromFile(string filePathToImage, TextureFormat) |
LoadSpriteFromTexture(Texture2D texture2D) |
The following example looks for an image file within the {GAME_PATH}/QMods/{MOD_PATH}/Assets
path and sets it as the Titanium icon.
using System.IO;
using System.Reflection;
using SMLHelper.V2.Handlers;
using SMLHelper.V2.Utility;
using UnityEngine;
#if SUBNAUTICA
using Sprite = Atlas.Sprite;
#endif
// You can also just use the ImageUtils.LoadSpriteFromFile() method
// to directly convert an image file to a sprite, but it's not shown in
// this example.
[QModCore]
public static class MyMainClass
{
private static Assembly _assembly = Assembly.GetExecutingAssembly();
private static string _assetFolderPath = Path.Combine(Path.GetDirectoryName(_assembly.Location), "Assets");
[QModPatch]
public static void MyPatch()
{
var iconPath = Path.Combine(_assetFolderPath, "new-titanium-icon.png");
if (File.Exists(iconPath))
{
Texture2D texture = ImageUtils.LoadTextureFromfile(iconPath);
Sprite icon = ImageUtils.LoadSpriteFromTexture(texture);
SpriteHandler.RegisterSprite(TechType.Titanium, icon);
}
}
}
Creates a new texture from an image file.
public static Texture2D LoadTextureFromFile(string filePathToImage, TextureFormat format = TextureFormat.BC7);
-
string
filePathToImage
The path to the image file. -
TextureFormat format
The texture format. Defaulted to TextureFormat.BC7
We advise against modifying this parameter unless you know what you're doing.
Texture2D if the image was found; otherwise, null
.
Creates a new sprite from an image file.
public static Sprite LoadSpriteFromFile(string filePathToImage, TextureFormat format = TextureFormat.BC7);
-
string
filePathToImage
The path to the image file. -
TextureFormat format
The texture format. Defaulted to TextureFormat.BC7.
We advise against modifying this parameter unless you know what you're doing.
If the image was found:
- Subnautica:
Atlas.Sprite
- Below Zero: Sprite
otherwise, null
.
Creates a new sprite from a texture object.
public static Sprite LoadSpriteFromTexture(Texture2D texture2D);
-
Texture2D texture2D
The 2D texture to convert into a sprite.
If the image was found:
- Subnautica:
Atlas.Sprite
- Below Zero: Sprite
otherwise, null
.
If there is something missing or ambiguous, please create an issue or contact us on the Subnautica Modding Discord using our tags:
- PrimeSonic:
@PrimeSonic#0667
- Metious:
@Metious#3682
Please note that some pages are under construction and the links to them will be enabled as they are completed
[Adding]
- Items/GameObjects using Asset Classes
- Asynchronous loading for ModPrefab
- [Custom Scanner Unlocks]
- Items/GameObjects to the Spawning System
- [Recipes to uncraftable items]
- [Custom Mouse Click Actions]
[Editing]
- Background Type
- Crafting Time
- Equipment Type
- Quick Slot Type
- Size in Inventory
- [Recipes for craftable items]
- Harvest Settings
- BioReactor Fuel Values
- [Scanning Count/Time]
- [Spawning (Where/How often/How many)]
[General Utilities]
- In-Game Options Menu
- Adding crafting recipes for other mods items
- Using items from other mods
- Texture/Sprite Utilities
- [Adding/Playing Audio]
- Config Files using Abstract Json Config class
- Custom Console Commands
- [Registering OnSave/OnQuit Actions]
[Language]