using MyGame.Battle; using Sirenix.Utilities.Editor; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEditor; using UnityEngine; namespace MyGame.Editor { public class CardEffectEditor : EditorWindow { private static CardEffectEditor window; private readonly Type baseType = typeof(CardEffect); private string[] baseTypeFields; private string[] tableKeys; private Type[] tableValues; private int selectIndex; private int currentIndex; private SerializedObject serializedObject; private SerializedProperty[] properties; [MenuItem("MyMenu/CardEffect編輯器")] private static void OpenWindow() { window = GetWindow<CardEffectEditor>("CardEffect編輯器"); } private void OnEnable() { baseTypeFields = GetFields(baseType).Select(x => x.Name).ToArray(); tableKeys = CardEffectTable.Table.Keys.Select(x => x.ToString()).ToArray(); tableValues = CardEffectTable.Table.Values.ToArray(); selectIndex = 0; currentIndex = 0; SelectIndex(0); } private void OnGUI() { // effect type dropdown selectIndex = EditorGUILayout.Popup("EffectType", selectIndex, tableKeys); // copy button if (GUILayout.Button("Copy json data to clipboard")) { string json = JsonUtility.ToJson(serializedObject.targetObject); Clipboard.Copy(json); } EditorGUILayout.Space(10); // object properties if (serializedObject == null) return; foreach (var property in properties) { EditorGUILayout.PropertyField(property); } serializedObject.ApplyModifiedProperties(); } private void OnInspectorUpdate() { if (currentIndex == selectIndex) return; currentIndex = selectIndex; SelectIndex(currentIndex); } private IEnumerable<FieldInfo> GetFields(Type type) { return type.GetFields() .Where(x => x.IsDefined(typeof(HideInInspector), true) == false); } private void SelectIndex(int index) { Type type = tableValues[index]; ScriptableObject obj = CreateInstance(type); serializedObject = new SerializedObject(obj); properties = GetFields(type) .OrderBy(x => baseTypeFields.Contains(x.Name) == false) // baseType 的 fields 會排在前面 .Select(x => serializedObject.FindProperty(x.Name)) .ToArray(); } } } 大概4這樣 窩要去吃炸雞了 -- (づ′・ω・)づ -- ※ 發信站: 批踢踢實業坊(ptt-website.tw), 來自: 49.158.160.52 (臺灣) ※ 文章網址: https://ptt-website.tw/Marginalman/M.1720868840.A.DC0
SiranuiFlare: 大師 07/13 19:07
Furina: 我好崇拜你 07/13 19:09
aioiwer318: 別卷了 07/13 19:10
sustainer123: 大師 養我 07/13 19:19
SecondRun: 做遊戲做到要破產 球球你各位打賞一點 07/13 19:22
alexantiy: 包養不急於談戀愛結婚。 07/13 19:22