1
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
namespace MuHuaEditor {
|
||||
/// <summary>
|
||||
/// 装备面板
|
||||
/// </summary>
|
||||
public class UIEquipmentPanel : ModuleUIPanel {
|
||||
|
||||
public WeaponConst weapon;
|
||||
public ArmorConst armor;
|
||||
public AccessoryConst accessory;
|
||||
|
||||
public Label Name => Q<Label>("Name");
|
||||
public Label Type => Q<Label>("Type");
|
||||
|
||||
public UIEquipmentPanel(VisualElement element) : base(element) {
|
||||
|
||||
}
|
||||
|
||||
public void Initial(EquipmentConst equipment) {
|
||||
element.EnableInClassList("ew-hide", equipment == null);
|
||||
if (equipment == null) { return; }
|
||||
Name.text = equipment.name;
|
||||
if (equipment is WeaponConst weapon) { InitialWeapon(weapon); }
|
||||
if (equipment is ArmorConst armor) { InitialArmor(armor); }
|
||||
if (equipment is AccessoryConst accessory) { InitialAccessory(accessory); }
|
||||
}
|
||||
|
||||
public void InitialWeapon(WeaponConst weapon) {
|
||||
Type.text = $"Lv{weapon.level} {weapon.rarity} {weapon.type} {weapon.category}";
|
||||
}
|
||||
public void InitialArmor(ArmorConst armor) {
|
||||
Type.text = $"Lv{armor.level} {armor.rarity} {armor.type}";
|
||||
}
|
||||
public void InitialAccessory(AccessoryConst accessory) {
|
||||
Type.text = $"Lv{accessory.level} {accessory.rarity} {accessory.type}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a4bc99140d169c4e8b0daf8629bfc08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: babeefadaf13a2f468d537479da309c7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
using MuHua;
|
||||
|
||||
namespace MuHuaEditor {
|
||||
/// <summary>
|
||||
/// 装备输入
|
||||
/// </summary>
|
||||
public class UIEquipmentInput : ModuleUIPanel {
|
||||
|
||||
public WeaponConst weapon;
|
||||
public EquipmentConst equipment;
|
||||
|
||||
public TextField Name => Q<TextField>("Name");
|
||||
public IntegerField Level => Q<IntegerField>("Level");
|
||||
public ObjectField Sprite => Q<ObjectField>("Sprite");
|
||||
public EnumField Rarity => Q<EnumField>("Rarity");
|
||||
public EnumField WeaponCategory => Q<EnumField>("WeaponCategory");
|
||||
|
||||
public UIEquipmentInput(VisualElement element) : base(element) {
|
||||
Name.RegisterCallback<FocusOutEvent>(evt => ModifyName());
|
||||
Level.RegisterCallback<FocusOutEvent>(evt => ModifyLevel());
|
||||
Sprite.RegisterCallback<FocusOutEvent>(evt => ModifySprite());
|
||||
Rarity.RegisterValueChangedCallback(evt => ModifyRarity((EquipmentRarity)evt.newValue));
|
||||
WeaponCategory.RegisterValueChangedCallback(evt => ModifyWeaponType((WeaponCategory)evt.newValue));
|
||||
}
|
||||
|
||||
public void Initial(EquipmentConst equipment) {
|
||||
this.equipment = equipment;
|
||||
if (equipment == null) { return; }
|
||||
Name.SetValueWithoutNotify(equipment.name);
|
||||
Level.SetValueWithoutNotify(equipment.level);
|
||||
Sprite.SetValueWithoutNotify(equipment.sprite);
|
||||
Rarity.Init(equipment.rarity);
|
||||
weapon = equipment as WeaponConst;
|
||||
WeaponCategory.EnableInClassList("ew-hide", weapon == null);
|
||||
if (weapon == null) { return; }
|
||||
WeaponCategory.Init(weapon.category);
|
||||
}
|
||||
|
||||
/// <summary> 修改名字 </summary>
|
||||
private void ModifyName() {
|
||||
if (Name.value == null || Name.value == "") {
|
||||
Name.SetValueWithoutNotify(equipment.name);
|
||||
return;
|
||||
}
|
||||
string oldPath = AssetDatabase.GetAssetPath(equipment);
|
||||
AssetDatabase.RenameAsset(oldPath, Name.value);
|
||||
equipment.name = Name.value;
|
||||
Dirty();
|
||||
}
|
||||
/// <summary> 修改类型 </summary>
|
||||
private void ModifyLevel() { equipment.level = Level.value; Dirty(); }
|
||||
/// <summary> 修改预览图 </summary>
|
||||
private void ModifySprite() { equipment.sprite = Sprite.value as Sprite; Dirty(); }
|
||||
/// <summary> 修改布尔值 </summary>
|
||||
private void ModifyRarity(EquipmentRarity rarity) { equipment.rarity = rarity; Dirty(); }
|
||||
/// <summary> 修改武器类型 </summary>
|
||||
private void ModifyWeaponType(WeaponCategory category) { weapon.category = category; Dirty(); }
|
||||
|
||||
/// <summary> 保存资源 </summary>
|
||||
private void Dirty() {
|
||||
EditorUtility.SetDirty(equipment);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e7055e519bcd124f847fb3c863398e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
namespace MuHuaEditor {
|
||||
/// <summary>
|
||||
/// 装备设置
|
||||
/// </summary>
|
||||
public class UIEquipmentSettings : ModuleUIPanel {
|
||||
|
||||
public EquipmentConst equipment;
|
||||
public UIEquipmentInput equipmentInput;
|
||||
|
||||
public VisualElement EquipmentInput => Q<VisualElement>("EquipmentInput");
|
||||
|
||||
public UIEquipmentSettings(VisualElement element) : base(element) {
|
||||
equipmentInput = new UIEquipmentInput(EquipmentInput);
|
||||
}
|
||||
|
||||
public void Initial(EquipmentConst equipment) {
|
||||
this.equipment = equipment;
|
||||
element.EnableInClassList("ew-hide", equipment == null);
|
||||
equipmentInput.Initial(equipment);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c315dbb1477d31342a8c610161d5d477
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user