Class Prefab
java.lang.Object
net.risingworld.api.worldelements.GameObject
net.risingworld.api.worldelements.Prefab
Represents a custom prefab. A prefab could consist of multiple models and meshes, and may also contain custom
textures and materials, animators, colliders etc. A prefab is typically created in Unity, where you could use
almost all Unity components (except "MonoBehaviours"). When using materials or custom shaders, make sure they're HDRP-compatible.
You're also able to change various parameters of any child element of the prefab (i.e a child within the actual prefab asset, not to be confused with another regular
Example: Load a prefab from an asset bundle
You're also able to change various parameters of any child element of the prefab (i.e a child within the actual prefab asset, not to be confused with another regular
GameObject
attached to this object).
-
Nested Class Summary
Nested classes/interfaces inherited from class net.risingworld.api.worldelements.GameObject
GameObject.AttachTarget
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addComponent
(String path, String component) Adds a new Unity component to the prefab or a child of this prefab.void
clearMaterialPropertyBlock
(String path, int materialIndex) Removes a MaterialPropertyBlock from a Renderer component.void
invokeComponentMethod
(String path, String component, String method, Object... parameters) void
playAnimatorState
(String path, String state, int layer, float normalizedTime) void
void
readLocalPosition
(String path, Player player, Callback<Vector3f> callback) Reads the actual local position of the prefab (or a child of this prefab, specified by the path) from a particular player.void
readLocalRotation
(String path, Player player, Callback<Quaternion> callback) Reads the actual local rotation of the prefab (or a child of this prefab, specified by the path) from a particular player.void
readWorldPosition
(String path, Player player, Callback<Vector3f> callback) Reads the actual world position of the prefab (or a child of this prefab, specified by the path) from a particular player.void
readWorldRotation
(String path, Player player, Callback<Quaternion> callback) Reads the actual world rotation of the prefab (or a child of this prefab, specified by the path) from a particular player.void
rebindAnimator
(String path, boolean keepState) Rebinds all properties and mesh data with the animator controller.void
void
removeComponent
(String path, String component) Removes a Unity component from the prefab or a child of this prefab.void
resetAnimatorTrigger
(String path, String trigger) Resets (i.e unsets) the value of the given trigger parameter on the animator controller component.void
Toggles the active state of the prefab or a child of the prefab.void
setAnimatorParameter
(String path, String parameter, boolean value) Sets a boolean parameter on the animator controller component of the prefab or a child of this prefab.void
setAnimatorParameter
(String path, String parameter, float value) Sets a float parameter on the animator controller component of the prefab or a child of this prefab.void
setAnimatorParameter
(String path, String parameter, int value) Sets an int parameter on the animator controller component of the prefab or a child of this prefab.void
setAnimatorTrigger
(String path, String trigger) Sets the value of the given trigger parameter on the animator controller component.void
setComponentEnabled
(String path, String component, boolean enabled) Enables or disables a component.void
setComponentProperty
(String path, String component, String property, Object value) Sets a component property via reflection.void
Sets the layer of the prefab or a child of this prefab.void
setLocalPosition
(String path, Vector3f position) Sets the position of the prefab or a child of this prefab, relative to its parent.void
setLocalRotation
(String path, Quaternion rotation) Sets the rotation of the prefab or a child of this prefab, relative to its parent.void
setLocalScale
(String path, Vector3f scale) Sets the local scale of the prefab or a child of this prefab, relative to its parent.void
setMaterial
(String path, MaterialAsset material) Assigns a new material to the prefab or a child of this prefab.void
setMaterialParameter
(String path, String parameter, boolean value) Sets a material parameter.void
setMaterialParameter
(String path, String parameter, float value) Sets a material parameter.void
setMaterialParameter
(String path, String parameter, TextureAsset texture) Sets a material parameter.void
setMaterialParameter
(String path, String parameter, Vector2f value) Sets a material parameter.void
setMaterialParameter
(String path, String parameter, Vector3f value) Sets a material parameter.void
setMaterialParameter
(String path, String parameter, Vector4f value) Sets a material parameter.void
setPrefab
(PrefabAsset prefab) Assigns a prefab asset to this game object.void
setVFXParameter
(String path, String parameter, boolean value) void
setVFXParameter
(String path, String parameter, float value) void
setVFXParameter
(String path, String parameter, int value) void
setVFXParameter
(String path, String parameter, Vector2f value) void
setVFXParameter
(String path, String parameter, Vector3f value) void
setVFXParameter
(String path, String parameter, Vector4f value) void
setVFXPaused
(String path, boolean pause) void
setVFXPlayRate
(String path, float rate) void
startAnimatorPlayback
(String path) void
stopAnimatorPlayback
(String path) void
Methods inherited from class net.risingworld.api.worldelements.GameObject
addChild, addComponent, attachTo, attachTo, deleteAttribute, getAttribute, getAttributes, getChildCount, getChilds, getCollider, getID, getLayer, getLocalPosition, getLocalRotation, getLocalScale, getParent, getPluginID, hasAttribute, hasAttribute, invokeComponentMethod, isActive, isAttached, isColliderVisible, isDisposed, moveToLocalPosition, moveToLocalPosition, moveToLocalPosition, moveToLocalPosition, moveToLocalTransform, readWorldPosition, readWorldRotation, removeAllChilds, removeChild, removeComponent, removeFromParent, rotateToLocalRotation, setActive, setAttribute, setCollider, setColliderVisible, setComponentEnabled, setComponentProperty, setLayer, setLocalPosition, setLocalPosition, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale
-
Constructor Details
-
Prefab
public Prefab() -
Prefab
-
-
Method Details
-
setPrefab
Assigns a prefab asset to this game object.- Parameters:
prefab
-
-
setActive
Toggles the active state of the prefab or a child of the prefab. Setting this to false will disable the object in the game scene, i.e it is no longer visible and no longer collides with the player or the world. This automatically affects all child elements as well.
By default, an object is set to active.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.set
- true to set the object active, false to disable it.
-
setLayer
Sets the layer of the prefab or a child of this prefab.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.layer
- the new layer you want to set.recursively
- true to set the layer for all prefab childs (contained by the actual prefab), false to change it only for the specified element.
-
setLocalPosition
Sets the position of the prefab or a child of this prefab, relative to its parent.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.position
- a vector which holds the new position coordinates.
-
setLocalRotation
Sets the rotation of the prefab or a child of this prefab, relative to its parent.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.rotation
- the quaternion which represents the new rotation.
-
setLocalScale
Sets the local scale of the prefab or a child of this prefab, relative to its parent.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.scale
- the new scale along the X, Y and Z axis.
-
readLocalPosition
Reads the actual local position of the prefab (or a child of this prefab, specified by the path) from a particular player. This may differ from the position set byGameObject.setLocalPosition(net.risingworld.api.utils.Vector3f)
, because if the element has a Rididbody physics component or if it's affected by an Animator, the position may be modified on the clientside (and it may be different for each client). These changes are not reflected in the API.
Once the result is available, the provided callback is invoked (containing the position of the element as Vector3f).- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) is used.player
- the player you want to read the information from. If null, the position is read from the first player this game object is currently linked to. If this game object is not linked with any players yet, an exception is thrown.callback
- callback that is invoked once the result is available from the client.- Example: Read local position of a child called "inner2", child of "inner", child of this prefab
-
readWorldPosition
Reads the actual world position of the prefab (or a child of this prefab, specified by the path) from a particular player. Once the result is available, the callback is invoked (containing the world position of the element as Vector3f).- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) is used.player
- the player you want to read the information from. If null, the position is read from the first player this game object is currently linked to. If this game object is not linked with any players yet, an exception is thrown.callback
- callback that is invoked once the result is available from the client.
-
readLocalRotation
Reads the actual local rotation of the prefab (or a child of this prefab, specified by the path) from a particular player. This may differ from the rotation set byGameObject.setLocalRotation(net.risingworld.api.utils.Quaternion)
, because if the element has a Rididbody physics component or if it's affected by an Animator, the rotation may be modified on the clientside (and it may be different for each client). These changes are not reflected in the API.
Once the result is available, the provided callback is invoked (containing the rotation of the element as Quaternion).- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) is used.player
- the player you want to read the information from. If null, the rotation is read from the first player this game object is currently linked to. If this game object is not linked with any players yet, an exception is thrown.callback
- callback that is invoked once the result is available from the client.
-
readWorldRotation
Reads the actual world rotation of the prefab (or a child of this prefab, specified by the path) from a particular player. Once the result is available, the callback is invoked (containing the world rotation of the element as Quaternion).- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) is used.player
- the player you want to read the information from. If null, the rotation is read from the first player this game object is currently linked to. If this game object is not linked with any players yet, an exception is thrown.callback
- callback that is invoked once the result is available from the client.
-
addComponent
Adds a new Unity component to the prefab or a child of this prefab. The component is created via reflection, determined by the type name.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.component
- the name/type of the component.- Example: Add a Rigidbody component to a prefab
-
removeComponent
Removes a Unity component from the prefab or a child of this prefab. The component type is determined by name (i.e the game will remove the first component of that type on the prefab or the child)- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.component
- the name/type of the component.
-
setComponentEnabled
Enables or disables a component. This only works for components which are derived from theBehaviour
component! If the component is not derived fromBehaviour
, nothing happens- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.component
- the name/type of the component.enabled
- true to set the component enabled, false to disable it.
-
setComponentProperty
Sets a component property via reflection.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.component
- the name/type of the component.property
- the name of the property.value
- the value you want to assign to the property. Make sure to use the correct type!
-
invokeComponentMethod
-
setAnimatorParameter
Sets a float parameter on the animator controller component of the prefab or a child of this prefab.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the name of the parameter.value
- the value you want to assign.
-
setAnimatorParameter
Sets an int parameter on the animator controller component of the prefab or a child of this prefab.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the name of the parameter.value
- the value you want to assign.
-
setAnimatorParameter
Sets a boolean parameter on the animator controller component of the prefab or a child of this prefab.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the name of the parameter.value
- the value you want to assign.
-
setAnimatorTrigger
Sets the value of the given trigger parameter on the animator controller component.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.trigger
- the name of the trigger/parameter.
-
resetAnimatorTrigger
Resets (i.e unsets) the value of the given trigger parameter on the animator controller component.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.trigger
- the name of the trigger/parameter you want to reset.
-
startAnimatorPlayback
-
stopAnimatorPlayback
-
playAnimatorState
-
rebindAnimator
Rebinds all properties and mesh data with the animator controller. This is important if you change the hierarchy of the prefab (and want newly added childs to be affected by the animator).- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.keepState
- true if you want to keep the current animator state, false to reset it (default behaviour).
-
setMaterial
Assigns a new material to the prefab or a child of this prefab.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.material
- the material asset you want to assign.
-
setMaterialParameter
Sets a material parameter.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the material parameter. In Unity, they typically begin with an underscore.value
- the value you want to assign.
-
setMaterialParameter
Sets a material parameter.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the material parameter. In Unity, they typically begin with an underscore.value
- the value you want to assign.
-
setMaterialParameter
Sets a material parameter.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the material parameter. In Unity, they typically begin with an underscore.value
- the value you want to assign.
-
setMaterialParameter
Sets a material parameter.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the material parameter. In Unity, they typically begin with an underscore.value
- the value you want to assign.- Example:
-
setMaterialParameter
Sets a material parameter. You can also use this method to change a color parameter of a material.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the material parameter. In Unity, they typically begin with an underscore.value
- the value you want to assign.- Example:
-
setMaterialParameter
Sets a material parameter.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.parameter
- the material parameter. In Unity, they typically begin with an underscore.texture
- the texture you want to assign.- Example:
-
clearMaterialPropertyBlock
Removes a MaterialPropertyBlock from a Renderer component.- Parameters:
path
- the path to the child (contained by the actual prefab). If null, the prefab itself (root object) will be affected.materialIndex
- optional material index (if a renderer has multiple materials), or 0 by default.
-
setVFXParameter
-
setVFXParameter
-
setVFXParameter
-
setVFXParameter
-
setVFXParameter
-
setVFXParameter
-
setVFXPaused
-
setVFXPlayRate
-
playVFX
-
stopVFX
-
reinitVFX
-