feat(): 实现EditComponent的UI基础,引入TextMeshPro,添加了在Inside状态下不能互动物体的逻辑控制
This commit is contained in:
@@ -1,19 +1,39 @@
|
||||
using Core;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Script.Gameplay.Facility;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class EditableComponentViewer : MonoBehaviour
|
||||
{
|
||||
public Component component;
|
||||
public bool IsOpen;
|
||||
|
||||
public void SetComponent()
|
||||
private IEditableComponent _component;
|
||||
[SerializeField] private TMP_Text componentName;
|
||||
[SerializeField] private TMP_Text componentState;
|
||||
[SerializeField] private Button closeButton;
|
||||
public void SetComponent(IEditableComponent component)
|
||||
{
|
||||
_component = component;
|
||||
if (component != null)
|
||||
{
|
||||
IsOpen = !IsOpen;
|
||||
component.gameObject.SetActive(IsOpen);
|
||||
closeButton.onClick.AddListener(OnClickButton);
|
||||
RefreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClickButton()
|
||||
{
|
||||
_component.IsActive = !_component.IsActive;
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
private void RefreshUI()
|
||||
{
|
||||
if (_component != null)
|
||||
{
|
||||
componentName.text = _component.ComponentName;
|
||||
componentState.text = _component.IsActive ? "Active" : "Inactive";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -146,6 +146,7 @@ namespace UI
|
||||
var viewer = go.GetComponent<EditableComponentViewer>();
|
||||
if (viewer != null)
|
||||
{
|
||||
viewer.SetComponent(components[i]); // 注入此UI需要的组件数据
|
||||
componentViewers.Add(viewer);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user