live2D (sdk가 6.5 미지원으로 sprite로 대응)

This commit is contained in:
2026-08-08 22:13:54 +09:00
parent 9ce6930772
commit 8a4a001fe0
4278 changed files with 287426 additions and 18 deletions

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 75a9b098cacf60a4dbd2879ed40df13d
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
/**
* 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
{
/// <summary>
/// Shows how to enable the <see cref="CubismBuiltinAsyncTaskHandler"/> from script.
/// </summary>
public sealed class AsyncToggler : MonoBehaviour
{
#if !UNITY_WEBGL
/// <summary>
/// Controls async task handling.
/// </summary>
public bool EnableAsync = true;
/// <summary>
/// Last <see cref="EnableAsync"/> state.
/// </summary>
private bool LastEnableSync { get; set; }
#endif
#region Unity Event Handling
#if UNITY_WEBGL
/// <summary>
/// Called by Unity.
/// </summary>
private void Start()
{
// Deactivate Async.
CubismBuiltinAsyncTaskHandler.Deactivate();
}
#else
/// <summary>
/// Called by Unity. Enables/Disables async task handler.
/// </summary>
private void Update()
{
if (EnableAsync == LastEnableSync)
{
return;
}
if (EnableAsync)
{
CubismBuiltinAsyncTaskHandler.Activate();
}
else
{
CubismBuiltinAsyncTaskHandler.Deactivate();
}
LastEnableSync = EnableAsync;
}
/// <summary>
/// Called by Unity. Disables async task handler.
/// </summary>
private void OnDestroy()
{
EnableAsync = false;
Update();
}
#endif
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f22e5acc2345e624b898e84b16306e17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1c90db99e86a760449d0a854b3fbd422
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,175 @@
/**
* 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 System;
using UnityEngine;
using UnityEngine.UI;
namespace Live2D.Cubism.Samples.AsyncBenchmark
{
/// <summary>
/// Automatically adjust the fps to the set value.
/// </summary>
public sealed class BenchmarkController : MonoBehaviour
{
/// <summary>
/// Interval time before the model can spawn.
/// </summary>
public readonly float SpawnIntervalTimeSecond = 1.0f;
/// <summary>
/// Target frame rate value.
/// </summary>
[SerializeField]
public int TargetFrameRate = 60;
/// <summary>
/// UI for displaying <see cref="ElapsedTime"/> values.
/// </summary>
[SerializeField]
public Text ReachedElapsedTimeUi = null;
/// <summary>
/// UI to display the number of instances of the model when the target frame rate is finally reached.
/// </summary>
[SerializeField]
public Text InstancesCountUi = null;
/// <summary>
/// Save the maximum frame rate.
/// </summary>
private float HighestRecordedFrameRate { get; set; }
/// <summary>
/// Whether the model is spawnable or not.
/// </summary>
private bool CanModelSpawn { get; set; }
/// <summary>
/// Add delta time.
/// </summary>
private float SpawnTimeCount { get; set; }
/// <summary>
/// Time elapsed since <see cref="CanModelSpawn"/> was set to false.
/// </summary>
private float ElapsedTime { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.FpsCounter"/> Component.
/// </summary>
private FpsCounter FpsCounter { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.ModelSpawner"/> Conponent.
/// </summary>
private ModelSpawner ModelSpawner { get; set; }
/// <summary>
/// Called by Unity. Setting vsync and target frame rate.
/// </summary>
private void Awake()
{
// Setting vsync and targetFrameRate.
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = TargetFrameRate + 1;
// Getting the component.
FpsCounter = GetComponent<FpsCounter>();
ModelSpawner = GetComponent<ModelSpawner>();
}
/// <summary>
/// Called by Unity. Record the maximum frame rate and manage model spawning.
/// </summary>
private void Update()
{
RecordFrameRate();
ManageSpawn();
}
/// <summary>
/// Records the maximum frame rate within a given time period.
/// </summary>
private void RecordFrameRate()
{
/// Get value from <see cref="FpsCounter"/> Component.
var fps = FpsCounter.Fps;
// Compare the measured value with the maximum value so far.
HighestRecordedFrameRate = fps >= HighestRecordedFrameRate
? fps
: HighestRecordedFrameRate;
// Whether you have time to make a decision.
if (SpawnTimeCount < SpawnIntervalTimeSecond)
{
SpawnTimeCount += Time.deltaTime;
return;
}
// If the model is not ready to spawn, add the elapsed time.
if (!CanModelSpawn && (ModelSpawner.InstancesCount != 0))
{
ElapsedTime += SpawnIntervalTimeSecond;
// Combine strings and display them in UI.
var elapsedTimeString = TimeConversion(Mathf.FloorToInt(ElapsedTime));
ReachedElapsedTimeUi.text = string.Format(" Reached Time:{0}", elapsedTimeString);
}
// Whether the recorded frame rate has reached the target frame rate.
CanModelSpawn = TargetFrameRate <= HighestRecordedFrameRate;
// Reset variables and properties.
SpawnTimeCount = 0.0f;
HighestRecordedFrameRate = 0.0f;
}
/// <summary>
/// Convert seconds to "hours:minutes:seconds".
/// </summary>
/// <param name="second">Number of seconds it conversion source.</param>
/// <returns>String type converted to "hours:minutes:seconds" notation.</returns>
private string TimeConversion(int second)
{
// Generate TimeSpan structure type.
var timeSpan = new TimeSpan(0, 0, second);
return timeSpan.ToString();
}
/// <summary>
/// Managing model spawn.
/// </summary>
private void ManageSpawn()
{
if (SpawnTimeCount < SpawnIntervalTimeSecond)
{
return;
}
// When the model can spawn
if (CanModelSpawn)
{
// Spawn the model.
ModelSpawner.IncreaseInstances();
// Reset variable.
ElapsedTime = 0;
}
// When the model can't spawn
else
{
/// Get Instances Count from <see cref="ModelSpawner"/> Component and update UI.
var instancesCount = ModelSpawner.InstancesCount;
InstancesCountUi.text = string.Format(" Reached Model Count:{0}", instancesCount.ToString());
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45247f3a2594a4b43ab1210b53006f54
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
[English](Description.md) / [日本語](Description.ja.md)
---
# Async Benchmark
このシーンでは、CubismSDKの簡単なベンチマークが可能です。

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7a51c19a83b5443ba8391581368634c5
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
[English](Description.md) / [日本語](Description.ja.md)
---
# Async Benchmark
This scene allows simple benchmarking of the Cubism SDK.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1e25b33344cc69f4e851cc8f50b9de3d
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2a75b78ff25bb0c4da6df6b7f91e6717
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
/**
* 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 UnityEditor;
namespace Live2D.Cubism.Samples.AsyncBenchmark.Editor
{
/// <summary>
/// Dynamically switch the display on <see cref="FrameRateUiHolder"/> inspector.
/// </summary>
[CanEditMultipleObjects]
[CustomEditor(typeof(FrameRateUiHolder))]
public class FrameRateUiHolderInspector : UnityEditor.Editor
{
// Components to add inspector enhancements.
private FrameRateUiHolder Target { get; set; }
/// <summary>
/// Called by Unity. Getting target component and Initializing.
/// </summary>
private void Awake()
{
Target = target as FrameRateUiHolder;
}
public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();
// Load a value from the internal cache.
serializedObject.Update();
//Whether to enable total uptime.
Target.HasShownElapsedTime = EditorGUILayout.ToggleLeft("Show Elapsed Time", Target.HasShownElapsedTime);
// Enable/disable observation.
Target.HasShownFrameRate = EditorGUILayout.ToggleLeft("Show Frame Rate", Target.HasShownFrameRate);
// Load properties.
var maximumFpsUi = serializedObject.FindProperty("HighestFrameRateUi");
var minimumFpsUi = serializedObject.FindProperty("LowestFrameRateUi");
var elapsedTimeUi = serializedObject.FindProperty("ElapsedTimeUi");
// View and change properties.
EditorGUILayout.PropertyField(maximumFpsUi);
EditorGUILayout.PropertyField(minimumFpsUi);
EditorGUILayout.PropertyField(elapsedTimeUi);
// Apply changes to the serializedProperty.
serializedObject.ApplyModifiedProperties();
// Changes the state of objects.
Target.HighestFrameRateUi.enabled = Target.HasShownFrameRate;
Target.LowestFrameRateUi.enabled = Target.HasShownFrameRate;
Target.ElapsedTimeUi.gameObject.SetActive(Target.HasShownElapsedTime);
if (EditorGUI.EndChangeCheck())
{
// Apply changes and set dirty flag.
EditorUtility.SetDirty(Target);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fcee6eaa99eb52b469da14650e7e952b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
{
"reference": "GUID:e5d337e0b3581c343aafde08e6e1727e"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 11487b2fc5ca5774f9704a4068423742
AssemblyDefinitionReferenceImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
/**
* 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 UnityEngine;
using UnityEngine.UI;
namespace Live2D.Cubism.Samples.AsyncBenchmark
{
/// <summary>
/// Measures Fps for on-screen display.
/// </summary>
public sealed class FpsCounter : MonoBehaviour
{
/// <summary>
/// UI component representing current model count.
/// </summary>
[SerializeField]
public Text FpsUi;
/// <summary>
/// Frame rate propertie to get from external sources.
/// </summary>
public float Fps { get; private set; }
/// <summary>
/// Time for FPS calculation.
/// </summary>
private float DeltaTime { get; set; }
#region Unity Event Handling
/// <summary>
/// Called by Unity. Initializes fields.
/// </summary>
private void Update()
{
// Update delta time.
DeltaTime += (Time.deltaTime - DeltaTime) * 0.1f;
// Compute FPS and update UI.
var fps = 1.0f / DeltaTime;
// Save the value to the property.
Fps = fps;
FpsUi.text = string.Format("({0:0.} fps)", fps);
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aae1af32819e41a4aad42efd297ff90a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,225 @@
/**
* 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 System;
using UnityEngine;
using UnityEngine.UI;
namespace Live2D.Cubism.Samples.AsyncBenchmark
{
/// <summary>
/// Measure the frame rate.
/// </summary>
public class FrameRateMeasurer : MonoBehaviour
{
/// <summary>
/// Target frame rate value.
/// </summary>
[SerializeField]
public int TargetFrameRate = 60;
/// <summary>
/// Whether the model is spawnable or not.
/// </summary>
private bool LessThanTargetFrameRate { get; set; }
/// <summary>
/// The highest frame rate on running the application.
/// </summary>
private float HighestFrameRate { get; set; }
/// <summary>
/// Save the maximum frame rate.
/// </summary>
private int CurrentHighestFrameRate { get; set; }
/// <summary>
/// Save Previous Frame <see cref="CurrentHighestFrameRate"/>.
/// </summary>
private int PreviousHighestFrameRate { get; set; }
/// <summary>
/// The lowest frame rate on running the application.
/// </summary>
private float LowestFrameRate { get; set; }
/// <summary>
/// Save the minimum frame rate.
/// </summary>
private int CurrentLowestFrameRate { get; set; }
/// <summary>
/// Save Previous Frame <see cref="CurrentLowestFrameRate"/>.
/// </summary>
private int PreviousLowestFrameRate { get; set; }
/// <summary>
/// Get Model Instances Count.
/// </summary>
private int InstancesCount { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.FpsCounter"/> Component.
/// </summary>
private FpsCounter FpsCounter { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.BenchmarkController"/> Component.
/// </summary>
private BenchmarkController BenchmarkController { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.ModelSpawner"/> Conponent.
/// </summary>
private ModelSpawner ModelSpawner { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.TotalElapsedTime"/> Component.
/// </summary>
private TotalElapsedTime TotalElapsedTime { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.FrameRateUiHolder"/> Component.
/// </summary>
private FrameRateUiHolder FrameRateUiHolder { get; set; }
/// <summary>
/// Displays the frame rate and observation time when the maximum frame rate is observed.
/// </summary>
private Text HighestFrameRateUi { get; set; }
/// <summary>
/// Displays the frame rate and observation time when the minimum frame rate is observed.
/// </summary>
private Text LowestFrameRateUi { get; set; }
/// <summary>
/// Called by Unity. Getting target component and Initializing.
/// </summary>
private void Start()
{
// Getting components and initializing.
FpsCounter = GetComponent<FpsCounter>();
BenchmarkController = GetComponent<BenchmarkController>();
ModelSpawner = GetComponent<ModelSpawner>();
TotalElapsedTime = GetComponent<TotalElapsedTime>();
FrameRateUiHolder = GetComponent<FrameRateUiHolder>();
HighestFrameRateUi = FrameRateUiHolder.HighestFrameRateUi;
LowestFrameRateUi = FrameRateUiHolder.LowestFrameRateUi;
/// If <see cref="BenchmarkController"/> is present, get <see cref="BenchmarkController.TargetFrameRate"/>.
TargetFrameRate = BenchmarkController != null
? BenchmarkController.TargetFrameRate
: TargetFrameRate;
}
// Update is called once per frame
private void Update()
{
/// Get value from <see cref="FpsCounter"/> Component.
var fps = Mathf.FloorToInt(FpsCounter.Fps);
// Compare the measured value with the maximum value so far.
CurrentHighestFrameRate = fps > CurrentHighestFrameRate
? fps
: CurrentHighestFrameRate;
// Compare the measured value with the maximum value so far.
CurrentLowestFrameRate = fps < CurrentLowestFrameRate
? fps
: CurrentLowestFrameRate;
// Whether the recorded frame rate has reached the target frame rate.
LessThanTargetFrameRate = TargetFrameRate > CurrentHighestFrameRate;
// When the observed value is lower than the set value.
if (LessThanTargetFrameRate)
{
// Assign the maximum and minimum values.
HighestFrameRate = HighestFrameRate < CurrentHighestFrameRate
? CurrentHighestFrameRate
: HighestFrameRate;
// Assign the maximum and minimum values.
LowestFrameRate = LowestFrameRate > CurrentLowestFrameRate
? CurrentLowestFrameRate
: LowestFrameRate;
// Has the values been changed?
var isMaximumFrameRateChange = (HighestFrameRate == CurrentHighestFrameRate) && (PreviousHighestFrameRate != CurrentHighestFrameRate);
var isMinimumFrameRateChange = (LowestFrameRate == CurrentLowestFrameRate) && (PreviousLowestFrameRate != CurrentLowestFrameRate);
var timeConversion = TimeConversion(TotalElapsedTime.ElapsedTime);
// Update ui.
if (isMaximumFrameRateChange)
{
var maximumObservationFrameRateText = string.Format("max ({0} fps)\n", HighestFrameRate);
HighestFrameRateUi.text = string.Concat(maximumObservationFrameRateText, timeConversion);
PreviousHighestFrameRate = CurrentHighestFrameRate;
}
if (isMinimumFrameRateChange)
{
var minimumObservationFrameRateText = string.Format("min ({0} fps)\n", LowestFrameRate);
LowestFrameRateUi.text = string.Concat(minimumObservationFrameRateText, timeConversion);
PreviousLowestFrameRate = CurrentLowestFrameRate;
}
}
// When the observed value is higher than the set value.
else
{
// Reset variables.
CurrentHighestFrameRate = 0;
PreviousHighestFrameRate = CurrentHighestFrameRate;
CurrentLowestFrameRate = TargetFrameRate;
PreviousLowestFrameRate = CurrentLowestFrameRate;
}
var storeInstancesCount = InstancesCount;
/// Get Instances Count from <see cref="ModelSpawner"/> Component
InstancesCount = ModelSpawner.InstancesCount;
if (storeInstancesCount != InstancesCount || InstancesCount == 0)
{
var timeConversion = TimeConversion(0);
// Reset ui.
var highestFrameRateText = string.Format("max (0 fps)\n");
HighestFrameRateUi.text = string.Concat(highestFrameRateText, timeConversion);
var lowesttFrameRateText = string.Format("min (0 fps)\n");
LowestFrameRateUi.text = string.Concat(lowesttFrameRateText, timeConversion);
// Reset variables.
CurrentHighestFrameRate = 0;
PreviousHighestFrameRate = CurrentHighestFrameRate;
HighestFrameRate = 0;
CurrentLowestFrameRate = TargetFrameRate;
PreviousLowestFrameRate = CurrentLowestFrameRate;
LowestFrameRate = TargetFrameRate;
}
}
/// <summary>
/// Convert seconds to "hours:minutes:seconds".
/// </summary>
/// <param name="second">Number of seconds it conversion source.</param>
/// <returns>String type converted to "hours:minutes:seconds" notation.</returns>
private string TimeConversion(int second)
{
// Generate TimeSpan structure type.
var timeSpan = new TimeSpan(0, 0, second);
return timeSpan.ToString();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9bb9e3187afcbf940b0c62f43c688fda
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
/**
* 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 UnityEngine;
using UnityEngine.UI;
namespace Live2D.Cubism.Samples.AsyncBenchmark
{
/// <summary>
/// Record when the frame rate falls below the set target frame rate.
/// </summary>
public class FrameRateUiHolder : MonoBehaviour
{
/// <summary>
/// Enable/disable observation.
/// </summary>
[SerializeField]
public bool HasShownFrameRate;
/// <summary>
/// Whether to enable total uptime.
/// </summary>
[SerializeField]
public bool HasShownElapsedTime;
/// <summary>
/// Displays the frame rate and observation time when the maximum frame rate is observed.
/// </summary>
[SerializeField]
public Text HighestFrameRateUi = null;
/// <summary>
/// Displays the frame rate and observation time when the minimum frame rate is observed.
/// </summary>
[SerializeField]
public Text LowestFrameRateUi = null;
/// <summary>
/// UI to display total benchmark uptime.
/// </summary>
[SerializeField]
public Text ElapsedTimeUi = null;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e53b3c070847eb2429f805793607c2e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Koharu
serializedVersion: 5
m_AnimatorParameters: []
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: 1107220330913208124}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1102 &1102068987388652362
AnimatorState:
serializedVersion: 5
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: body
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 8111a2bbebfc2014c92395318f2e4277, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1107 &1107220330913208124
AnimatorStateMachine:
serializedVersion: 5
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 1102068987388652362}
m_Position: {x: 24, y: 216, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 800, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 1102068987388652362}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f27586cd44c114b978374b537376c08f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 9100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,147 @@
/**
* 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.Core;
using Live2D.Cubism.Rendering;
using System.Collections.Generic;
using Live2D.Cubism.Framework.Tasking;
using UnityEngine;
using UnityEngine.UI;
using Random = System.Random;
namespace Live2D.Cubism.Samples.AsyncBenchmark
{
/// <summary>
/// Spawns models for benchmarking.
/// </summary>
public sealed class ModelSpawner : MonoBehaviour
{
/// <summary>
/// <see cref="CubismModel"/> prefab to spawn.
/// </summary>
[SerializeField]
public GameObject ModelPrefab;
/// <summary>
/// Attaches to instantiate object from <see cref="ModelPrefab"/>.
/// </summary>
[SerializeField]
public RuntimeAnimatorController AnimatorController;
/// <summary>
/// UI component representing current model count.
/// </summary>
[SerializeField]
public Text ModelCountUi;
/// <summary>
/// Holds the number of instances of the model.
/// </summary>
public int InstancesCount { get; private set; }
/// <summary>
/// Model instances.
/// </summary>
private List<GameObject> Instances { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.BenchmarkController"/> Component.
/// </summary>
private BenchmarkController BenchmarkController { get; set; }
#region Interface for UI Elements
/// <summary>
/// Adds a new instance.
/// </summary>
public void IncreaseInstances()
{
if (ModelPrefab == null)
{
return;
}
// Spawn new instance.
var instance = Instantiate(ModelPrefab);
if (AnimatorController)
{
instance.GetComponent<Animator>().runtimeAnimatorController = AnimatorController;
}
var random = new Random();
var offsetX = (float)random.Next(-1000, 1000) / 1000f;
var offsetY = (float)random.Next(-1000, 1000) / 1000f;
var screenToWorld = Camera.main.ScreenToWorldPoint(
new Vector3(
Screen.width,
Screen.height,
Camera.main.nearClipPlane));
instance.transform.position = new Vector3(
screenToWorld.x * offsetX,
screenToWorld.y * offsetY,
instance.transform.position.z);
// Register instance and update UI.
Instances.Add(instance);
// Make sure to assign a unique sorting order to the instance.
instance.GetComponent<CubismRenderController>().SortingOrder = Instances.Count;
// Update propertie.
InstancesCount = Instances.Count;
// Update UI.
ModelCountUi.text = BenchmarkController == null
? Instances.Count.ToString()
: string.Concat("Current Model Count:", Instances.Count.ToString());
}
/// <summary>
/// Removes an instance.
/// </summary>
public void DecreaseInstances()
{
// Return early if there's nothing to decrease.
if (Instances.Count == 0)
{
return;
}
// Remove last instance and update UI.
DestroyImmediate(Instances[Instances.Count - 1]);
Instances.RemoveAt(Instances.Count - 1);
ModelCountUi.text = Instances.Count.ToString();
}
#endregion
#region Unity Event Handling
/// <summary>
/// Called by Unity. Initializes fields.
/// </summary>
private void Start()
{
Instances = new List<GameObject>();
BenchmarkController = GetComponent<BenchmarkController>();
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 85a778bfb76699e4d970a3da1db1b89b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
/**
* 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 System;
using UnityEngine;
using UnityEngine.UI;
namespace Live2D.Cubism.Samples.AsyncBenchmark
{
public class TotalElapsedTime : MonoBehaviour
{
/// <summary>
/// Interval time before the model can spawn.
/// </summary>
public readonly int UpdateInterval = 1;
/// <summary>
/// Total benchmark uptime.
/// </summary>
[SerializeField, HideInInspector]
public int ElapsedTime = 0;
/// <summary>
/// Add delta time.
/// </summary>
private float UpdateIntervalCount { get; set; }
/// <summary>
/// UI to display total benchmark uptime.
/// </summary>
private Text TotalElapsedTimeText { get; set; }
/// <summary>
/// <see cref="AsyncBenchmark.FrameRateUiHolder"/> Component.
/// </summary>
private FrameRateUiHolder FrameRateUiHolder { get; set; }
/// <summary>
/// Called by Unity. Getting FpsObservation Component and Getting Component from FpsObservation.
/// </summary>
private void Start()
{
FrameRateUiHolder = GetComponent<FrameRateUiHolder>();
TotalElapsedTimeText = FrameRateUiHolder.ElapsedTimeUi;
}
/// <summary>
/// Called by Unity. Update Total Operating Time.
/// </summary>
private void Update()
{
// Whether you have time to make a decision.
if (UpdateIntervalCount < UpdateInterval)
{
UpdateIntervalCount += Time.deltaTime;
return;
}
// Update total benchmark uptime.
ElapsedTime += UpdateInterval;
if (TotalElapsedTimeText != null)
{
TotalElapsedTimeText.text = TimeConversion(ElapsedTime);
}
// Reset variable.
UpdateIntervalCount = 0.0f;
}
/// <summary>
/// Convert seconds to "hours:minutes:seconds".
/// </summary>
/// <param name="second">Number of seconds it conversion source.</param>
/// <returns>String type converted to "hours:minutes:seconds" notation.</returns>
private string TimeConversion(int second)
{
// Generate TimeSpan structure type.
var timeSpan = new TimeSpan(0, 0, second);
return timeSpan.ToString();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 92567bfc643287d4083f40b8a8a594bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: