I have a simple custom editor window, which displays an asset.
The asset is a class which is derived from scriptable object and holds a list of third base class.
A simplified version:
using System;
using UnityEngine;
using UnityEditor;
[Serializable]
public class BaseClass
{
public int someValue;
public void OnGUI()
{
// EditorGUILayout Stuff - THIS IS THE PROBLEM RIGHT HERE
}
}
using System.Collections.Generic;
using UnityEngine;
public class ListContainer : ScriptableObject
{
public List<BaseClass> m_List;
void OnEnable()
{
//First check if this a new ScriptableObject or one which has been deserialized
if (m_Listt == null)
{
// Just initializing the list with a single entry
m_List = new List<BaseClass>()
{
new BaseClass()
};
}
}
public void OnGUI()
{
// Show each item in the list:
for (int i = 0; i < m_List.Count; i++)
{
m_List[i].OnGUI();
}
}
}
using UnityEngine;
using UnityEditor;
public class LevelEditor : EditorWindow
{
private ListContainer m_ListContainer;
[MenuItem("GameAssets/LevelsList")]
static void Init()
{
var window = GetWindow<LevelEditor>();
}
void OnGUI()
{
m_ListContainer.OnGUI();
}
}
The problem stems from the fact the I want the containing list and the base class, to display EditorGUILayout derived functions(being responsible for their own display in the custom editor window)…While this works for running the project in Unity editor… It fails on builds.
The error reported is : type or namespace name `UnityEditor’ could not be found. Are you missing a using directive or an assembly reference?
I understand this is due to the fact that I am not keeping the base level class and the ListContainer class in the “Editor” folder.
So what would be the right way of getting this done…Basically I am asking how can I have members which belong to an editor window be responsible for their own appearance in the editor window using EditorGUI /EditorGUILayout methods, while retaining their availability to other scripts outside the “Editor” folder.