How to do it...

To create an extensible class-based code architecture to manage complex IMGUIs, follow these steps:

  1. First let's create an interface, that is, a template script-class that defines a method all implementing-classes must have. Create a folder Editor. Inside that create a folder MyGUI. Inside that create a new C# script-class named IMyGUI containing the following:
public interface IMyGUI {     void OnGUI(); } 
  1. Now, let's define a FlexibleSpace class for our GUI library. Create a C# script class named MyGUIFlexibleSpace containing the following:
using UnityEngine;  public class MyGUIFlexibleSpace : IMyGUI {     public void OnGUI()     {         GUILayout.FlexibleSpace();     } }
  1. Now, we'll create a button class. Create a C# script class named MyGUIButton ...

Get Unity 2018 Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.