今日進度

作者: SecondRun (雨夜琴聲)   2024-07-13 19:07:17
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這樣
窩要去吃炸雞了
作者: SiranuiFlare (阿火)   2023-07-13 19:07:00
大師
作者: Furina (芙寧娜)   2024-07-13 19:09:00
我好崇拜你
作者: aioiwer318 (哀歐)   2024-07-13 19:10:00
別卷了
作者: sustainer123 (caster)   2024-07-13 19:19:00
大師 養我
作者: SecondRun (雨夜琴聲)   2024-07-13 19:22:00
做遊戲做到要破產 球球你各位打賞一點

Links booklink

Contact Us: admin [ a t ] ucptt.com