287 lines
11 KiB
C#
287 lines
11 KiB
C#
using Simulator.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UVC.UI.Window.PropertyWindow;
|
|
|
|
public class NodeProperty : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private PropertyWindow propertyWindow;
|
|
|
|
private void Awake()
|
|
{
|
|
propertyWindow.PropertyValueChanged += OnPropertyValueChanged;
|
|
}
|
|
|
|
public void SetPropertyWindow(ConveyorNode data)
|
|
{
|
|
if (PlayerPropertyDataBase.isPlaying)
|
|
{
|
|
return;
|
|
}
|
|
Debug.Log(data);
|
|
InitNodeProperty(data);
|
|
}
|
|
|
|
void SaveChange(object source, object value, string name)
|
|
{
|
|
var path = PathIndexer.GetNodePath(source);
|
|
Patch updateData = new Patch();
|
|
updateData.value = value;
|
|
UpdateValueStack.AddPatch($"{path}.{name}", value);
|
|
}
|
|
|
|
public void InitNodeProperty(ConveyorNode node)
|
|
{
|
|
List<IPropertyEntry> entries = new List<IPropertyEntry>
|
|
{
|
|
new StringProperty("name", "이름", node.name)
|
|
{
|
|
IsReadOnly=true
|
|
},
|
|
new StringProperty("label", "라벨", node.label)
|
|
{
|
|
IsReadOnly=false
|
|
}.Bind(
|
|
setter: v => {node.label = v;SaveChange(node,v,"label"); }
|
|
),
|
|
new ListProperty("type","타입",new List<string> { "start","junction","endpoint"},node.node_type)
|
|
{
|
|
IsReadOnly=true
|
|
}.Bind(
|
|
setter: v => {node.node_type=v; SaveChange(node,v,"node_type"); }
|
|
),
|
|
CreateInputDetailGroup(node),
|
|
CreateOutputDetailGroup(node),
|
|
new IntProperty("capacity", "용량", node.capacity)
|
|
{
|
|
IsReadOnly=false
|
|
}.Bind(
|
|
setter: v => {node.capacity = v;SaveChange(node,v,"capacity"); }
|
|
),
|
|
new EnumProperty("display_mode_ProcessingTimePolicy", "보관 비용 정책",node.processing_time_policy.policy).Bind(
|
|
setter: v=>{node.processing_time_policy=PolicyFactory.Create(v.ToString());SaveChange(node,PolicyFactory.Create(v.ToString()),"processing_time_policy");}
|
|
),
|
|
CreateProcessingTimePolicy_Constant(node),
|
|
CreateProcessingTimePolicy_Normal(node),
|
|
CreateProcessingTimePolicy_Uniform(node),
|
|
CreateProcessingTimePolicy_Exponential(node),
|
|
CreateProcessingTimePolicy_Triangular(node)
|
|
};
|
|
propertyWindow.LoadMixedProperties(entries);
|
|
|
|
HandleDisplayModeChanged_ProcessingTimePolicy(node.processing_time_policy.policy.ToString());
|
|
HandleDisplayModeChanged_InputOutput(node.node_type);
|
|
}
|
|
|
|
private void OnPropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
|
|
{
|
|
if (e.PropertyId == "display_mode_ProcessingTimePolicy")
|
|
{
|
|
string selectedMode = e.NewValue.ToString();
|
|
HandleDisplayModeChanged_ProcessingTimePolicy(selectedMode);
|
|
}
|
|
}
|
|
|
|
private PropertyGroup CreateInputDetailGroup(ConveyorNode node)
|
|
{
|
|
var group = new PropertyGroup("inputs", "투입 대상 컴포넌트", isExpanded: true);
|
|
if (node.inputs == null||node.inputs.Count == 0)
|
|
{
|
|
group.AddItem(new StringProperty($"inputs.no_locs", "", "연결된 항목이 없습니다.")
|
|
{
|
|
IsReadOnly = true
|
|
});
|
|
return group;
|
|
}
|
|
|
|
foreach (var input in node.inputs)
|
|
{
|
|
string inputId = $"input.count.{input.target}";
|
|
|
|
var countProp = new IntProperty(inputId, input.target, input.required_items)
|
|
.Bind(setter: v =>
|
|
{
|
|
input.required_items = v; SaveChange(input, input.required_items, "required_items");
|
|
});
|
|
|
|
group.AddItem(countProp);
|
|
}
|
|
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateOutputDetailGroup(ConveyorNode node)
|
|
{
|
|
var group = new PropertyGroup("outputs", "출하 대상 컴포넌트", isExpanded: true);
|
|
if (node.outputs == null||node.outputs.Count == 0)
|
|
{
|
|
group.AddItem(new StringProperty($"outputs.no_locs", "", "연결된 항목이 없습니다.")
|
|
{
|
|
IsReadOnly = true
|
|
});
|
|
return group;
|
|
}
|
|
|
|
foreach (var output in node.outputs)
|
|
{
|
|
string outputId = $"output.count.{output.target}";
|
|
|
|
var countProp = new IntProperty(outputId, output.target, output.required_items)
|
|
.Bind(setter: v =>
|
|
{
|
|
output.required_items = v; SaveChange(output, output.required_items, "required_items");
|
|
});
|
|
|
|
group.AddItem(countProp);
|
|
}
|
|
|
|
return group;
|
|
}
|
|
|
|
private void HandleDisplayModeChanged_InputOutput(string mode)
|
|
{
|
|
// 모든 조건부 그룹 숨김
|
|
propertyWindow.SetGroupVisibility("inputs", false);
|
|
propertyWindow.SetGroupVisibility("outputs", false);
|
|
// 선택된 모드에 따라 해당 그룹만 표시
|
|
switch (mode)
|
|
{
|
|
case "start":
|
|
propertyWindow.SetGroupVisibility("inputs", true);
|
|
break;
|
|
case "endpoint":
|
|
propertyWindow.SetGroupVisibility("outputs", true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#region 처리 시간 정책
|
|
private PropertyGroup CreateProcessingTimePolicy_Constant(ConveyorNode node)
|
|
{
|
|
var group = new PropertyGroup("ProcessingTimePolicy_Constant", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("ProcessingTimePolicy_Constant_Value", "상수 값", (node.processing_time_policy as Policy_Constant) ?.value ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Constant).value = v;SaveChange(node,v,"processing_time_policy.value"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateProcessingTimePolicy_Normal(ConveyorNode node)
|
|
{
|
|
var group = new PropertyGroup("ProcessingTimePolicy_Normal", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("ProcessingTimePolicy_Normal_Mean", "정규 분포 표준치", (node.processing_time_policy as Policy_Normal) ?.mean ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Normal).mean = v;SaveChange(node,v,"processing_time_policy.mean"); }
|
|
),
|
|
new FloatProperty("ProcessingTimePolicy_Normal_Gap", "정규 분포 표준 편차", (node.processing_time_policy as Policy_Normal) ?.stddev ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Normal).stddev = v;SaveChange(node,v,"processing_time_policy.stddev"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateProcessingTimePolicy_Uniform(ConveyorNode node)
|
|
{
|
|
var group = new PropertyGroup("ProcessingTimePolicy_Uniform", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("ProcessingTimePolicy_Uniform_Min", "균등 분포 최소값", (node.processing_time_policy as Policy_Uniform) ?.min_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Uniform).min_val = v;SaveChange(node,v,"processing_time_policy.min_val"); }
|
|
),
|
|
new FloatProperty("ProcessingTimePolicy_Uniform_Max", "균등 분포 최대값", (node.processing_time_policy as Policy_Uniform) ?.max_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Uniform).max_val = v;SaveChange(node,v,"processing_time_policy.max_val"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateProcessingTimePolicy_Exponential(ConveyorNode node)
|
|
{
|
|
var group = new PropertyGroup("ProcessingTimePolicy_Exponential", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("ProcessingTimePolicy_Exponential_Mean", "지수 분포 평균치", (node.processing_time_policy as Policy_Exponential) ?.mean ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Exponential).mean = v;SaveChange(node,v,"processing_time_policy.mean"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateProcessingTimePolicy_Triangular(ConveyorNode node)
|
|
{
|
|
var group = new PropertyGroup("ProcessingTimePolicy_Triangular", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("ProcessingTimePolicy_Triangular_Min", "지수 분포 최소값", (node.processing_time_policy as Policy_Triangular) ?.min_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Triangular).min_val = v;SaveChange(node,v,"processing_time_policy.min_val"); }
|
|
),
|
|
new FloatProperty("ProcessingTimePolicy_Triangular_Mean", "지수 분포 최빈값", (node.processing_time_policy as Policy_Triangular) ?.mode ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Triangular).mode = v;SaveChange(node,v,"processing_time_policy.mode"); }
|
|
),
|
|
new FloatProperty("ProcessingTimePolicy_Triangular_Max", "지수 분포 최대값", (node.processing_time_policy as Policy_Triangular) ?.max_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(node.processing_time_policy as Policy_Triangular).max_val = v;SaveChange(node,v,"processing_time_policy.max_val"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private void HandleDisplayModeChanged_ProcessingTimePolicy(string mode)
|
|
{
|
|
// 모든 조건부 그룹 숨김
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Constant", false);
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Normal", false);
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Uniform", false);
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Exponential", false);
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Triangular", false);
|
|
// 선택된 모드에 따라 해당 그룹만 표시
|
|
switch (mode)
|
|
{
|
|
case "Constant":
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Constant", true);
|
|
break;
|
|
case "Normal":
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Normal", true);
|
|
break;
|
|
case "Uniform":
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Uniform", true);
|
|
break;
|
|
case "Exponential":
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Exponential", true);
|
|
break;
|
|
case "Triangular":
|
|
propertyWindow.SetGroupVisibility("ProcessingTimePolicy_Triangular", true);
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (propertyWindow != null)
|
|
propertyWindow.PropertyValueChanged -= OnPropertyValueChanged;
|
|
}
|
|
}
|