(client) chore:Clean code
This commit is contained in:
@ -3,7 +3,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class BarUI:MonoBehaviour
|
||||
public class BarUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image image;
|
||||
|
||||
|
@ -64,7 +64,7 @@ namespace UI
|
||||
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
|
||||
button.Label = buttonTextSelector(def);
|
||||
// 确保 lambda 捕获的是循环当前迭代的 def 变量,而不是循环变量本身
|
||||
var currentDef = def;
|
||||
var currentDef = def;
|
||||
button.AddListener(() => buttonAction(currentDef));
|
||||
}
|
||||
}
|
||||
@ -78,8 +78,8 @@ namespace UI
|
||||
"事件菜单",
|
||||
"未定义任何事件",
|
||||
// 假设 EventDef 也有 label 字段作为按钮文本
|
||||
def => def.label,
|
||||
eventDef =>
|
||||
def => def.label,
|
||||
eventDef =>
|
||||
{
|
||||
// TODO: 在这里实现事件触发逻辑
|
||||
Debug.Log($"触发事件: {eventDef.label}");
|
||||
@ -165,7 +165,7 @@ namespace UI
|
||||
{
|
||||
entityPlacementUI.currentAction = () =>
|
||||
{
|
||||
Managers.EntityManage.Instance.GenerateEntity(Program.Instance.FocusedDimensionId,entityDef, Utils.MousePosition.GetWorldPosition());
|
||||
Managers.EntityManage.Instance.GenerateEntity(Program.Instance.FocusedDimensionId, entityDef, Utils.MousePosition.GetWorldPosition());
|
||||
};
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{entityDef.label}\n描述:{entityDef.description}";
|
||||
entityPlacementUI.snapEnabled = false;
|
||||
@ -175,7 +175,7 @@ namespace UI
|
||||
{
|
||||
entityPlacementUI.currentAction = () =>
|
||||
{
|
||||
Managers.EntityManage.Instance.GenerateMonsterEntity(Program.Instance.FocusedDimensionId,monsterDef, Utils.MousePosition.GetWorldPosition());
|
||||
Managers.EntityManage.Instance.GenerateMonsterEntity(Program.Instance.FocusedDimensionId, monsterDef, Utils.MousePosition.GetWorldPosition());
|
||||
};
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{monsterDef.label}\n描述:{monsterDef.description}";
|
||||
entityPlacementUI.snapEnabled = false;
|
||||
@ -185,7 +185,7 @@ namespace UI
|
||||
{
|
||||
entityPlacementUI.currentAction = () =>
|
||||
{
|
||||
Managers.EntityManage.Instance.GenerateBuildingEntity(Program.Instance.FocusedDimensionId,def, Utils.MousePosition.GetSnappedWorldPosition());
|
||||
Managers.EntityManage.Instance.GenerateBuildingEntity(Program.Instance.FocusedDimensionId, def, Utils.MousePosition.GetSnappedWorldPosition());
|
||||
};
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{def.label}\n描述:{def.description}";
|
||||
entityPlacementUI.snapEnabled = true;
|
||||
@ -195,7 +195,7 @@ namespace UI
|
||||
{
|
||||
entityPlacementUI.currentAction = () =>
|
||||
{
|
||||
Managers.EntityManage.Instance.GeneratePickupEntity(Program.Instance.FocusedDimensionId,itemDef, Utils.MousePosition.GetWorldPosition());
|
||||
Managers.EntityManage.Instance.GeneratePickupEntity(Program.Instance.FocusedDimensionId, itemDef, Utils.MousePosition.GetWorldPosition());
|
||||
};
|
||||
entityPlacementUI.Prompt = $"当前生成器:\n名称:{itemDef.label}\n描述:{itemDef.description}";
|
||||
entityPlacementUI.snapEnabled = false;
|
||||
|
@ -1,16 +1,15 @@
|
||||
using Base;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
|
||||
|
||||
public delegate void NonReturnCallback();
|
||||
public class EntityPlacementUI:UIBase,ITickUI
|
||||
public class EntityPlacementUI : UIBase, ITickUI
|
||||
{
|
||||
public TMP_Text promptText;
|
||||
|
||||
|
||||
public NonReturnCallback currentAction;
|
||||
|
||||
public GameObject focusBox;
|
||||
@ -29,7 +28,7 @@ namespace UI
|
||||
{
|
||||
Base.UIInputControl.Instance.Hide(this);
|
||||
}
|
||||
if (currentAction!=null&&Input.GetMouseButtonDown(0))
|
||||
if (currentAction != null && Input.GetMouseButtonDown(0))
|
||||
{
|
||||
currentAction();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Base;
|
||||
using Entity;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
// 确保 Character 类在此命名空间下
|
||||
|
||||
@ -103,7 +103,7 @@ namespace UI
|
||||
|
||||
// 立即更新UI以反映新的关注实体(或没有关注实体)的状态。
|
||||
UpdateUI();
|
||||
|
||||
|
||||
// 在更新UI后,确保UI的选中状态与角色当前选中字段同步
|
||||
// 只有当有焦点角色且库存不为空时才更新选中状态
|
||||
if (focusedEntity != null && focusedEntity.Inventory != null && focusedEntity.Inventory.Capacity > 0)
|
||||
@ -187,7 +187,7 @@ namespace UI
|
||||
}
|
||||
}
|
||||
uiParent.SetActive(true);
|
||||
|
||||
|
||||
// 首次更新UI时,或者当Inventory改变时,需要确保 CurrentSelected 的UI状态是正确的
|
||||
// 但如果 UpdateFocusedEntity 已经处理了,这里可以省略,或者确保只在必要时调用
|
||||
// 考虑到 UpdateUI 也会被 Inventory.OnInventoryChanged 调用,这里再次确保同步是合理的。
|
||||
|
@ -1,10 +1,9 @@
|
||||
using Base;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class EscUI:UIBase
|
||||
public class EscUI : UIBase
|
||||
{
|
||||
public void ContinueButton()
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using Base;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@ -7,20 +7,20 @@ using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class ItemUI:MonoBehaviour,IPointerEnterHandler,IPointerExitHandler,IPointerClickHandler,ITick
|
||||
public class ItemUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, ITick
|
||||
{
|
||||
[SerializeField] private Image textureUI;
|
||||
[SerializeField] private TMP_Text countUI;
|
||||
[SerializeField] private TMP_Text nameUI;
|
||||
[SerializeField] private GameObject selectedOutline;
|
||||
|
||||
|
||||
private Entity.InventorySlot _item;
|
||||
private float timer = 0;
|
||||
private float switchTime = 0;
|
||||
private int texturePtr = 0;
|
||||
|
||||
|
||||
public event Action OnPlayerSelect;
|
||||
|
||||
|
||||
public bool Select
|
||||
{
|
||||
get => selectedOutline.activeSelf;
|
||||
@ -29,7 +29,7 @@ namespace UI
|
||||
|
||||
public int SlotIndex { get; private set; } = -1;
|
||||
|
||||
public void Init(Entity.InventorySlot item,int index)
|
||||
public void Init(Entity.InventorySlot item, int index)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
@ -75,17 +75,17 @@ namespace UI
|
||||
{
|
||||
if (switchTime > 0)
|
||||
{
|
||||
timer+=Time.deltaTime;
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= switchTime)
|
||||
{
|
||||
timer-=switchTime;
|
||||
timer -= switchTime;
|
||||
texturePtr++;
|
||||
texturePtr%=_item.Item.Icon.Count;
|
||||
textureUI.sprite=_item.Item.Icon[texturePtr];
|
||||
texturePtr %= _item.Item.Icon.Count;
|
||||
textureUI.sprite = _item.Item.Icon[texturePtr];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using Prefab;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Prefab;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class PlayerStateUI:MonoBehaviour,Base.ITick
|
||||
public class PlayerStateUI : MonoBehaviour, Base.ITick
|
||||
{
|
||||
[SerializeField] private BarUI focusedEntityHP;
|
||||
[SerializeField] private BarUI lastEntityHP;
|
||||
|
||||
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
@ -19,6 +17,6 @@ namespace UI
|
||||
(float)focusedEntity.attributes.health / focusedEntity.entityDef.attributes.health;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
using System.Globalization;
|
||||
using Base;
|
||||
using System.Globalization;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
Reference in New Issue
Block a user