refactor(Facility): 使用继承让所有机关都拥有了独自的 可交互 可编辑 可连接设定。大面积重构
This commit is contained in:
@@ -24,7 +24,7 @@ namespace UI
|
||||
|
||||
private void OnClickButton()
|
||||
{
|
||||
_component.IsComponentActive = !_component.IsComponentActive;
|
||||
_component.IsOpenInEditor = !_component.IsOpenInEditor;
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace UI
|
||||
if (_component != null)
|
||||
{
|
||||
componentName.text = _component.ComponentName;
|
||||
componentState.text = _component.IsComponentActive ? "Active" : "Inactive";
|
||||
componentState.text = _component.IsOpenInEditor ? "Active" : "Inactive";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using Core;
|
||||
using Script.Gameplay.Player;
|
||||
using Script.Gameplay.Connect;
|
||||
using Script.Gameplay.Interface;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user