Deadcows / MyBox

MyBox is a set of attributes, tools and extensions for Unity
http://deadcow.ru
MIT License
1.94k stars 244 forks source link

Hide inherited properties from inspector #209

Closed FredTA closed 2 years ago

FredTA commented 2 years ago

Let's say I have a base class with some serializableField property, that gets inherited by the child class While the child class should have this property, I don't want this property to be visible in the inspector on this child class. It would be awesome if there could be a conditional field where the condition is className == someClass or className != someClass

Deadcows commented 2 years ago

It is already possible. ConditionalField allows to use method to check the field. ConditionalFieldAttribute(bool useMethod, string method, bool inverse = false) so you need to set true in the first parameter and method name in the second

[ConditionalField(true, "IsBaseClass")]
public bool ShownInBaseClass;
protected bool IsBaseClass() => GetType() == typeof(MyBaseClass);

note the protected keyword. It might be marked public as well, but provate method would not be accessible for the ConditionalField in the child class

..I really need to update the docs 😁