Skip to content

jcs090218/Unity.Mx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation



Logo

Typing SVG

License: MIT Unity Engine .NET Release Tag

openupm openupm

M-x for Unity

Mx (or Meta-X) is a command-based completion framework. It allows you to execute all kinds of tasks based on your design. Mx is an alternate to attribute MenuItem; by contrast, doing multiple tasks is possible. It gives you the option to choose and explore unnoticed commands.

Table of Contents

πŸ† Features

This part of the document explains what Mx is trying to aim for!

  • Search Assets
  • Search GameObjects by various way (Type, tag, name, etc)
  • Execute Menu
  • Get/Set EditorPrefs and PlayerPrefs
  • Visually see things in action (hover event)
  • Configurable & Extensible

and more!

πŸ’Ύ Installation

Go to our release page and download the latest .unitypackage. Then simply import it to your project!

Or install it through OpenUPM:

$ openupm add com.jcs090218.mx

This package requires the Visual Scripting package to be installed. Make sure you have it installed!

πŸ”¨ Usage

Hit Alt+x!

❓ How to define your own command?

Here is a simple example that prints out "Hello World!~" with Debug.Log.

[Interactive(summary: "Print Hello World!")]
private static void PrintHelloWorld()
{
    Debug.Log("Hello World!~");
}

But you need to define under a class inherit Mx!

using UnityEngine;
using Mx;  // For InteractiveAttribute.cs

public class DummyCommands : Mx.Mx
{
    // Place your command function here!
}

You can see all more advanced examples in our source code, under Assets/Mx/Editor/Commands!

βš› Interactive Attribute's Properties

This part of the document explains all properties inside the Interactive attribute.

attribute

πŸ§ͺ summary (string)

A brief description of your command. It will appear on the right of your command name.

πŸ§ͺ icon (string)

The name of the icon.

See the full list of icons in unity-editor-icons.

πŸ§ͺ tooltip (string)

The full description of your command. It will appear in the popup window when you hover with your mouse.

πŸ§ͺ enabled (boolean)

Enable/Disable your command. If the value is false, it will not be shown inside the completion window.

🧰 Advanced Usage

Mx provides some functions to accomplish more complex tasks.

βš™ CompletingRead (prompt, collection, callback, hover, requiredMatch)

Allows you to receive input from the user but limits their answer to the prompt.

CompletingRead("What's your favorite animal: ", 
    new List<string>() { "Cat", "Dog" }, 
    (answer, _) =>
    {
        Debug.Log("My favorite animal is " + answer);
    });

This is the most commonly used function since you can accomplish any task with it.

βš™ ReadString (prompt, callback)

A function allows users to input an arbitrary string.

ReadString("What is your name? ", 
    (answer, _) =>
    {
        Debug.Log("My name is " + answer);
    });

βš™ ReadNumber (prompt, callback)

A function allows users to input an arbitrary number.

ReadNumber("What is your age? ", 
    (answer, _) =>
    {
        Debug.Log("My age is " + answer);
    });

The result is a string, but you can parse it with int.Parse or float.Parse.

βš™ YesOrNo (prompt, callback)

The simplest function that only accepts Yes or No.

YesOrNo("Do you like Cat? ", 
    (answer, _) =>
    {
        switch (answer)
        {
            case "Yes":
                Debug.Log("Great! I like it too!");
                break;
            case "No":
                // Do something else
                break;
        }
    });

πŸ“Œ Credits

This part of the document lists projects that I've used as references to develop Mx.

  • Find Editor Tools by @phwitti - UI extracted here
  • FlxCs by @jcs090218 - Fuzzy matching library
  • Prefs by @jcs090218 - Retrieved list of EditorPrefs/PlayerPrefs

Any other supported projects:

πŸ” See Also

License

Copyright (c) Jen-Chieh Shen. All rights reserved.

See LICENSE for details.