Class PrefabAsset

java.lang.Object
net.risingworld.api.assets.Asset
net.risingworld.api.assets.PrefabAsset

public final class PrefabAsset extends Asset
Represents a prefab. A prefab may consist of several meshes. You can prepare a prefab in Unity, so it may also contain custom materials (including custom shaders), lights, particle effects etc.
Supported file formats: zip, fbx, obj, stl, ply, 3mf, gltf
  • Method Details

    • loadFromGame

      public static PrefabAsset loadFromGame(String path)
      Loads a prefab from the game assets. This is quite efficient because the server doesn't have to send any data to the clients.
      To get the prefab asset paths of game items, you could check out the various tables in the definitions.db file (in Data/StreamingAsets/). Alternatively get the asset path from the Definitions via API.
      Parameters:
      path - the path to the game prefab.
      Returns:
      a new prefab asset instance.
      Example: Load pickaxe from game files using hard-coded path
      1PrefabAsset asset = PrefabAsset.loadFromGame("Models/Items/Pickaxe/pickaxe.prefab");
      2//do something with the asset

      Example: Load pickaxe from game files using definition
      1//Get item definition
      2Items.ItemDefinition itemDef = Definitions.getItemDefinition("pickaxe");
      3
      4//Get asset path (from variant 0)
      5String assetpath = itemDef.getVariant(0).assetpath;
      6
      7PrefabAsset asset = PrefabAsset.loadFromGame(assetpath);
      8//do something with the asset
    • loadFromAssetBundle

      public static PrefabAsset loadFromAssetBundle(AssetBundle bundle, String path)
      Loads a prefab from an AssetBundle.
      Parameters:
      bundle - the asset bundle you want to load the prefab from.
      path - the path in the asset bundle.
      Returns:
      a new prefab asset instance.
    • loadFromFile

      public static PrefabAsset loadFromFile(String file)
      Loads a prefab from a file. This could be an fbx, obj or any other model file. If your model contains any textures you want to load automatically, it's recommended to put them into a zip file (together with the model file) and load the zip file.
      Parameters:
      file - the path to the model file.
      Returns:
      a new prefab asset instance.
    • loadFromFile

      public static PrefabAsset loadFromFile(String file, ModelImportSettings settings)
      Loads a prefab from a file. This could be an fbx, obj or any other model file. If your model contains any textures you want to load automatically, it's recommended to put them into a zip file (together with the model file) and load the zip file.
      Parameters:
      file - the path to the model file.
      settings - a settings object which enables you to influence how the model should be loaded.
      Returns:
      a new prefab asset instance.