Get User Data Set in ArtMeshes
Updated: 11/21/2017
This section explains how to get the “UserData” information set in the ArtMesh from the model.
Summary
[UserData] is a feature that allows users to add desired metadata to an ArtMesh.
Depending on how the user data is handled, the ArtMesh can be used for a variety of things, such as designating that ArtMesh as a collision detection or applying special shading.
See “User Data and Events” for information on how to set up user data in an ArtMesh.
To retrieve the user data set in the ArtMesh, follow the steps described below.
Click [Create] in the Project window, then click [C# Script] to create a C# script.
In this example, name it UserDataTest.
Rewrite the content of the UserDataTest you created as follows.
using Live2D.Cubism.Framework.UserData; using UnityEngine; public class UserDataTest : MonoBehaviour { private void Start () { var userDatas = gameObject.GetComponentsInChildren<CubismUserDataTag>(); foreach (var userData in userDatas) { Debug.Log( "Drawable ID : " + userData.gameObject.name +"\n" + "Value : " + userData.Value ); } } }
The Prefab of the model with user data is then placed in the Hierarchy.
Attach the UserDataTest component created above to the root of the placed Prefab.
See the tutorial on the “Import SDK” page for more information on importing models.
This completes the setup.
When the Scene is executed in this state, the Console window will output the ID of the ArtMesh to which the user data is set and the string set in the user data.