Write a Simple Mod

There might come a time when you would like to add your own modifier to the system to do a deformation specific to your game. This can be done by adding your own Modifier class that derives from the MegaModifier base class.

Here we will write a very simple modifier that will randomly add values to the vertex position. All you need to do to add a basic modifier is to override the Map(int i, Vector3 p) method in the MegaModifer base class. This is the method that is called for each vertex in the mesh being deformed. In this method you do whatever you like to the Vector3 p vertex position passed in and return the new value at the end. The MegaFier system will automatically handle dealing with such things as vertex selections. The i value passed in is the index into the meshes vertex list which can be useful for some calculations, if this value is -1 then the point being deformed is part of the gizmo box.

The ModName() and GetHelpURL() can also be overridden to give your name for the modifier and provide a help page for any params etc. The AddComponentMenu before the class will add the modifier to the menus in Unity for easy selection.

using UnityEngine;

public class SimpleMod : MegaModifier
    public Vector3 a3;

    public override string ModName() { return "Simple"; }
    public override string GetHelpURL() { return "SimpleMod.htm"; }

    public override Vector3 Map(int i, Vector3 p)
        p.x += (-1.0f + (Random.value * 0.5f)) * a3.x;
        p.y += (-1.0f + (Random.value * 0.5f)) * a3.y;
        p.z += (-1.0f + (Random.value * 0.5f)) * a3.z;
        return p;

Adding Custom Inspector

If you want MegaFiers to handle the inspector for you and also deal with the common params for a modifier such as gizmo colors, offsets and gizmo transforms then you will need to create an editor script where again you will extend a base class called MegaModifierEditor. That is all that is required for the custom inspectors to work.

using UnityEditor;

public class SimpleModEditor : MegaModifierEditor

A more complex modifier example will be added to this page soon showing some of the more advanced methods that can be used to do more powerful modifiers and more advanced editor inspectors etc.

You must be logged in to post a comment.