refactor(Facility): 使用继承让所有机关都拥有了独自的 可交互 可编辑 可连接设定。大面积重构

This commit is contained in:
2025-10-22 17:34:58 +08:00
parent acd8282ff0
commit 5198a80318
61 changed files with 1516 additions and 889 deletions

View File

@@ -13,6 +13,7 @@ namespace UI
public class PlayerEditViewer : UIBase
{
[SerializeField] private GameObject componentEditViewerPrefab;
[SerializeField] private GameObject notEditableComponentEditViewer;
[SerializeField] private GameObject noEditableTargetPanel;
[SerializeField] private float panelRadius = 100f;
public List<EditableComponentViewer> componentViewers = new List<EditableComponentViewer>();
@@ -30,18 +31,16 @@ namespace UI
public void OnBeginEdit(GameObject target)
{
this.gameObject.SetActive(true);
if (target != null)
{
ClearComponentUI();
GenerateComponentUI(EditableManager.GetEditableComponents(target));
}
else
if (target == null)
{
if (noEditableTargetPanel != null)
{
noEditableTargetPanel.SetActive(true);
}
}
ClearComponentUI();
GenerateComponentUI(EditableManager.GetEditableComponents(target));
}
public void OnEndEdit(GameObject target)
@@ -63,7 +62,7 @@ namespace UI
this.editController.OnEndEditTarget += OnEndEdit;
//Debug.Log("PlayerEditViewer obtained PlayerEditController.");
}
private void ClearComponentUI()
{
foreach (var viewer in componentViewers)
@@ -99,13 +98,24 @@ namespace UI
float angleDeg = angleStep * i;
float angleRad = Mathf.Deg2Rad * angleDeg;
Vector2 localPos = new Vector2(Mathf.Cos(angleRad), Mathf.Sin(angleRad)) * radius;
IEditableComponent component = components[i];
var go = Instantiate(componentEditViewerPrefab, transform);
GameObject go;
if (component.IsEnableEdit)
{
go = Instantiate(componentEditViewerPrefab, transform);
}
else
{
go = Instantiate(notEditableComponentEditViewer, transform);
}
go.name = $"{componentEditViewerPrefab.name}_{i}";
var viewer = go.GetComponent<EditableComponentViewer>();
if (viewer != null)
{
viewer.SetComponent(components[i]); // 注入此UI需要的组件数据
viewer.SetComponent(component); // 注入此UI需要的组件数据
componentViewers.Add(viewer);
}