api:umfasset:loadtexture2d
Description:
Loads an image file from the mod's assets and returns it as a Texture2D.
Note: Flat file/on disk assets always overwrite packed assets.
Added In: v0.50
Function
1 2 3 4 5 6 7 |
public static Texture2D LoadTexture2D( string file, bool shared = false ) //file: File in mod's Asset folder. Should not include Assets\MyModName in file. //Packed Mods: Assets\MyModName\MyTexture.png //Unpacked Mods: ...\Mods\Assets\MyModName\MyTexture.png //shared set to true: Get the asset from \Mods\Assets\Shared\ instead. |
Usage
1 2 3 4 5 6 7 8 |
Texture2D myTexture1 = UMFAsset.LoadTexture2D( "MyTexture.png" ); //Loads from \Mods\Assets\MyModName\MyTexture.png or from packed Assets\MyModName\MyTexture.png Texture2D myTexture2 = UMFAsset.LoadTexture2D( "MyTexture.png" , true ); //Loads from \Mods\Assets\Shared\MyTexture.png Texture2D myTexture3 = UMFAsset.LoadTexture2D(Path.Combine( "MySubFolder" , "MyTexture.png" )); //Loads from \Mods\Assets\MyModName\MySubFolder\MyTexture.png or from packed Assets\MyModName\MySubFolder\MyTexture.png |
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
using UModFramework.API; namespace MyModName { [UMFScript] class MyModName : MonoBehaviour { private const string myTextureFile = "MyTexture.png" ; internal static Texture2D myTexture = null ; internal static void Log( string text, bool clean = false ) { using (UMFLog log = new UMFLog()) log.Log(text, clean); } void Awake() { myTexture = UMFAsset.LoadTexture2D(myTextureFile); if (myTexture == null ) { Log( "Error: Failed to load the texture." ); //Do something about the error } //At this point you can use MyModName.myTexture anywhere in your code to replace or set the Texture2D of something. } } } |
api/umfasset/loadtexture2d.txt · Last modified: 2019/06/28 01:39 by umfdev