Community Made Tools

Have you made any useful utilities with Odin?

Login and submit your creations here

Facade

Authored by Gijs-Jan
Shared 23-05-2020

Facade is a tiny add-on for OdinInspector which allows you to define types which will be used to render an editor instead of the target type. With it you can use the attributes you know and love instead of having to implement a whole custom ValueDrawer.

To install, simply download the single source file from here and place it in your assets folder.

Let's say you have a type called ComplexObject, which you either can't edit, or editing it would be too much work. You simply want to show parts of the object without having to write a custom ValueDrawer.

Create a new type that inherits from OdinFacade and uses ComplexObject as the target. Then write the properties that access the variables you want to change on the target and use attributes as you normally would.

Per Example:

public class ComplexObjectFacade : OdinFacade<ComplexObject> {
    
   // Draws the Name label if ComplexObject is not null.
   [ShowInInspector, HideIf("@Target == null")]
   public string Name
   {
       get { return Target?.Name; }
       set { if(Target != null) Target.Name = value; }
   }
       
}

TODO

  • Support inheritance on OdinFacade.
  • Implement auto-mapping of variables/properties so the null-check can be avoided.