What Class/Array/List/Dictionary do I use in a Custom Editor

I’ve asked this in the forums but I’ve gotten no response:

I have tried everything, Arrays / Multidimensional Arrays, Jagged Arrays, Lists, Classes…
I am not getting the result I want to work in the Editor.

I have an Array of textures. However, I want to dynamically add/delete other texture arrays.

MainArray

-----TextureArray1

----------texture1

----------texture2

----------texture3

-----TextureArray2

----------texture4

----------texture5

----------texture6

----------texture7

----------texture8

----------texture9

-----TextureArray3

----------texture10

----------texture11

Then I want to access them like so
MainArray[0,2].name or MainArray[0][2].name ----> “texture2”

I want to be able to add a TextureArray# at the end of the MainArray
I want to be able to delete a TextureArray# & all texture# within the MainArray
I want to be able to add a texture# at the end of the TextureArray#
I want to be able to delete a texture# within the TextureArray#

I first got it working with a single-dimensional array with no trouble. I thought converting it to a multi-dimensional array would be easy. No. The problem is adding and deleting. I have to build a temporary array with an additional value and then copy it back to the MainArray. Not Working like it does in a single-dimensional array. I tried a List with its simple Add & Delete but couldn’t get it to work at all. As soon as I got to (Texture2D)EditorGUILayout.ObjectField it broke. It said I had too many arguments even though it worked fine with an Array.

How do I go about creating this type of system?

I’ve now started to use a List of Arrays where List calls a new class.
Of course, it still doesn’t work but I am puzzled by the error I am getting.

TextureObjects.cs


        using UnityEngine;
        using System.Collections;
         
        public class TextureObjects : MonoBehaviour {
            public TextureObjects(){
                Texture2D[] textureObject = new Texture2D[1];
            }
        }

MyClass.cs


using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[System.Serializable]

public class MyClass : MonoBehaviour {
     
     [SerializeField]
     public List<TextureObjects[]> textureObjects = new List<TextureObjects[]>();
     
     void Start(){
          textureObjects.Add (new TextureObjects[1]);
     }

}

MyClassEditor.cs


using UnityEngine;
using UnityEditor;
using System.Collections;
 
[CustomEditor( typeof( MyClass ) )]

[System.Serializable]

public class MyClassEditor : Editor {
 
 
     public override void OnInspectorGUI(){
     serializedObject.Update ();
 
     myClass.textureObjects[z] _= (Texture2D)EditorGUILayout.ObjectField ("", myClass.textureObjects[z]*, typeof(Texture2D), true, GUILayout.Width(100));*_
 
 _*}*_
_*}*_
_*```*_
_*(Note: 'z' loops through the List)*_
_*(Note: 'i' loops through the texture array)*_
_*The error I get on the myClass.textureObjects[z] is:*_
<em>_*No overload method 'ObjectField' takes '5' arguments.*_</em>
_*However, if I just use an array, this same line for ObjectField works without errors*_

Hi
unfortunately I don’t have Unity installed at work, so i build up for you C# console application, but that should work in the same way as in Unity.
You can download compiled console app here

Please investigate the code and i hope it will be clear for you how to achieve your goal.
Also im using Lists instead of arrays as arrays are toooo static and require exact size allocated where list is the same array just dynamic, u can add, remove elements within without reallocation of entire array.

using System;
using System.Collections.Generic;

namespace TestMultDimArr
{
    class Program
    {
        static void Main(string[] args)
        {
            new Runner();
            Console.ReadKey();
        }
    }

    public class Runner
    {
        List<List<List<Texture>>> mainHolder;
        public Runner()
        {
            initialise();
            displayListContent();
            updateListContent();
        }

        public void updateListContent()
        {
            //get 4d texture of 3d mid from main holder
            Texture my4dTextrFrom3dMid = mainHolder[0][2][3];
            Console.WriteLine("Got texture: " + my4dTextrFrom3dMid.name);
            //update name of texture
            mainHolder[0][2][3].name = mainHolder[0][2][3].name + " Updated Name";
            //see changes
            displayListContent();

            //delete 2nd mid
            mainHolder[0].Remove(mainHolder[0][1]);
            //see changes
            displayListContent();

            //delete 3d texture in 1st mid
            mainHolder[0][0].Remove(mainHolder[0][0][2]);
            //see changes
            displayListContent();

            //add 5th texture to 3d mid (keep in mind that mid 2 was already deleted)
            mainHolder[0][1].Add(new Texture("Mid-3 Texture6"));

            //add new mid
            List<List<Texture>> newMid = new List<List<Texture>>();
            newMid.Add(getInnerList(6));
            mainHolder.Add(newMid);
            //see changes
            displayListContent();
        }

        public void displayListContent()
        {
            foreach (var midList in mainHolder)
            {
                Console.WriteLine("Main List:");
                foreach (var txtrList in midList)
                {
                    Console.WriteLine(" - " + "Mid List:");
                    foreach (var txtr in txtrList)
                    {
                        Console.WriteLine(" - - "+txtr.name);
                    }
                }
            }
        }

        public void initialise()
        {
            /*
             * initialise 3 dementional list
             * Main holder
             * - mid texture holder1
             *  - - texture1
             *  - - texture2
             *  - - N
             *  - mid texture holder2
             *  - - texture1
             *  - - texture2
             *  - - N
             *  - Z
             *  ***
             */
            mainHolder = new List<List<List<Texture>>>();
            mainHolder.Add(getMidList());
        }

        public List<List<Texture>> getMidList()
        {
            List<List<Texture>> midHolder = new List<List<Texture>>();
            for (int i=1; i<=5; i++ )
            {
                midHolder.Add(getInnerList(i));
            }
            return midHolder;
        }

        public List<Texture> getInnerList(int mid)
        {
            List<Texture> innerList = new List<Texture>();
            for (int i=1; i<=5; i++ )
            {
                innerList.Add(new Texture("Mid-"+mid+" Texture"+i));
            }
            return innerList;
        }
    }

    //obstract Texture class, as im not in Unity, just console project
    public class Texture
    {
        public string name;
        public Texture(string name)
        {
            this.name = name;
        }
    }
}

please note this answer addresses requests made in various comments

You’ve lost me with the whole thing at this point. In your original question, you stated you wanted A Collection Of Collections Of Textures - right?

To achieve this, I would create a class called TextureGroup. Until it needs to do something else, all it does is “hold” a list of Texture2D objects.

public class TextureGroup {
     private List<Texture2D> textures;
     public List<Texture2D> Textures {
          get { if (textures==null) textures = new List<Texture2D>(); return textures; }
          set { textures = value; }
     }
}

That satisfies the first group-of-textures requirement. The group-of-groups requirement can be satisfied by having a list of TextureGroup objects.

List<TextureGroup> groups = new List<TextureGroup>();

When you create a new TextureGroup object, you can add it to the “groups” list. When you create a new Texture2D object, you can add it to any TextureGroup object’s “textures” list.