Skip to content

LenixSO/SerializedMethod

Repository files navigation

Serialized Method

A package for serializing class methods in unity editor.

Instalation

You can install this package via Unity package manager, using the git link: https://github.com/LenixSO/SerializedMethod/#upm

SerializeMethod Attribute

By adding the SerializedMethod attribute to a method in a MonoBehaviour class, a button to call that method will appear in the inspector of that class.

image

The method can also have parameters and return values

image

You can also add the SerializeClassMethods attribute to your classes to serialize all public and/or not public methods in that class

image

The package supports most of C# and Unity's basic types when serializing parameters for the functions, and it can also serialize some types of strucs and classes, but in case you want to serialize a function with a unsupported parameter type you can create your own serialization.

Creating your own SerializedObject

The parameters are serialized using Unity's VisualElement, and you can create a template of your serialization from the creation menu:

image

This will create a template script for your serialization, with all the basics you need to make it work. The template also comes with an example of how a custom serialization would look like for an integer parameter (which already has its serialization).

The script must be on the Resources folder to be detected!

image

usedTypes: The type(s) this script will be used to serialize. this usually will contain only one type, but in some ocasions it might be possible to use the same script for multiple types.

image

GetElement: The method that will return the VisualElement that represents the serialization of the usedTypes. It's parameters are:

  • label: The name of the parameter being serialized.
  • value: The initial value of the parameter.
  • type: The parameter type.
  • onValueChanged: Invoke this action when the parameter value changes in the inspector so it can be internally saved by the package.

MethodTesting Window

If you don't want to add the SerializeMethod attribute to all methods in a class, you can also see all non-static methods of a MonoBehaviour class using the MethodTest Window.

image

Just pick the Target object(GameObject) and the Class(Component) and all all non-static methods will appear in the window the same way they would using the attribute.

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages