174 lines
5.7 KiB
C#
174 lines
5.7 KiB
C#
using Simulator.Data;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ProgressPopupView : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
TMP_Text titleLabel;
|
|
[SerializeField]
|
|
TMP_Text componentTypeLabel;
|
|
[SerializeField]
|
|
Button closeButton;
|
|
[SerializeField]
|
|
TMP_Text inputValueText;
|
|
[SerializeField]
|
|
TMP_Text inputTitleText;
|
|
[SerializeField]
|
|
TMP_Text outputValueText;
|
|
[SerializeField]
|
|
TMP_Text outputTitleText;
|
|
[SerializeField]
|
|
ProgressInoutList inOutListPrefab;
|
|
[SerializeField]
|
|
List<ProgressInoutList> inOutListViews = new List<ProgressInoutList>();
|
|
[SerializeField]
|
|
Transform inOutListContainer;
|
|
|
|
string boundComponentKey;
|
|
|
|
private void Awake()
|
|
{
|
|
closeButton.onClick.AddListener(()=>gameObject.SetActive(false));
|
|
ProgressDatabase.Instance.OnValueChanged += HandleValueChanged;
|
|
}
|
|
public void Show(ComponentType type,ComponentDataBase componentData)
|
|
{
|
|
if (!PlayerPropertyDataBase.isPlaying)
|
|
{
|
|
return;
|
|
}
|
|
gameObject.SetActive(true);
|
|
|
|
titleLabel.text = componentData.label;
|
|
boundComponentKey = componentData.name;
|
|
|
|
var v = ProgressDatabase.Instance.BindValue(boundComponentKey);
|
|
UpdateInputOutputValue(v.Item1, v.Item2);
|
|
switch (type)
|
|
{
|
|
case ComponentType.Source:
|
|
componentTypeLabel.text = "투입(source)";
|
|
inputTitleText.text = "생성";
|
|
outputTitleText.text = "출력";
|
|
foreach(var inout in inOutListViews)
|
|
{
|
|
Destroy(inout.gameObject);
|
|
}
|
|
inOutListViews.Clear();
|
|
var inputitem = Instantiate(inOutListPrefab, inOutListContainer);
|
|
inOutListViews.Add(inputitem);
|
|
List<string> Lists = new List<string>();
|
|
var source = componentData as SourceDataClass;
|
|
if (source == null) break;
|
|
foreach(var output in source.outputs)
|
|
{
|
|
Lists.Add(output.target);
|
|
}
|
|
inputitem.Set(false, Lists);
|
|
break;
|
|
case ComponentType.Queue:
|
|
//title_Type.text = "투입(source)";
|
|
break;
|
|
case ComponentType.Sink:
|
|
componentTypeLabel.text = "배출(sink)";
|
|
inputTitleText.text = "배출량";
|
|
outputTitleText.text = "제품 종류";
|
|
foreach (var inout in inOutListViews)
|
|
{
|
|
Destroy(inout.gameObject);
|
|
}
|
|
inOutListViews.Clear();
|
|
var outputitem = Instantiate(inOutListPrefab, inOutListContainer);
|
|
inOutListViews.Add(outputitem);
|
|
Lists = new List<string>();
|
|
var sink = componentData as SinkDataClass;
|
|
if (sink == null) break;
|
|
foreach (var input in sink.inputs)
|
|
{
|
|
Lists.Add(input.target);
|
|
}
|
|
outputitem.Set(true, Lists);
|
|
break;
|
|
case ComponentType.Processor:
|
|
componentTypeLabel.text = "작업대(workbench)";
|
|
inputTitleText.text = "입력";
|
|
outputTitleText.text = "출력";
|
|
foreach (var inout in inOutListViews)
|
|
{
|
|
Destroy(inout.gameObject);
|
|
}
|
|
inOutListViews.Clear();
|
|
inputitem = Instantiate(inOutListPrefab, inOutListContainer);
|
|
outputitem = Instantiate(inOutListPrefab, inOutListContainer);
|
|
inOutListViews.Add(inputitem);
|
|
inOutListViews.Add(outputitem);
|
|
Lists = new List<string>();
|
|
var processor = componentData as ProcessorDataClass;
|
|
if (processor == null) break;
|
|
foreach (var input in processor.inputs)
|
|
{
|
|
Lists.Add(input.prefab);
|
|
}
|
|
inputitem.Set(false, Lists);
|
|
Lists.Clear();
|
|
foreach (var output in processor.outputs)
|
|
{
|
|
Lists.Add(output.prefab);
|
|
}
|
|
outputitem.Set(true, Lists);
|
|
break;
|
|
case ComponentType.ASRS:
|
|
//title_Type.text = "투입(source)";
|
|
break;
|
|
case ComponentType.Rack:
|
|
//title_Type.text = "투입(source)";
|
|
break;
|
|
case ComponentType.RobotArm:
|
|
//title_Type.text = "투입(source)";
|
|
break;
|
|
case ComponentType.Worker:
|
|
//title_Type.text = "투입(source)";
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void HandleValueChanged(string key, (string input, string output) value)
|
|
{
|
|
if (string.IsNullOrEmpty(boundComponentKey) || key != boundComponentKey) return;
|
|
|
|
UpdateInputOutputValue(value.input, value.output);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (closeButton != null) closeButton.onClick.RemoveAllListeners();
|
|
if (ProgressDatabase.Instance != null)
|
|
{
|
|
ProgressDatabase.Instance.OnValueChanged -= HandleValueChanged;
|
|
}
|
|
}
|
|
|
|
public void UpdateInputOutputValue(string input,string output)
|
|
{
|
|
if (string.IsNullOrEmpty(input))
|
|
{
|
|
inputValueText.text = "0";
|
|
}
|
|
else
|
|
{
|
|
inputValueText.text = input;
|
|
}
|
|
if (string.IsNullOrEmpty(output))
|
|
{
|
|
outputValueText.text = "0";
|
|
}
|
|
else
|
|
{
|
|
outputValueText.text = output;
|
|
}
|
|
}
|
|
}
|