Edit Code
Learn how to add code to your Unity project while getting data from the cloud.
Now that you are able to successfully stream the 3D model into Unity, it's time to make some custom adjustments.
Each asset will be instantiated with a script named CustomBehaviour.cs
attached. You can edit this script to create any behavior you would like while referencing additional data streamed from the cloud.
Code Example
From the project's packages folder, open the /co.echo3d.unity/Runtime/CustomBehaviour.cs
script:
You can add any custom code after line 21. An example follows.
Querying Metadata
Lines 22-28 are an example that queries the entry's metadata for a key called name
, and if such key exists, set the game object's name to the corresponding value:
Without the name
key being set, the default game object's name is the asset filename.
key
value
name
empire_state
Run Unity again and notice that the game object name automatically changes.
Great work! 🎉
Posting Metadata
In order to call this function from any other script you can use the Echo3DService instance to callUpdateEntryData
function with this single line of code:
Where <ENTRY_ID>
is the a specific entry ID you are trying to post metadata too, <DATA>
is the data key (e.g. scale
), and <VALUE>
is the data value (e.g. 2
).
Subscribing for Metadata Changes
Add the following code to your Start
function to register an action that will be executed when metadata is received from the cloud.
Last updated
Was this helpful?