/**
* 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
{
///
/// Interval time before the model can spawn.
///
public readonly int UpdateInterval = 1;
///
/// Total benchmark uptime.
///
[SerializeField, HideInInspector]
public int ElapsedTime = 0;
///
/// Add delta time.
///
private float UpdateIntervalCount { get; set; }
///
/// UI to display total benchmark uptime.
///
private Text TotalElapsedTimeText { get; set; }
///
/// Component.
///
private FrameRateUiHolder FrameRateUiHolder { get; set; }
///
/// Called by Unity. Getting FpsObservation Component and Getting Component from FpsObservation.
///
private void Start()
{
FrameRateUiHolder = GetComponent();
TotalElapsedTimeText = FrameRateUiHolder.ElapsedTimeUi;
}
///
/// Called by Unity. Update Total Operating Time.
///
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;
}
///
/// Convert seconds to "hours:minutes:seconds".
///
/// Number of seconds it conversion source.
/// String type converted to "hours:minutes:seconds" notation.
private string TimeConversion(int second)
{
// Generate TimeSpan structure type.
var timeSpan = new TimeSpan(0, 0, second);
return timeSpan.ToString();
}
}
}