/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ using Live2D.Cubism.Framework.Tasking; using UnityEngine; namespace Live2D.Cubism.Samples.AsyncBenchmark { /// /// Shows how to enable the from script. /// public sealed class AsyncToggler : MonoBehaviour { #if !UNITY_WEBGL /// /// Controls async task handling. /// public bool EnableAsync = true; /// /// Last state. /// private bool LastEnableSync { get; set; } #endif #region Unity Event Handling #if UNITY_WEBGL /// /// Called by Unity. /// private void Start() { // Deactivate Async. CubismBuiltinAsyncTaskHandler.Deactivate(); } #else /// /// Called by Unity. Enables/Disables async task handler. /// private void Update() { if (EnableAsync == LastEnableSync) { return; } if (EnableAsync) { CubismBuiltinAsyncTaskHandler.Activate(); } else { CubismBuiltinAsyncTaskHandler.Deactivate(); } LastEnableSync = EnableAsync; } /// /// Called by Unity. Disables async task handler. /// private void OnDestroy() { EnableAsync = false; Update(); } #endif #endregion } }