Files
XRLib/Assets/Scripts/Simulator/UI/PropertyWindow/SinkProperty.cs
2026-02-25 16:30:12 +09:00

110 lines
3.4 KiB
C#

using Simulator.Data;
using System.Collections.Generic;
using UnityEngine;
using UVC.UI.Window.PropertyWindow;
public class SinkProperty : MonoBehaviour
{
[SerializeField]
private PropertyWindow propertyWindow;
private void Awake()
{
//propertyWindow.PropertyValueChanged += OnPropertyValueChanged;
}
public void SetPropertyWindow(ComponentType type, ComponentDataBase data)
{
if (PlayerPropertyDataBase.isPlaying)
{
return;
}
switch (type)
{
case ComponentType.Sink:
InitSinkProperty(data as SinkDataClass);
break;
}
}
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 InitSinkProperty(SinkDataClass sink)
{
List<IPropertyEntry> entries = new List<IPropertyEntry>
{
new StringProperty("name", "이름", sink.name)
{
IsReadOnly=true
},
new StringProperty("label", "라벨", sink.label)
{
IsReadOnly=false
}.Bind(
setter: v => {sink.label = v;SaveChange(sink,v,"label"); }
),
CreatePositionGroup(sink),
CreateInputDetailGroup(sink)
};
propertyWindow.LoadMixedProperties(entries);
}
private PropertyGroup CreatePositionGroup(SinkDataClass sink)
{
var group = new PropertyGroup("robotArm_position", "위치 및 회전", isExpanded: true);
group.AddItems(new IPropertyItem[]
{
new FloatProperty("x_position", "X 좌표(m)", sink.physical.position.x)
{
}.Bind(
setter: v => {sink.physical.position.x = v;SaveChange(sink,v,"physical.position.x"); }
),
new FloatProperty("y_position", "y 좌표(m)", sink.physical.position.y)
{
}.Bind(
setter: v => {sink.physical.position.y = v;SaveChange(sink,v,"physical.position.y"); }
),
new FloatProperty("orientation", "회전(°)", sink.physical.orientation)
{
}.Bind(
setter: v => {sink.physical.orientation = v;SaveChange(sink,v,"physical.orientation");propertyWindow.ApplyExternalValue("orientation",RotationSnap.SnapOrientation(v),false); }
),
});
return group;
}
private PropertyGroup CreateInputDetailGroup(SinkDataClass sink)
{
var group = new PropertyGroup("inputs", "입력 연결", isExpanded: true);
if (sink.inputs == null || sink.inputs.Count == 0)
{
group.AddItem(new StringProperty($"inputs.no_locs", "", "연결된 항목이 없습니다.")
{
IsReadOnly = true
});
return group;
}
foreach (var input in sink.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;
}
}