VGO runtime loading - izayoijiichan/VGO GitHub Wiki

1. Load scene

Load LoadScene when using the UniVGO sample project.

image1

2. File settings

Select the RuntimeLoader game object in Hierarchy,
In Inspector, enter the full path of the VGO file you want to load at runtime in Local File Path.

image1

3. Run game

Press the play button to run the game.

Confirm that the VGO file is loaded.

If an error has occurred, the Console will display the details of the error.

Script

If you write your own script, write as follows.

    using System;
    using UnityEngine;
    using UniVgo2;

    public class VgoRuntimeLoader : MonoBehaviour
    {
        [SerializeField]
        private string _FilePath = string.Empty;

        private readonly VgoImporter _VgoImporter = new();

        private VgoModelAsset? _VgoModelAsset = null;

        private void Start()
        {
            VgoModelAsset vgoModelAsset = _VgoImporter.Load(_FilePath);

            //_VgoImporter.ReflectSkybox(Camera.main, vgoModelAsset);

            vgoModelAsset.ReflectSkybox(Camera.main);

            _VgoModelAsset = vgoModelAsset;
        }

        // When using stream (FileStream, MemoryStream, etc...)
        //private async Task Start()
        //{
        //    using var vgoStream = new FileStream(_FilePath, FileMode.Open, FileAccess.Read);
        //
        //    _VgoModelAsset = await _VgoImporter.LoadAsync(vgoStream, cancellationToken);
        //
        //    vgoStream.Dispose();
        //}

        private void OnDestroy()
        {
            _VgoModelAsset?.Dispose();
        }
    }