api:umfasset:loadmesh
Description:
Loads a Wavefront .obj mesh file from the mod's assets and returns it as a Mesh.
Note: Flat file/on disk assets always overwrite packed assets.
Added In: v0.50
Function
1 2 3 4 5 6 7 |
public static Mesh LoadMesh( string file, bool shared = false ) //file: File in mod's Asset folder. Should not include Assets\MyModName in file. //Packed Mods: Assets\MyModName\MyMesh.obj //Unpacked Mods: ...\Mods\Assets\MyModName\MyMesh.obj //shared set to true: Get the asset from \Mods\Assets\Shared\ instead. |
Usage
1 2 3 4 5 6 7 8 |
Mesh myMesh1 = UMFAsset.LoadMesh( "MyMesh.obj" ); //Loads from \Mods\Assets\MyModName\MyMesh.obj or from packed Assets\MyModName\MyMesh.obj Mesh myMesh2 = UMFAsset.LoadMesh( "MyMesh.obj" , true ); //Loads from \Mods\Assets\Shared\MyMesh.obj Mesh myMesh3 = UMFAsset.LoadMesh(Path.Combine( "MySubFolder" , "MyMesh.obj" )); //Loads from \Mods\Assets\MyModName\MySubFolder\MyMesh.obj or from packed Assets\MyModName\MySubFolder\MyMesh.obj |
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 myMeshFile = "MyMesh.obj" ; internal static Mesh myMesh = null ; internal static void Log( string text, bool clean = false ) { using (UMFLog log = new UMFLog()) log.Log(text, clean); } void Awake() { myMesh = UMFAsset.LoadMesh(myMeshFile); if (myMesh == null ) { Log( "Error: Failed to load the texture." ); //Do something about the error } //At this point you can use MyModName.myMesh anywhere in your code to replace or set the Mesh of a GameObject. } } } |
api/umfasset/loadmesh.txt · Last modified: 2019/06/28 01:33 by umfdev