Translations of this page:

Sidebar

en:vci:script:reference:exportassets

vci.assets(ExportAssets)

This is a method to handle the components attached to a VCI. You can do the following.
Moreover, the methods with _ALL_ prefix are run on VCIs of everyone in the same studio.

  • Playback of an Audio
  • Playback of an Animation
  • Change the color or UV of a Material

List of methods

For the latest list of the methods, refer to “types.lua” file in “EmbeddedScriptWorkspace” folder.

Method Description
IsMine Returns true for the client who spawned the VCI, otherwise returns nil.
SetMaterialColorFromIndex Change the color of the material specified by an Indexnumber
SetMaterialColorFromName Change the color of the material specified by a name
SetMaterialTextureOffsetFromIndex Change the UV offset of the material specified by an Indexnumber
SetMaterialTextureOffsetFromName Change the UV offset of the material specified by a name
PlayAnimationFromIndex Playback an Animation specified by an Indexnumber
PlayAnimationFromName Playback an Animation specified by a name
StopAnimation
PlayAudioFromIndex Playback an Audio file specified by an Indexnumber
PlayAudioFromName Playback an Audio file specified by a name
PauseAudioFromIndex Pause an Audio file specified by an Indexnumber
PauseAudioFromName Playback an Audio file specified by a name
StopAudioFromIndex Stops an Audio file specified by an Indexnumber
StopAudioFromName Stops an Audio file specified by a name
HapticPulseOnGrabbingController Used to rumble the controllers
HapticPulseOnTouchingController Used to rumble the controllers

The methods with _ALL_ are synchronized and run on other clients as well.
If you want the result to be the same in all clients, use methods with _ALL_ prefix.

Method Description
_ALL_SetMaterialColorFromIndex Change the color of the material specified by an Indexnumber
_ALL_SetMaterialColorFromName Change the color of the material specified by a name
_ALL_SetMaterialTextureOffsetFromIndex Change the UV offset of the material specified by an Indexnumber
_ALL_SetMaterialTextureOffsetFromName Change the UV offset of the material specified by a name
_ALL_PlayAnimationFromIndex Playback an Animation specified by an Indexnumber
_ALL_PlayAnimationFromName Playback an Animation specified by a name
_ALL_StopAnimation
_ALL_PlayAudioFromIndex Playback an Audio file specified by an Indexnumber
_ALL_PlayAudioFromName Playback an Audio file specified by a name
_ALL_PauseAudioFromIndex Pause an Audio file specified by an Indexnumber
_ALL_PauseAudioFromName Playback an Audio file specified by a name
_ALL_StopAudioFromIndex Stops an Audio file specified by an Indexnumber
_ALL_StopAudioFromName Stops an Audio file specified by a name
_ALL_HapticPulseOnGrabbingController Used to rumble the controllers
_ALL_HapticPulseOnTouchingController Used to rumble the controllers

Synchronization of VCI

When you are creating something that moves over a network, you have to take the synchronization into account.
In a scenario where there are three people (A, B and C) in a single Virtual Cast studio, the act of applying the result of the person A moving an object to the computer of person B and C is called “synchronization.”
On the other hand, when something moves only in the computer of the person who moved it, that situation is called “working in local only.”
Following are the most common way of synchronization in VCI.

  • Transform is synchronized by Virtual Cast feature.
  • Methods with _ALL_ will be synchronized and run.
  • Use sync variables to sync the state of VCIs.

Basically, use the methods with _ALL_ so that the VCI behaves the same in every user's clients.
* For simple VCIs, such as the one that plays a sound, you can just call _ALL_ in an event function.
On the other hand, if you want everyone's VCIs to have varying states, make them run locally so that the states won't be synchronized.

For details on the synchronization of transform, refer to About VCI items and subitems.


IsMine

Determines if the user is the owner (user that spawned the VCI) of the VCI.

main.lua
function updateAll() -- This is run by all users regardless of ownership
    if vci.assets.IsMine then
        print("The owner of the VCI")
    end
end

The result

The owner of the VCI
(This is only shown on the Console of the owner of the VCI (the user which spawned the VCI))

