If you’re using the list to hold both types of C and B, you can check what you get from the list by attempting to cast the result A you get from the list to the type of B and C, if it casts correctly, you have your reference, if it’s null you know to try another cast type.
I’m not really sure what you mean, if the list should only contain one or the other, make sure the list is only of that type.
If you absolutely have to have the list able to take both types, but is only meant for one type, you can have an editor script that will pop up and test the first element in the array for it’s type, and tell you the answer, but this seems like more of an issue of self-management. If I’m understanding your question correctly, it sounds like you need to re-design your code structure.
What im trying to achieve is to be able to switch in the editor whether the list should take in B or C objects and hence expose the fields of either the B or C class in the editor List. I forgot to mention that the classes have the [System.Serializable] tag. I thought about something like a drop down menu saying I want either B or C…
You haven’t made your case plain enough for us to understand so it’s hard to help you here, but my guess is that you don’t want to use inheritence at all, and that you should look into interfaces for what you want to achieve. Give us a clear idea of what you’re trying to accomplish, it will help us help you.
The reason im using inheritance is so that I can make the system more flexible. I have a list of the Events which hold another list of type Dialog. Dialog is the A class and it can have several classes which inherit from it.
[System.Serializable]
public class Events
{
public List<Dialog> dialogClips;
}
public List<Events> events;
What I want to achieve is using this structure for whatever kind of Dialog I have. So the events list should be run through without caring for whatever is inside from the code point of view.
The reason for the whole editor thing is so that you easily can place in the parameters and clips for each Dialog type. Regardless of what type it is. But each type will of course have its own fields exposed.
Ok, let’s see if I have this right… Your Events class contains a list of Dialogs and each Dialog in this list can be (for simplicity sake) DialogA or DialogB, and when the list shows up in the editor inspector window, you want each Dialog in the list to expose those particular properties corresponding that that particular Dialog type. Is this correct? So let’s say you have a list containing DialogA and DialogB, and DialogA has a string property and DialogB has an int property, you want to be able to see a list with 2 items, one containing a string property that can be set, and the other with an int property that can be set?
Oh I’m sorry… are these actual Dialog windows? In that case, you want two windows, one with a string and the other with an int?
If so, then you’ll need to create either
a custom editor that uses reflection/attributes to automagically display the properties you want exposed and pass it the dialog instance
or
a custom editor for each Dialog type that exposes whatever you want, and you’ll know what type of Dialog to show based on the following check : if (dialogClip is DialogA) { // create DialogA window here } else if (dialogClip is DialogB) { // create DialogB window here }
There is no way around writing your own GUI inspector/editor.
When you down-cast a object (i.e. AudioEvent to Event), then only the Event properties are exposed, because you reduce it to the least common denominator. In order to access the “extended” features you have to upcast it.
I only want the events to be able to hold either B or C never mixed. The classes Event and Dialog are all custom classes I made which are made serializable. I dont have any way to check what is actually put into the list as everything will be put in through in the inspector. Hence I need to be able to tell what I want to put in before I actually add the values to their exposed fields.
Im still new to editor scripts, so any pointers in the right direction are highly appreciated.