using UnityEngine;
namespace VketCloudGUITools.Serialization
{
///
/// インポート時の進捗管理
///
public class ImportProgress
{
///
/// デバッグ表示用のタグ
///
private string _tag = string.Empty;
///
/// デバッグ表示用の詳細
///
private string _detail = string.Empty;
///
/// 子タスクの重み
///
private float _childProgressWeight = 0f;
///
/// 子タスク
///
private ImportProgress _childProgress = null;
///
/// 親タスク
///
private ImportProgress _parentProgress = null;
///
/// 自己タスク完了量
///
private float _selfProgress = 0f;
public string Tag => _tag;
public string Detail => _detail;
public ImportProgress Root
{
get
{
if (_parentProgress == null)
{
return this;
}
else
{
return _parentProgress.Root;
}
}
}
public float SelfProgress
{
get => _selfProgress; set => _selfProgress = value;
}
public float TotalProgress
{
get
{
return (_childProgress == null) ?
SelfProgress :
SelfProgress + _childProgress.TotalProgress * ChildProgressWeight;
}
}
public float ChildProgressWeight
{
get => _childProgressWeight;
set => _childProgressWeight = value;
}
private ImportProgress()
{
}
public ImportProgress(string tag, string detail, float childProgressWeight)
{
_tag = tag;
_detail = detail;
_childProgressWeight = childProgressWeight;
}
public void SetParent(ImportProgress parent)
{
DoAttachParent(parent);
}
public void Done()
{
if (_parentProgress != null)
{
_parentProgress.SelfProgress += _parentProgress.ChildProgressWeight;
DoDetouchParent();
}
}
private void DoAttachParent(ImportProgress newParent)
{
DoDetouchParent();
if (newParent != null)
{
_parentProgress = newParent;
_parentProgress._childProgress = this;
}
}
private void DoDetouchParent()
{
if (_parentProgress != null)
{
_parentProgress._childProgress = null;
_parentProgress = null;
}
}
public string ToDebugInfo(string progressFormat = "P3")
{
string info = $"[{Tag}]{Detail} ... ({TotalProgress.ToString(progressFormat)})\n";
if (_childProgress != null)
{
info += _childProgress.ToDebugInfo(progressFormat);
}
return info;
}
}
}