SetMaterialColor

Example

main.lua
function onUse(self)
    print("onUse")
    local r = math.random()
    local g = math.random()
    local b = math.random()
    vci.assets._ALL_SetMaterialColorFromIndex(0, Color.__new(r,g,b))
end

The result

(Changes the color randomly when the grip button is pressed)

Change the color of a material. The color can be specified in two ways:

  • SetMaterialColorFromIndex(Material number,Color)
  • SetMaterialColorFromName(“Material name”,Color)

You can also specify the alpha value (transparency) in the Color, which can make materials such as Transparent to translucent.

main.lua
function onUse(self)
    print("onUse")
    local r = 1.0
    local g = 0.0
    local b = 0.0
    local a = 0.5
    vci.assets._ALL_SetMaterialColorFromIndex(0, Color.__new(r,g,b,a))
end

The result

(Change the material to be translucent red)

SetMaterialTextureOffset

Example

main.lua
function SetCounterOffset(count)
    local offset = Vector2.zero
 
    -- y shift
    local Yshift = math.floor(count / 4)    
    offset.y = -0.25 * Yshift
 
    -- x shift
    local Xshift = count % 4
    offset.x = 0.25 * Xshift
 
    vci.assets._ALL_SetMaterialTextureOffsetFromName("Counter", offset)
end

The result

(Based on the count value, determines the number of times to shift in the X direction and the Y direction, then changes the Counter)


The example above uses a 4-by-4 grid (up to 16 patterns) and shifts the UV.
The origin position of the 3D model's UV is upper left corner.
If the count value is 1, the number of times to shift in the Y direction is 0 and in the X direction is 1. Which result in the UV to shift to the position of “1.”
If the count value is 8, the number of times to shift in the Y direction is 2 and in the X direction is 0. Which result in the UV to shift to the position of “8.”
For a detailed explanation of how to create a counter, refer to the example.
→Example in preparation


PlayAnimation / StopAnimation

Example

main.lua
function onGrab(target)
    -- Play different animations based on the name of the target SubItem
    if target == "Subitem1" then
        vci.assets._ALL_PlayAnimationFromName("Subitem1",true) --true/false > whether or not to loop
    end
 
    if target == "Subitem2" then
        vci.assets._ALL_PlayAnimationFromName("Subitem2",true) --true/false > whether or not to loop
    end
end

The result

(When you grab the Subitem1, the animation "Subitem1" is played. When you grab the Subitem2, the animation "Subitem2" is played)

The example above controls the animation played with a Subitem.
The name of the animation files does not necessarily have to have the same name as the name of a Subitem. In the example, they are given the same name just for the sake of understandability.
For a detailed explanation on how to create an animation and set it up, refer to the sample.
* The example in preparation


PlayAudio

Example

main.lua
function onUse(target)
    if target == "gun" then
        vci.assets._ALL_PlayAudioFromName("gun")
        vci.assets._ALL_PlayAnimationFromName("gun",false) --true/false > whether or not to loop
    end
end

The result

(When a VCI named "gun" is used, play a sound and a firing animation)

The name of the audio file and the animation file must be “gun”.
The animation file replicates gunfire by deforming a fire object. (Not needed if just the sound is enough for you)
An audio file is quite loud with default volume, so it would be a good idea to adjust the volume from the inspector.
Check the loudness by running it in the Editor. Unity Audio Source


PauseAudio

Example

main.lua
 

The result

 

Description


StopAudio

Example

main.lua
 

The result

 

Description


HapticPulseOnGrabbingController

Example

main.lua
function onUse(use)
    vci.assets.HapticPulseOnGrabbingController(use, 3000, 0.1)
end

The result

(The used VCI rumbles for 0.1 second with the intensity of 3000)

The argument is (The target for the rumble, intensity of the rumble, length of the rumble).
Specify the target for the rumble with string and the intensity in a value between 0 to 3999.


Method name

Example

main.lua
 

The result

 

Description


en/vci/script/reference/exportassets.txt · Last modified: 2021/11/18 18:32 by numa

Page Tools