|
It's hard to give a title for this question, sorry for this. My situation is this: I have a script that should set a property called "Monsters" (a list) on a given gameobject. This list is composed by a lot of Spawnable, wich is a simple class built in this way: So the Spawner script that is attached to my "Spawn" empty gameobject (a prefab): Are there any possibility to do this by allowing unity to automatically generate the editor for my custom type with its base editors? (one for int, one for bool and one for gameobject). Are there any way to set everything I've shown in the inspector? Thanks for any suggestion I would like to edit through the inspector my monsters list by setting its size (this is already possible) and set Spawnable properties for each item.
(comments are locked)
|
|
Yes, it's very straightforward- Your 'simple class' shouldn't be descended from MonoBehaviour. The MonoBehaviour class is a complex class with lots of functionality, and it's not really intended to work that way. Instead, just use the 'System.Serializable' attribute, and make it a base class. Then, when you create your public list, it will give you a sizable dropdown-list with the correct properties for the type. Correct! Data class shouldn't inherit from MonoBehaviour. They should be made as base class or you may want them to inherit from Object or ScriptableObject, which are explained in the Scripting Reference.
Jan 11 '12 at 10:04 PM
by0log1c
Your example is great and works really way, thanks a lot! (also to you Byologic). I used the MonoBehaviour only because it was the only way I know to make something appear in the inspector, I'm more happy with this approach keeping inheritance for other important things :)
Jan 11 '12 at 10:37 PM
Fire-Dragon-DoL
(comments are locked)
|
|
If you are not using custom inspector script then I believe all you need is the Serializable attribute.
(comments are locked)
|
|
Hi, And... what is the answer if I need Spawnable class like Monobehaviour?. I have the same problem and, in my case, I need to detect mouse behaviour over the element. I mean, imagine I have a GUI and a MenuPage and I have a list of controls, basically, this controls are buttons and I have a MenuButtonGUI class for it. Then, like Monster class, I have a MenuPage class to containing a List. When I write a sise in the list I watch a new element in the list but I cannot setup its properties. I have a "class MenuButtonGUIEditor : Editor" too and I tried with it to show and edit the properties of the buttons inside the MenuPage class without success. I have created a "class MenuPageEditor : Editor" to edit the properties of all, the MenuPage class and the properties of elements in the MenuButtonGUI list as well but it seems it's not the way. Any Idea? Regards, Jordi Please don't post questions as solutions - this is not a message board.
Mar 27 at 01:34 PM
whydoidoit
(comments are locked)
|
