About the included package

VRoid SDK includes UniVRM. UniVRM is imported automatically when VRoid SDK is imported. The version that this package supports is UniVRM 0.89.0.

Use CharacterModelExample

<aside> ✏️ By using VRoidHubController in Assets/VRoidSDK/Examples/CharacterModelExample/Prefabs, you can import a new scene with the same process.

</aside>

Method without using Example or Prefab

Login

class Login : MonoBehaviour
{
    void Start()
    {
                // ThreadContext used for communication
                var context = SynchronizationContext.Current;
                // Load the downloaded credential.json.bytes file
                var credential = Resources.Load<TextAsset>("credential.json");
                // App information used for configuration
                var credentialJson = credential.text;
                // Create a Config to be used for authorization
                var config = OauthProvider.LoadConfigFromCredential(credentialJson);
                // Create a Client to handle OAuth authorization
          var oauthClient = OauthProvider.CreateOauthClient(config, context);
                // Create a Browser for login
          var browser = BrowserProvider.Create(oauthClient, config);
                // Account files are saved locally and have not expired
                var isLoggedIn = oauthClient.IsAccountFileExist() && !oauthClient.IsAccessTokenExpired();
                // Login
                if (!isLoggedIn)
                {
                        // If already authorized but expired, it gets reauthorized.
                        // Otherwise opens a browser and starts the authorization flow.
                        oauthClient.Login(
                            browser,
                            (account) => { /*if login is successful*/ },
                        (error) => { /*if login fails*/ }
                        );
                }
    }
}

Loading models

oauthClient.Login(
        browser,
        (account) => {
            // Initialize the ModelLoader used for model loading
            ModelLoader.Initialize(
                config,                  // Config created from Credentials
                defaultApi,              // Authorized API
                "PASSWORD_FOR_YOUR_APP", // The model's encryption password
                10                       // Maximum number of caches for a model
            );

            defaultApi.GetAccountCharacterModels(10, (models) => {
                // Start model loading
                ModelLoader.LoadVrm(
                    models[0],  // Model to load
                    (gameObject) => {
                        // Callback after loading is complete
                        gameObject.transform.parent = this.transform;
                    },
                    (progress) => {
                        // Loading progress callback
                    },
                    (error) => {
                        // Callback when an error occurs
                    }
                );
            }, (error) => { });
        },
    (error) => { /*if login fails*/ }
    );