/// <summary> /// Unity callback that is invoked before the first frame update /// and prior to Start(). /// </summary> private void Awake() { // Set import options so that imported models are // automatically scaled to a standard size. ImportOptions = new GltfImportOptions { AutoScale = true, AutoScaleSize = ModelManager.Instance.DefaultModelSize }; // Set up callbacks for logging progress messages during // glTF imports. The default behaviour is to render // progress messages directly on top of the window using // IMGUI methods, whereas the WebGL build renders the progress // messages as HTML as part of the main web page, // outside of the Unity WebGL canvas. ProgressLog.Instance.AddLineCallback = Gui.Instance.AddProgressLogLine; ProgressLog.Instance.UpdateLineCallback = Gui.Instance.UpdateProgressLogLine; ProgressLog.Instance.ResetLogCallback = Gui.Instance.ResetProgressLog; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN gameObject.AddComponent <WindowsGameManager>(); #elif UNITY_ANDROID gameObject.AddComponent <AndroidGameManager>(); #elif UNITY_WEBGL gameObject.AddComponent <WebGlGameManager>(); #endif }
/// <summary> /// Unity callback that is invoked before the first frame. /// Create the glTF import task and set up callbacks for /// progress messages and successful completion. /// </summary> void Start() { // Uniformly scale the model such that the longest // dimension of its world-space axis-aligned bounding // box becomes 4.0 units. var importOptions = new GltfImportOptions(); importOptions.AutoScale = true; importOptions.AutoScaleSize = 4.0f; // Note: To import a local .gltf/.glb/.zip file, you may // instead pass an absolute file path to GetImportTask // (e.g. "C:/Users/Joe/Desktop/piggleston.glb"), or a byte[] // array containing the raw byte content of the file. _task = RuntimeGltfImporter.GetImportTask( "https://awesomesaucelabs.github.io/piglet-webgl-demo/StreamingAssets/cartoon_hartman.zip", importOptions); _task.OnCompleted = OnComplete; }