Readonly
unityThe handle to access the property of the Unity component.
This API requires the exact name of the property of the Unity component. The name of the property shown in the Unity Editor may be different from the actual property name. Please refer to the Unity API reference for details.
The properties that can be accessed with unityProp
must be one of the following data types:
bool
, int
, float
, double
, string
, Vector2
, Vector3
, Vector4
, Quaternion
, Color
, or a derived type of Enum
.
If you try to access a property of a different data type, null
will be returned when getting the property, and an exception will be thrown when setting the property.
Enum
is represented as an int
value.
Similarly, when setting a property of type Enum
, specify an int
value.
Please refer to the Unity API reference to see the correspondence between the value of Enum
and the internal int
value.
In Player Script
, the properties updated by this method are only reflected in the player running the script.
In Scriptable Item
, the value of the property specified by this method is synchronized over the network.
Please be aware it may not be reflected immediately, and no interpolation is applied to the value.
// An example for Scriptable Item to set the property of the component in SubNode
let node = $.subNode("Cube");
let meshRenderer = node.getUnityComponent("MeshRenderer");
meshRenderer.unityProp.receiveShadows = false;
let transform = node.getUnityComponent("Transform");
transform.unityProp.localScale = new Vector3(2, 2, 2);
// An example for Player Script to set the property of the component in PlayerLocalObject
let imageObject = _.playerLocalObject("ImageObject");
let image = imageObject.getUnityComponent("Image");
image.unityProp.color = new Color(1, 0, 0, 1);
let textObject = _.playerLocalObject("TextObject");
let textComponent = textObject.getUnityComponent("Text");
textComponent.unityProp.text = "Hello, World!";
In Scriptable Item
, This API will result in undefined behavior if the same property is updated by this API and other methods.
When this API and Animator etc. update the same property, the behavior is undefined.
Also, other APIs such as SubNode.setPosition that update Transform.localPosition
internally, will result in undefined behavior when used in combination with this API to update Transform.localPosition
.
To avoid undefined behavior, consider the following when using Scriptable Item
:
For example, consider using ClusterScript.setPosition to change the position of an item, instead of using this API to update Transform.localPosition
.
In Scriptable Item
, the available properties with this API are limited to make the properties synchronized between players.
The available properties are enabled
and following properties for each types.
Beta
Registers a callback function to be called when a Button
in a Player Local UI is interacted with.
The component should be a Button
and should be obtained by PlayerLocalObject.getUnityComponent.
If the component is not a Button
, or the instance is obtained by ClusterScript.getUnityComponent or SubNode.getUnityComponent, an error will occur.
If the same callback is registered multiple times for a Button
component, only the last registration will take effect.
The callback will be called with isDown = true
when pressed, and called again with isDown = false
when the button is released.
This callback is not necessarily called with isDown = false
after being called with isDown = true
.
For example, if you hold down the button, move the pointer outside of the button, and then release it, the isDown = false
callback will not be triggered.
method that is called when the button is pressed or released.
Beta
Plays the component if the handled component is PlayableDirector
, AudioSource
, ParticleSystem
, or VideoPlayer
.
An error will occur for other components.
If the instance is obtained by ClusterScript.getUnityComponent by SubNode.getUnityComponent and the handled component is PlayableDirector
, AudioSource
, its time will look same for all players.
The beginning of the playback may be skipped.
When play()
is called for already playing component, the component will stop and restart playing.
For ParticleSystem
, this method also plays particles attached in children objects.
If both a parent and child object have ParticleSystem
, please execute play()
or stop()
on the particles of the parent only.
If play()
or stop()
is called for multiple ParticleSystem
s in a parent-child relationship, they may not play correctly.
For VideoPlayer
, it is recommended to specify Video Clip
for Source
and Material Override
for Render Mode
.
If Source
is set to Video Clip
, the playback time will look same for all players.
The beginning of the playback may be skipped.
Also, depending on the size of the video and the encoding method, it may take some time for playback to start.
If Source
is URL
, there will be a large delay until the playback actually starts.
Also, the playback start timing and playback time will not be consistent for each player.
If the rendering result of VideoPlayer
is applied to Render Texture
, the rendering state when not playing will change depending on the OS and texture settings.
Consider to hide the texture when VideoPlayer
is not playing.
Beta
Sets Bool
parameter value of the AnimatorController, if the handled component is Animator
.
An error will occur for other components.
This method does nothing if the parameter does not exist, or if it is not Bool
.
Name of the parameter
The value to set
Beta
Sets Float
parameter value of the AnimatorController, if the handled component is Animator
.
An error will occur for other components.
This method does nothing if the parameter does not exist, or if it is not Float
.
Name of the parameter
The value to set
Beta
Sets Integer
parameter value of the AnimatorController, if the handled component is Animator
.
An error will occur for other components.
This method does nothing if the parameter does not exist, or if it is not Integer
.
Name of the parameter
The value to set
Beta
Stops the component playback if the handled component is PlayableDirector
, AudioSource
, ParticleSystem
, or VideoPlayer
.
An error will occur for other components.
Playback time will be reset when stop()
is called for PlayableDirector
and VideoPlayer
.
For ParticleSystem
, this method also stops particles attached in children objects.
If both a parent and child object have ParticleSystem
, please execute play()
or stop()
on the particles of the parent only.
If play()
or stop()
is called for multiple ParticleSystem
s in a parent-child relationship, they may not play correctly.
Generated using TypeDoc
The handle of the Unity component attached to an object.
This handle can be obtained by following APIs.
If the instance is obtained by ClusterScript.getUnityComponent or SubNode.getUnityComponent, the operations to the handle will change the appearance and behavior of the item. The change can be seen by any players.
If the instance is obtained by PlayerLocalObject.getUnityComponent, the operation to the handle will change the appearance and behavior of the item, which can be seen only by the player.
There APIs supports same list of component names. Below is the list of available type names for
getUnityComponent
method.