Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jcs090218/unity.mx

M-x for Unity
https://github.com/jcs090218/unity.mx

command command-palette m-x unity

Last synced: 3 months ago
JSON representation

M-x for Unity

Awesome Lists containing this project

README

        




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](#๐Ÿ†-features)
- [๐Ÿ“‡ Commands](#๐Ÿ“‡-commands)
- [๐Ÿ’พ Installation](#๐Ÿ’พ-installation)
- [๐Ÿ”จ Usage](#๐Ÿ”จ-usage)
- [โ“ How to define your own command?](#โ“-how-to-define-your-own-command)
- [โš› `Interactive` Attribute's Properties](#โš›-interactive-attributes-properties)
- [๐Ÿงช summary (`string`)](#๐Ÿงช-summary-string)
- [๐Ÿงช icon (`string`)](#๐Ÿงช-icon-string)
- [๐Ÿงช tooltip (`string`)](#๐Ÿงช-tooltip-string)
- [๐Ÿงช enabled (`boolean`)](#๐Ÿงช-enabled-boolean)
- [๐Ÿงฐ Advanced Usage](#๐Ÿงฐ-advanced-usage)
- [โš™ CompletingRead (`prompt`, `collection`, `callback`, `hover`, `requiredMatch`)](#โš™-completingread-prompt-collection-callback-hover-requiredmatch)
- [โš™ ReadString (`prompt`, `callback`)](#โš™-readstring-prompt-callback)
- [โš™ ReadNumber (`prompt`, `callback`)](#โš™-readnumber-prompt-callback)
- [โš™ YesOrNo (`prompt`, `callback`)](#โš™-yesorno-prompt-callback)
- [๐Ÿ“Œ Credits](#๐Ÿ“Œ-credits)
- [๐Ÿ” See Also](#๐Ÿ”-see-also)
- [License](#license)

## ๐Ÿ† 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](https://github.com/jcs090218/Unity.Mx/releases) and download the latest `.unitypackage`.
Then simply import it to your project!

Or install it through [OpenUPM](https://openupm.com/packages/com.jcs090218.mx/):

```sh
$ 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`.

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

But you need to define under a class inherit `Mx`!

```cs
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.

```cs
CompletingRead("What's your favorite animal: ",
new List() { "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.

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

### โš™ ReadNumber (`prompt`, `callback`)

A function allows users to input an arbitrary number.

```cs
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`.

```cs
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:

- [readme-typing-svg][] by **`@DenverCoder1`**

## ๐Ÿ” See Also

- [Find Editor Tools][] - Command Palette for Unity
- [ReUniter][] - Better Search For Unity
- [QuickSearch][] - A Command Palette for Unity

## License

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

See [LICENSE](./LICENSE) for details.

[Assets/Mx/Editor/Commands]: https://github.com/jcs090218/Unity.Mx/tree/master/Assets/Mx/Editor/Commands
[unity-editor-icons]: https://github.com/halak/unity-editor-icons

[Find Editor Tools]: https://github.com/phwitti/unity-find-editor-tools
[FlxCs]: https://github.com/jcs090218/FlxCs
[Prefs]: https://github.com/jcs090218/Unity.Prefs
[readme-typing-svg]: https://github.com/DenverCoder1/readme-typing-svg

[ReUniter]: https://assetstore.unity.com/packages/tools/utilities/reuniter-better-search-for-unity-28691
[QuickSearch]: https://github.com/appetizermonster/Unity3D-QuickSearch