• Stars
    star
    138
  • Rank 263,332 (Top 6 %)
  • Language
    C#
  • Created about 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Weaver is a code weaving framework built right into Unity Engine. Based heavily off of Fody.

Weaver

A a code weaver built for use in Unity Engine. Based very heavily off of Fody. Implmented using Mono.Cecil.

What is Code Weaving?

Weaving refers to the process of injecting functionality into an existing program. This can be done conceptually at a number of levels:

  • Source code weaving would inject source code lines before the code is compiled
  • IL weaving (for .NET) adds the code as IL instructions in the assembly

A great example of this is the Unity Project Updater. It uses both versions of code weaving on your project. It uses text replacing for unsupported code in your source files and IL weaving for compiled dlls.

Weaver for now only uses IL Weaving which runs once every time an assembly is recompiled.

Features

  • Hooked into Unity callbacks to run automatically.
  • Filter only the assemblies you want to weave.
  • Validation for end user.
  • Custom logger.
  • Utility functions to write MSIL.

How To Use

Weaver is run using a single ScriptableObjects you will need to create a new instance for your project. Int Unity use the create menu to create a new instance.

Right click in the Project Window Create/Weaver/Settings

You Only Need One: Only one instance should exist in your project since every operation only needs to happen once.

Weaved Assemblies

When you create a new instance by default Weaver will not edit any assemblies. It is up to you to define which assemblies you want to be modified. Click on the + icon on the bottom right and a context menu will pop up with all the valid assemblies you can target. You can also disable the assemblies in this list by unchecking the check box beside it's name. This will stop them from being edited.

Menu Content: The assemblies in the menu are populated with reflection and will be found if they they are anywhere ein the Unity Project.

Components

Weaver is built around it's components as they are what do the weaving of the assemblies. Weaver itself is just a provider of information for the components. They get notified when they should run and on which assemblies they should run against.

To add a new component use the (+) button to open the menu and pick any option.

There Can Only Be One: You can only have one instance of each component as having more would be useless.

Adding New Componet Types: The component menu uses reflection to find all types that inherit from WeaverComponent and are not abstract and are part of the EditorAssembly. Any new classes that match thoese rules will populate inside the menu.

Logs

To make the process a bit more clear but also not spam to your console Weaver logs all it's contents to it's own console on the ScriptableObject. Errors are also logged to the Unity console because that is important.

Toggling Weaver

If you would like Weaver to not run while in your project you can uncheck Is Enabled in the settings object. You also have the option to define if Weaver will run depending on the Script Symbols defined in Unity.

You can use any flag like UNITY_EDITOR or the inverse flag !UNITY_EDITOR. Weaver will only run if all flags are active.

Current Extensions

  • Method Timer - Any method with the MethodTimerAttribute will be timed using Stopwatch and logged to the console.

  • Profile Sample - Any method with the ProfileSample attribute will be have a profile sample injected into the method. The sample name will be the name of the method.

  • Property Changed : Invoke a callback whenever a property is marked with the [OnChanged(string callback)] attribute..

Git Sub Modules

  • Capture Groups: Used to generate the screen shots because I am too lazy to do that by hand. All code is under the preproc CAPTURE_GROUPS so feel free to remove this if you copy over the code.

Meta

Handcrafted by Byron Mayne [twitter β€’ github]

Released under the MIT License.

If you have any feedback or suggestions for Weaver feel free to contact me.

More Repositories

1

AssetPathAttribute

AssetPathAttribute is a Unity attribute used in Unity to allow you to have drag and drop asset references in the inspector but really use string paths for serialization.
C#
137
star
2

UnityIO

An easy to use API that allows you to manipulate files inside of Unity without the headache of using AssetDatabase.
C#
69
star
3

ScriptForge

A simple tool to generate constants for Unity for your Layers, Tags, Sorting Layers, Animations, Scenes, and Resources.
C#
53
star
4

SourceGenerator.Foundations

A Source Generator for Source Generators. Gives out of the box support for transistent dependencies and logging right in Visual Studio
C#
26
star
5

Reflected-Inspector

Reflected Inspector is a system for Unity that works very much like Serialized Properties but works with non-Unity types and can serialize the values.
C#
20
star
6

StyleBrowser

A browser editor window to view all Unity built in styles.
C#
11
star
7

LoxSharp

The C# implementation of the Lox Tutorials written by @munificentbob found at http://www.craftinginterpreters.com/
C#
8
star
8

CaptureGroups

A editor tool used to take screenshots for documentation
C#
7
star
9

CallMeEasy

CallMeEasy is a series of Unity attributes that allow you to hook into some callbacks that Unity does not expose out of the box.
C#
7
star
10

Seed.IO

Seed.IO is a library containing a bunch of useful helpers types and class for working with IO
C#
5
star
11

IPool

IPool is an open source Unity pooling system. It's designed to be easy to use and full docmented.
C#
5
star
12

GUIGrid

A simple to use IMGUI grid class for editor windows in Unity
C#
4
star
13

Recoil.net

Recoil.net is the C# version of the Facebook's Recoil.js library. It's designed to handle managing state in WPF applications.
C#
4
star
14

JiffyEditor

Powerful unity editor to auto generate inspectors and property drawers.
C#
4
star
15

Parcel

Parcel is an open source project that is used to allow you to load from Asset Bundles in Editor without really building them. So when you build your game the logic flow stays the same.
C#
3
star
16

Extended.Collections

Library containg C# collections of verious types of collections.
C#
2
star
17

MUUG-Aug-2017

The source code for my Montreal Unity User Group talk that is happening on 8/16/2017
C#
2
star
18

Ninject.Extensions.AutoFactories

C#
1
star
19

SearchableList

C#
1
star
20

Redux.DotNet

A C# implemention of Redux but done in C#. This also contains a WPF abstraction
C#
1
star
21

AtomPackageManager

C#
1
star
22

AsyncApi-Generator-CSharp

A C# implemention of the AsyncApi generator used to create both client and servers.
TypeScript
1
star
23

clox

My implementation of the Byte Code Interpreter following the great book Crafting Interpreters by Bob Nystrom. Chapter starts http://www.craftinginterpreters.com/chunks-of-bytecode.html
C
1
star
24

Turnip

Turnip is a cross platform time timer library that adds full timer support in Unity. In 1702 based on the verge movement thick pocketwatches went out of fashion and were only worn by the poor and derisively referred to as "turnips".
C#
1
star
25

OpenApi.SourceGenerator

OpenApi.Generator uses a Source Generator to generate the boilerplate for an Asp.Net Core application that is based of a preexisting openapi definition
C#
1
star