125 lines
5.1 KiB
C#
125 lines
5.1 KiB
C#
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Samkwang
|
|
{
|
|
public class UI_WorkProgressContent : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI planqty;
|
|
public TextMeshProUGUI percentplanqty;
|
|
public Slider Slider_planqty;
|
|
|
|
public TextMeshProUGUI workqty;
|
|
public TextMeshProUGUI percentworkqty;
|
|
public Slider Slider_workqty;
|
|
|
|
public TextMeshProUGUI goodqty;
|
|
public TextMeshProUGUI percentgoodqty;
|
|
public Slider Slider_goodqty;
|
|
|
|
public TextMeshProUGUI badqty;
|
|
public TextMeshProUGUI percentbadqty;
|
|
public Slider Slider_badqty;
|
|
|
|
public TextMeshProUGUI badrate;
|
|
public TextMeshProUGUI percentbadrate;
|
|
public Slider Slider_badrate;
|
|
|
|
public TextMeshProUGUI progressrate;
|
|
public TextMeshProUGUI percentprogressrate;
|
|
public Slider Slider_progressrate;
|
|
|
|
public void Init()
|
|
{
|
|
var textDict = transform.GetChildComponentsByName<TextMeshProUGUI>();
|
|
var sliderDict = transform.GetChildComponentsByName<Slider>();
|
|
|
|
planqty = textDict.GetOrNull(nameof(planqty));
|
|
percentplanqty = textDict.GetOrNull(nameof(percentplanqty));
|
|
Slider_planqty = sliderDict.GetOrNull(nameof(Slider_planqty));
|
|
|
|
workqty = textDict.GetOrNull(nameof(workqty));
|
|
percentworkqty = textDict.GetOrNull(nameof(percentworkqty));
|
|
Slider_workqty = sliderDict.GetOrNull(nameof(Slider_workqty));
|
|
|
|
goodqty = textDict.GetOrNull(nameof(goodqty));
|
|
percentgoodqty = textDict.GetOrNull(nameof(percentgoodqty));
|
|
Slider_goodqty = sliderDict.GetOrNull(nameof(Slider_goodqty));
|
|
|
|
badqty = textDict.GetOrNull(nameof(badqty));
|
|
percentbadqty = textDict.GetOrNull(nameof(percentbadqty));
|
|
Slider_badqty = sliderDict.GetOrNull(nameof(Slider_badqty));
|
|
|
|
badrate = textDict.GetOrNull(nameof(badrate));
|
|
percentbadrate = textDict.GetOrNull(nameof(percentbadrate));
|
|
Slider_badrate = sliderDict.GetOrNull(nameof(Slider_badrate));
|
|
|
|
progressrate = textDict.GetOrNull(nameof(progressrate));
|
|
percentprogressrate = textDict.GetOrNull(nameof(percentprogressrate));
|
|
Slider_progressrate = sliderDict.GetOrNull(nameof(Slider_progressrate));
|
|
}
|
|
public void SetWorkProgressContent(BranchInfo branchInfo)
|
|
{
|
|
SetWorkProgressItem(planqty, percentplanqty, Slider_planqty, branchInfo.planqty, branchInfo.planqty);
|
|
SetWorkProgressItem(workqty, percentworkqty, Slider_workqty, branchInfo.planqty, branchInfo.workqty);
|
|
SetWorkProgressItem(goodqty, percentgoodqty, Slider_goodqty, branchInfo.planqty, branchInfo.goodqty);
|
|
SetWorkProgressItem(badqty, percentbadqty, Slider_badqty, branchInfo.planqty, branchInfo.badqty);
|
|
SetWorkProgressrateItem(badrate, percentbadrate, Slider_badrate, branchInfo.badrate);
|
|
SetWorkProgressrateItem(progressrate, percentprogressrate, Slider_progressrate, branchInfo.progressrate);
|
|
}
|
|
public void SetWorkProgressItem(TextMeshProUGUI value, TextMeshProUGUI percent, Slider slider, string maxValue, string currentValue)
|
|
{
|
|
value.SetText(currentValue);
|
|
|
|
var maxValueData = StringConvertFloat(maxValue);
|
|
var currentValueData = StringConvertFloat(currentValue);
|
|
value.SetText(currentValueData.ToString("N0"));
|
|
percent.SetText($"{SetPercentData(maxValueData, currentValueData)}%");
|
|
|
|
slider.maxValue = 1f;
|
|
slider.value = GetSliderData(maxValueData, currentValueData);
|
|
}
|
|
public void SetWorkProgressrateItem(TextMeshProUGUI value, TextMeshProUGUI percent, Slider slider, string currentValue)
|
|
{
|
|
value.SetText(currentValue);
|
|
|
|
var currentValueData = StringConvertFloat(currentValue);
|
|
percent.SetText($"{currentValue}%");
|
|
|
|
slider.maxValue = 1f;
|
|
slider.value = GetRateSliderData(currentValueData);
|
|
}
|
|
private string SetPercentData(float maxValue, float currentValue)
|
|
{
|
|
if (maxValue == 0f)
|
|
return "0.0";
|
|
|
|
var percentData = (currentValue / maxValue) * 100f;
|
|
var result = percentData >= 100 ? percentData.ToString("F0") : percentData > 0 && percentData < 0.02 ? "0.01" : percentData.ToString("F2");
|
|
|
|
return result;
|
|
}
|
|
private float GetSliderData(float maxValue, float currentValue)
|
|
{
|
|
var percentData = currentValue / maxValue;
|
|
|
|
var percent = percentData > 0 && percentData <= 0.01f ? 0.01f : percentData;
|
|
return percent;
|
|
}
|
|
private float GetRateSliderData(float currentValue)
|
|
{
|
|
var percentData = currentValue * 0.01f;
|
|
var percent = percentData > 0 && percentData <= 0.01f ? 0.01f : percentData;
|
|
return percent;
|
|
}
|
|
private float StringConvertFloat(string value)
|
|
{
|
|
float.TryParse(value, out var floatValue);
|
|
return floatValue;
|
|
}
|
|
}
|
|
}
|
|
|