Unity как внутри списка отобразить/скрыть поля в зависимости от значения в enum

У меня есть класс унаследованный от ScriptableObject в нëм есть один список классов Actions и в каждом элементе в зависимости от выбранного типа (поле Type) показывается определëнное поле

(если изменение размера (Type.Scale) то надо указать размер (поле Scale) если переход (Type.Transition) то надо указать цвет (поле Color) и тд)

я написал для этого скрипт AnimationEditor в котором это предусмотренно но при отрисовке полей они рисуются не в текущем элементе а в самом низу

А вот как должно

Подскажите пожалуйста как это исправить

Вот код скрипта Animation:

using System.Collections.Generic;
using UnityEngine;

namespace Independent.Animation
{
    [CreateAssetMenu(menuName = "Data/Animation/Animation", fileName = "Animation")]
    public class Animation : ScriptableObject
    {
        public enum Type
        {
            None = 0,
            Move = 1,
            Rotate = 2,
            Scale = 3,
            Transition = 4
        }

        public class Object<T1, T2, T3, T4, T5, T6, T7, T8>
        {
            public T1 Type;
            public T2 Curve;
            public T3 StartIn;
            public T4 Length;

            [HideInInspector]
            public T5 Offset;
            [HideInInspector]
            public T6 Degrees;
            [HideInInspector]
            public T7 Scale;
            [HideInInspector]
            public T8 Color;
        }
        [System.Serializable]
        public class Action : Object<Type, AnimationCurve, float, float, Vector3, int, Vector3, Color> { }



        public List<Action> Actions;
    }
}

А вот AnimationEditor:

using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(Independent.Animation.Animation))]
[CanEditMultipleObjects]
public class AnimationEditor : Editor
{
    private Independent.Animation.Animation Script;



    public void OnEnable()
    {
        Script = (Independent.Animation.Animation)target;
    }

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        foreach (var Action in Script.Actions)
        {
            if (Action.Type == Independent.Animation.Animation.Type.Move)
            {
                Action.Offset = EditorGUILayout.Vector3Field(new GUIContent("Offset"), Action.Offset);
            }
            if (Action.Type == Independent.Animation.Animation.Type.Rotate)
            {
                Action.Degrees = EditorGUILayout.IntField(new GUIContent("Degrees"), Action.Degrees);
            }
            if (Action.Type == Independent.Animation.Animation.Type.Scale)
            {
                Action.Scale = EditorGUILayout.Vector3Field(new GUIContent("Scale"), Action.Scale);
            }
            if (Action.Type == Independent.Animation.Animation.Type.Transition)
            {
                Action.Color = EditorGUILayout.ColorField(new GUIContent("Transition"), Action.Color);
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
}

Надеюсь я понятно объяснил


Ответы (1 шт):

Автор решения: FruitGames537

Короче я решил эту проблему с помощью ReorderableList

→ Ссылка