Basicly, what I am trying to do, is to display a double array as one.
Let me explain better.
→ First I have a list of strings
[HideInInspector]
public List<string> ThemesList = new List<string>();
–>Then in the custom Editor I display it as a Drop Down Menu
GUIContent themeList = new GUIContent("Theme Mode");
code.SelecteedThemeIndex = EditorGUILayout.Popup(themeList, code.SelecteedThemeIndex, code.ThemesList.ToArray());
(code.SelecteedThemeIndex being my choice, (everything works just fine here))
→ Now I have an array of Images
public Image[][] ThemeArray = new Image[5][];
’ 5 ’ being the maximum allowed number.
→ to display it, In custom Editor I use
Image[][] array = code.ThemeArray;
code.showImages = EditorGUILayout.Foldout(code.showImages, "Themes List");
if (code.showImages)
{
EditorGUI.indentLevel++;
code.ObjectSize = Mathf.Max(0, EditorGUILayout.IntField("Size", code.ObjectSize));
for (int i = 0; i < code.ObjectSize; i++)
{
array[code.SelecteedThemeIndex][i] = (Image)EditorGUILayout.ObjectField("Theme " + i, array[code.SelecteedThemeIndex][i], typeof(Image), true);
}
EditorGUI.indentLevel--;
}
I am trying to show in inspector an array of images, based on the selected Index.
(ex. on Index 0, there will be 3 images (img 1, img 2, img 3)
on Index 1, there will be also 3 images (img 1, img 4, img 5)
and I can switch the Index through the drop down menu, and the images(aka Arrays) will be swaped)
Until now, if I set the ObjectSize to anything but ’ 0 ’ it gives me this error
In Visual Studio (2019) there are no errors.
If you need the full code there it is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public class ThemesCoder : MonoBehaviour
{
[HideInInspector]
public List<string> ThemesList = new List<string>();
[HideInInspector]
public List<Image> Theme = new List<Image>();
[HideInInspector]
public int SelecteedThemeIndex = 0;
[HideInInspector]
public bool showList = false;
[HideInInspector]
public bool showImages = false;
[HideInInspector]
public Image[][] ThemeArray = new Image[5][];
[HideInInspector]
public int ObjectSize = 0;
[HideInInspector]
public int size = 0;
[CustomEditor(typeof(ThemesCoder))]
//[CanEditMultipleObjects]
public class ThemeCoderEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
DrawInspector();
}
public void DrawInspector()
{
ThemesCoder code = (ThemesCoder)target;
#region Themes Modes List
code.showList = EditorGUILayout.Foldout(code.showList, "Themes List");
if (code.showList)
{
EditorGUI.indentLevel++;
List<string> list = code.ThemesList;
code.size = Mathf.Max(0, EditorGUILayout.IntField("Size", list.Count));
while (code.size > list.Count)
{
list.Add(null);
}
while (code.size < list.Count)
{
list.RemoveAt(list.Count - 1);
}
for (int i = 0; i < list.Count; i++)
{
list[i] = EditorGUILayout.TextField("Theme " + i, list[i]);
}
EditorGUI.indentLevel--;
}
#endregion
#region Curent Mode
GUIContent themeList = new GUIContent("Theme Mode");
code.SelecteedThemeIndex = EditorGUILayout.Popup(themeList, code.SelecteedThemeIndex, code.ThemesList.ToArray());
#endregion
EditorGUILayout.Space();
#region Theme Game Object
Image[][] array = code.ThemeArray;
code.showImages = EditorGUILayout.Foldout(code.showImages, "Themes List");
if (code.showImages)
{
EditorGUI.indentLevel++;
code.ObjectSize = Mathf.Max(0, EditorGUILayout.IntField("Size", code.ObjectSize));
for (int i = 0; i < code.ObjectSize; i++)
{
array[code.SelecteedThemeIndex][i] = (Image)EditorGUILayout.ObjectField("Theme " + i, array[code.SelecteedThemeIndex][i], typeof(Image), true);
}
EditorGUI.indentLevel--;
}
#endregion
}
}
}
Hope you can help me.
Thank You anticiped.