1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| using UnityEngine; using UnityEditor;
public class PlayerProfileWindow : EditorWindow { private string playerName = "Player"; private int level = 1; private float health = 100f; private Color playerColor = Color.white; private bool showAdvanced = false; private Vector2 scrollPosition;
[MenuItem("Tools/Player Profile")] static void ShowWindow() { var window = GetWindow<PlayerProfileWindow>("玩家配置"); window.Show(); }
private void OnGUI() { scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); { EditorGUILayout.LabelField("基础信息", EditorStyles.boldLabel); playerName = EditorGUILayout.TextField("玩家名称", playerName); level = EditorGUILayout.IntSlider("等级", level, 1, 100);
EditorGUILayout.Space(10);
EditorGUILayout.LabelField("属性值", EditorStyles.boldLabel); health = EditorGUILayout.Slider("生命值", health, 0, 100); playerColor = EditorGUILayout.ColorField("角色颜色", playerColor);
EditorGUILayout.Space(10);
showAdvanced = EditorGUILayout.Foldout(showAdvanced, "高级设置"); if (showAdvanced) { EditorGUI.indentLevel++; EditorGUILayout.Toggle("启用调试", false); EditorGUILayout.Toggle("显示伤害数字", true); EditorGUILayout.Toggle("自动存档", true); EditorGUI.indentLevel--; }
EditorGUILayout.Space(10);
EditorGUILayout.LabelField("预览", EditorStyles.boldLabel); Rect previewRect = EditorGUILayout.GetControlRect(false, 60); EditorGUI.DrawRect(previewRect, playerColor); GUI.Label(previewRect, $"Lv.{level} {playerColor}", EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space(10);
using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("保存配置", GUILayout.Height(30))) { SaveProfile(); } if (GUILayout.Button("重置", GUILayout.Height(30))) { ResetProfile(); } } } EditorGUILayout.EndScrollView(); }
private void SaveProfile() { Debug.Log($"保存: {playerName}, Lv.{level}"); }
private void ResetProfile() { playerName = "Player"; level = 1; health = 100f; playerColor = Color.white; } }
|