- Home /
Question by
ossobuko · Apr 16, 2018 at 08:37 AM ·
c#programmingserialization
Dynamic EditorGuiLayout.PopUp list
Hello.
I am trying to use EditorGuiLayout.PopUp, but the string array is in another component attached to the same object.
I am using a PropertyAttribute and a CustomPropertyDrawer. I have to access the monobehaviour inside the drawer.
public class ClassA : MonoBehaviour
{
public List<Foo> foos = new List<Foo>();
[Serializable]
private class Foo
{
[MyAttribute]
public string field;
{
// custom property attribute
public class MyAttribute : PropertyAttribute
{
}
[CustomPropertyDrawer(typeof(MyAttribute))]
public class MyAttributeDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// how can I get the instance of classA ????
ClassA a;
// use getComponent
string[] names = a.GetComponent<MyOtherComponent>().getNames();
// draw
Editor.PopUp( ... , names)
}
}
}
How can I access the instance of ClassA ?
Note: I have simplified the code to make it easier to read. Everything else works fine.
Comment
Best Answer
Answer by ossobuko · Apr 16, 2018 at 08:49 AM
The answer was pretty simple.
ClassA a = (ClassA) property.serializedObject.targetObject;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Add lines to a script from another script 0 Answers
Problems with the XML Serializer 1 Answer
Distribute terrain in zones 3 Answers