- Home /
 
               Question by 
               saifors · Mar 13, 2020 at 11:58 PM · 
                editoreditorwindowguilayouteditorguilayout  
              
 
              Custom Editor Struct array layout

Hello, I'd like to know whether there's any way for a custom editor to display an array of a struct like in the following mockup (or a way similar to it).
Currently I have it set up like the following, but this leads to every Element in the animations struct being in a foldout and it all being one after another vertically, any attempts at at least making the string name and int[] frames display horizontally with BeginHorizontal and EndHorizontal failed.
 using UnityEngine;
 using UnityEditor;
 
 public class AutoSpriteWindow : EditorWindow
 {
     public Texture2D texture;
 
     public string[] directions;
     public string[] dummy;
     public AnimStates[] animations;
 
     [MenuItem("Window/Custom/AutoSprite")]
     public static void ShowWindow()
     {
         GetWindow<AutoSpriteWindow>();
     }
     private void OnGUI()
     {
         EditorGUILayout.BeginHorizontal();
         texture = TextureField("Texture", texture);
         if(GUILayout.Button("Organize Spritesheet"))
         {
             Debug.Log("doot");
         }
         EditorGUILayout.EndHorizontal();
         EditorGUILayout.BeginHorizontal();
         StringArrayField(directions, "directions");
         AnimArrayField(animations, "animations");
         EditorGUILayout.EndHorizontal();
 
     }
 
     public void AnimArrayField(AnimStates[] prop, string name)
     {
         ScriptableObject target = this;
         SerializedObject so = new SerializedObject(target);
         SerializedProperty animsProperty = so.FindProperty(name);
         EditorGUILayout.PropertyField(animsProperty, true);
         so.ApplyModifiedProperties();
     }
 
     public void StringArrayField(string[] prop, string name)
     {
         ScriptableObject target = this;
         SerializedObject so = new SerializedObject(target);
         SerializedProperty stringsProperty = so.FindProperty(name);
         EditorGUILayout.PropertyField(stringsProperty, true);
         so.ApplyModifiedProperties();
     }
 
     //Diplay Tetxure With Label on top
     private static Texture2D TextureField(string name, Texture2D texture)
     {
         GUILayout.BeginVertical();
         var style = new GUIStyle(GUI.skin.label);
         style.alignment = TextAnchor.UpperCenter;
         style.fixedWidth = 70;
         GUILayout.Label(name, style);
         var result = (Texture2D)EditorGUILayout.ObjectField(texture, typeof(Texture2D), false, GUILayout.Width(70), GUILayout.Height(70));
         GUILayout.EndVertical();
         return result;
     }
 }
 
 [System.Serializable]
 public struct AnimStates
 {
     public string name;
     public int[] frames;
 }
Any help would be very much appreciated.
 
                 
                editormockup.png 
                (15.8 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                