[RELEASED] Code Macros for Unity

It’s code-generator tool which make possible to inject any type of the code.

Using
In any file (text or script) declare macros:

#region source macros MACROSNAME
var anyCode = 0;
++anyCode;
#endregion

In any file (where you want to use it):

#region macros MACROSNAME
#endregion

Result:

#region macros MACROSNAME
/* This code is auto-generated
* Do not change it
*/
var anyCode = 0;
++anyCode;
#endregion

So, you edit your code only once and it’s automatically updated in all your scripts.

Why

Try to imagine you have 2 base classes - Image and Text.

public class Image {

   private Texture texture;

   public void SetTexture(Texture texture) {
      this.texture = texture;
   }

   public Texture GetTexture() {
      return this.texture;
   }

}
public class Text {

   private string text;

   public void SetText(string text) {
      this.text = text;
   }

   public string GetText() {
      return this.text;
   }

}

So, now you want to create ImageAndText class:

public class ImageAndText {

   // What do you want to place here? Hm...

}

To avoid of copy-paste your code you can use macros:

public class ImageAndText {

   #region macros IMAGE
   #endregion

   #region macros TEXT
   #endregion

}

And declare it in both Text and Image classes:

public class Image {

   #region source macros IMAGE
   private Texture texture;

   public void SetTexture(Texture texture) {
      this.texture = texture;
   }

   public Texture GetTexture() {
      return this.texture;
   }
   #endregion

}
public class Text {

   #region source macros TEXT
   private string text;

   public void SetText(string text) {
      this.text = text;
   }

   public string GetText() {
      return this.text;
   }
   #endregion

}

It’s looks like you can do this things:

public class ImageAndText : Image, Text {}

But you can’t do this in C#, so you can use this hack :wink:

And yep, it’s free and open-source :slight_smile:

You can download it for free here:

5 Likes

Thanks, much appreciated.

Post update.