107 lines
3.7 KiB
C#
107 lines
3.7 KiB
C#
using System;
|
|
using UnityEditor;
|
|
using UnityEditor.UIElements;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using BaseGames.Player;
|
|
|
|
namespace BaseGames.Editor.Modules
|
|
{
|
|
/// <summary>
|
|
/// DataHub 武器模块 —— 管理 WeaponSO 资产。
|
|
/// </summary>
|
|
public class WeaponModule : IDataModule, IDataModuleOrdered
|
|
{
|
|
private const string Folder = "Assets/_Game/Data/Weapons";
|
|
private const string Prefix = "WPN_";
|
|
|
|
public string ModuleId => "weapon";
|
|
public string DisplayName => "武器";
|
|
public string IconName => null;
|
|
public int DisplayOrder => 10;
|
|
|
|
private SoListPane<WeaponSO> _listPane;
|
|
private DetailHeader _header;
|
|
private VisualElement _detailRoot;
|
|
private WeaponSO _selected;
|
|
|
|
public void Initialize()
|
|
{
|
|
_listPane = new SoListPane<WeaponSO>(
|
|
Folder, Prefix,
|
|
w => w.weaponType.ToString());
|
|
}
|
|
|
|
public void BuildListPane(VisualElement container, Action<UnityEngine.Object> onSelected)
|
|
{
|
|
_listPane.SelectionChanged = sel =>
|
|
{
|
|
_selected = sel;
|
|
onSelected?.Invoke(sel);
|
|
};
|
|
container.Add(_listPane);
|
|
_listPane.Refresh();
|
|
}
|
|
|
|
public void BuildDetailPane(VisualElement container, UnityEngine.Object selected)
|
|
{
|
|
_selected = selected as WeaponSO;
|
|
|
|
// Header(重命名)
|
|
_header = new DetailHeader();
|
|
_header.SetAsset(_selected);
|
|
_header.RenameRequested += OnRenameRequested;
|
|
container.Add(_header);
|
|
|
|
if (_selected == null) return;
|
|
|
|
// Stats Card(复用 SkillModule 共享构建方法)
|
|
var statsCard = BuildStatsCard(_selected);
|
|
container.Add(statsCard);
|
|
|
|
// 操作按钮行(复用 BuildStandardActionBar,统一按钮样式)
|
|
container.Add(SkillModule.BuildStandardActionBar<WeaponSO>(
|
|
_selected, Folder, Prefix,
|
|
created => _listPane.Refresh(created),
|
|
cloned => _listPane.Refresh(cloned),
|
|
() => _listPane.Refresh(null)));
|
|
|
|
// 分隔线
|
|
container.Add(SkillModule.MakeDivider());
|
|
|
|
// Inspector
|
|
var insp = new InspectorElement(_selected); container.Add(insp);
|
|
}
|
|
|
|
public void OnActivated()
|
|
{
|
|
_listPane?.Refresh();
|
|
}
|
|
|
|
// ── 内部 ─────────────────────────────────────────────────────────────
|
|
|
|
private void OnRenameRequested(string newName)
|
|
{
|
|
if (_selected == null) return;
|
|
var (ok, err) = AssetOperations.Rename(_selected, newName);
|
|
if (!ok)
|
|
EditorUtility.DisplayDialog("重命名失败", err, "确定");
|
|
else
|
|
{
|
|
_header.SetAsset(_selected);
|
|
_listPane.Invalidate();
|
|
}
|
|
}
|
|
|
|
private static VisualElement BuildStatsCard(WeaponSO w)
|
|
{
|
|
var card = SkillModule.MakeCard();
|
|
SkillModule.AddChip(card, "类型", w.weaponType.ToString());
|
|
SkillModule.AddChip(card, "地面段数", (w.groundComboSteps?.Length ?? 0).ToString());
|
|
SkillModule.AddChip(card, "空中段数", (w.airComboSteps?.Length ?? 0).ToString());
|
|
SkillModule.AddChip(card, "ID", string.IsNullOrEmpty(w.weaponId) ? "-" : w.weaponId);
|
|
return card;
|
|
}
|
|
}
|
|
}
|