249 lines
9.9 KiB
C#
249 lines
9.9 KiB
C#
using Simulator.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UVC.UI.Window.PropertyWindow;
|
|
|
|
public class QueueProperty : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private PropertyWindow propertyWindow;
|
|
private void Awake()
|
|
{
|
|
propertyWindow.PropertyValueChanged += OnPropertyValueChanged;
|
|
}
|
|
public void SetPropertyWindow(ComponentType type, ComponentDataBase data)
|
|
{
|
|
if (PlayerPropertyDataBase.isPlaying)
|
|
{
|
|
return;
|
|
}
|
|
InitNodeProperty(data as QueueDataClass);
|
|
}
|
|
|
|
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(QueueDataClass queue)
|
|
{
|
|
List<IPropertyEntry> entries = new List<IPropertyEntry>
|
|
{
|
|
new StringProperty("name", "이름", queue.name)
|
|
{
|
|
IsReadOnly=true
|
|
},
|
|
new StringProperty("label", "라벨", queue.label)
|
|
{
|
|
IsReadOnly=false
|
|
}.Bind(
|
|
setter: v => {queue.label = v;SaveChange(queue,v,"label"); }
|
|
),
|
|
CreatePositionGroup(queue),
|
|
new BoolProperty("is_unlimited","수용 용량 무제한", queue.is_unlimited)
|
|
{
|
|
IsReadOnly=false
|
|
},
|
|
new IntProperty("capacity","최대 수용 개수", queue.capacity)
|
|
{
|
|
IsReadOnly=false
|
|
}.Bind(
|
|
setter: v => { queue.capacity = v; SaveChange(queue, v, "capacity"); }
|
|
),
|
|
new ListProperty("queue_type","대기열 처리 방식",new List<string>(){ "fifo", "lifo", "priority" }, queue.queue_type)
|
|
{
|
|
IsReadOnly=false,
|
|
}.Bind(
|
|
setter: v => { queue.queue_type = v; SaveChange(queue, v, "queue_type"); }
|
|
),
|
|
new EnumProperty("display_mode_CostPolicy", "대기 비용 처리 정책",queue.cost_policy.policy)
|
|
{
|
|
IsReadOnly=false
|
|
}.Bind(
|
|
setter: v=>{queue.cost_policy=PolicyFactory.Create(v.ToString());SaveChange(queue,PolicyFactory.Create(v.ToString()),"cost_policy");}
|
|
),
|
|
CreateCostPolicy_Constant(queue),
|
|
CreateCostPolicy_Normal(queue),
|
|
CreateCostPolicy_Uniform(queue),
|
|
CreateCostPolicy_Exponential(queue),
|
|
CreateCostTimePolicy_Triangular(queue),
|
|
};
|
|
propertyWindow.LoadMixedProperties(entries);
|
|
|
|
HandleDisplayModeChanged_CostPolicy(queue.cost_policy.policy.ToString());
|
|
propertyWindow.SetPropertyEnabled("capacity", !queue.is_unlimited);
|
|
}
|
|
|
|
private void OnPropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
|
|
{
|
|
Debug.Log($"[PropertyChanged] Id:{e.PropertyId}, Type:{e.PropertyType}, Value:{e.NewValue}");
|
|
|
|
// 동적 그룹 표시/비표시 테스트
|
|
if (e.PropertyId == "display_mode_CostPolicy")
|
|
{
|
|
string selectedMode = e.NewValue.ToString();
|
|
HandleDisplayModeChanged_CostPolicy(selectedMode);
|
|
}
|
|
if (e.PropertyId == "is_unlimited")
|
|
{
|
|
bool flag = Convert.ToBoolean(e.NewValue);
|
|
propertyWindow.SetPropertyEnabled("capacity", !flag);
|
|
}
|
|
}
|
|
|
|
private PropertyGroup CreatePositionGroup(QueueDataClass queue)
|
|
{
|
|
var group = new PropertyGroup("queue_position", "위치 및 회전", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("x_position", "X 좌표(m)", queue.physical.position.x)
|
|
{
|
|
}.Bind(
|
|
setter: v => {queue.physical.position.x = v;SaveChange(queue,v,"physical.position.x"); }
|
|
),
|
|
new FloatProperty("y_position", "y 좌표(m)", queue.physical.position.y)
|
|
{
|
|
}.Bind(
|
|
setter: v => {queue.physical.position.y = v;SaveChange(queue,v,"physical.position.y"); }
|
|
),
|
|
new FloatProperty("orientation", "회전(°)", queue.physical.orientation)
|
|
{
|
|
}.Bind(
|
|
setter: v => {queue.physical.orientation = v;SaveChange(queue,v,"physical.orientation");propertyWindow.ApplyExternalValue("orientation",RotationSnap.SnapOrientation(v),false); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
#region 입고 시간 정책
|
|
private PropertyGroup CreateCostPolicy_Constant(QueueDataClass queue)
|
|
{
|
|
var group = new PropertyGroup("CostPolicy_Constant", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("CostPolicy_Constant_Value", "상수 값", (queue.cost_policy as Policy_Constant)?.value??0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Constant).value = v;SaveChange(queue,v,"cost_policy.value"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateCostPolicy_Normal(QueueDataClass queue)
|
|
{
|
|
var group = new PropertyGroup("CostPolicy_Normal", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("CostPolicy_Normal_Mean", "정규 분포 표준치", (queue.cost_policy as Policy_Normal) ?.mean ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Normal).mean = v;SaveChange(queue,v,"cost_policy.mean"); }
|
|
),
|
|
new FloatProperty("CostPolicy_Normal_Gap", "정규 분포 표준 편차", (queue.cost_policy as Policy_Normal) ?.stddev ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Normal).stddev = v;SaveChange(queue,v,"cost_policy.stddev"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateCostPolicy_Uniform(QueueDataClass queue)
|
|
{
|
|
var group = new PropertyGroup("CostPolicy_Uniform", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("CostPolicy_Uniform_Min", "균등 분포 최소값", (queue.cost_policy as Policy_Uniform) ?.min_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Uniform).min_val = v;SaveChange(queue,v,"cost_policy.min_val"); }
|
|
),
|
|
new FloatProperty("CostPolicy_Uniform_Max", "균등 분포 최대값", (queue.cost_policy as Policy_Uniform) ?.max_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Uniform).max_val = v;SaveChange(queue,v,"cost_policy.max_val"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateCostPolicy_Exponential(QueueDataClass queue)
|
|
{
|
|
var group = new PropertyGroup("CostPolicy_Exponential", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("CostPolicy_Exponential_Mean", "지수 분포 평균치", (queue.cost_policy as Policy_Exponential) ?.mean ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Exponential).mean = v;SaveChange(queue,v,"cost_policy.mean"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private PropertyGroup CreateCostTimePolicy_Triangular(QueueDataClass queue)
|
|
{
|
|
var group = new PropertyGroup("CostPolicy_Triangular", "", isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new FloatProperty("CostPolicy_Triangular_Min", "지수 분포 최소값", (queue.cost_policy as Policy_Triangular) ?.min_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Triangular).min_val = v;SaveChange(queue,v,"cost_policy.min_val"); }
|
|
),
|
|
new FloatProperty("CostPolicy_Triangular_Mean", "지수 분포 최빈값", (queue.cost_policy as Policy_Triangular) ?.mode ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Triangular).mode = v;SaveChange(queue,v,"cost_policy.mode"); }
|
|
),
|
|
new FloatProperty("CostPolicy_Triangular_Max", "지수 분포 최대값", (queue.cost_policy as Policy_Triangular) ?.max_val ?? 0f)
|
|
{
|
|
}.Bind(
|
|
setter: v => {(queue.cost_policy as Policy_Triangular).max_val = v;SaveChange(queue,v,"cost_policy.max_val"); }
|
|
),
|
|
});
|
|
return group;
|
|
}
|
|
private void HandleDisplayModeChanged_CostPolicy(string mode)
|
|
{
|
|
// 모든 조건부 그룹 숨김
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Constant", false);
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Normal", false);
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Uniform", false);
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Exponential", false);
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Triangular", false);
|
|
|
|
// 선택된 모드에 따라 해당 그룹만 표시
|
|
switch (mode)
|
|
{
|
|
case "Constant":
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Constant", true);
|
|
break;
|
|
case "Normal":
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Normal", true);
|
|
break;
|
|
case "Uniform":
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Uniform", true);
|
|
break;
|
|
case "Exponential":
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Exponential", true);
|
|
break;
|
|
case "Triangular":
|
|
propertyWindow.SetGroupVisibility("CostPolicy_Triangular", true);
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (propertyWindow != null)
|
|
propertyWindow.PropertyValueChanged -= OnPropertyValueChanged;
|
|
}
|
|
}
|