Hi,
I have a class (Test) that includes an enumeration to be used as a mask.
using UnityEngine;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;
// Need Serializable and class attributes to make InitParms visible in the editor.
[Serializable]
public class Test : MonoBehaviour
{
public enum Mask
{
one = 1,
two = 2,
four = 4,
eight = 8,
};
public Test()
{
}
public Mask m_Mask = 0;
}
In order to allow multiple items to be selected within variables of that enumeration’s type, I made a custom editor.
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
[CustomEditor(typeof(Test))]
public class TestEditor : Editor
{
public override void OnInspectorGUI()
{
Test script = (Test)target;
script.m_Mask = ((Test.Mask)EditorGUILayout.EnumMaskField("Mask", (Test.Mask)script.m_Mask));
}
}
This worked fine until I tried to use that class as a separate class member inside a second class, TestClass.
using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;
public class TestClass : MonoBehaviour
{
TestClass()
{
}
public Test m_Test;
}
After adding both to scripts to a game object, I have problems viewing the TestClass script’s m_Test member variable. All that is displayed in the inspector is None(Test)
If I delete the editor script, then the TestClass member variable m_Test displays properly, however I can no longer choose multiple items from the enumerated mask.
Any idea as to how to solve this problem? My ultimate desire is to add a member variable to a class and select multiple mask bits via the inspector. The attached image is to simply illustrate that the custom editor works so long as the Test.cs script is dropped directly onto the game object.
Thanks,
Brian