Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xjine/unity_remotecommands
RemoteCommand provides a simple logic to execute your methods from remote.
https://github.com/xjine/unity_remotecommands
assets unity
Last synced: 15 days ago
JSON representation
RemoteCommand provides a simple logic to execute your methods from remote.
- Host: GitHub
- URL: https://github.com/xjine/unity_remotecommands
- Owner: XJINE
- License: bsd-3-clause
- Created: 2019-03-11T13:34:09.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-12T02:26:18.000Z (about 2 months ago)
- Last Synced: 2024-11-12T03:23:31.971Z (about 2 months ago)
- Topics: assets, unity
- Language: C#
- Homepage:
- Size: 85.9 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unity_RemoteCommands
``RemoteCommands`` provides a simple logic to execute your methods from remote.
## Importing
You can use Package Manager or import it directly.
```
https://github.com/XJINE/Unity_RemoteCommands.git?path=Assets/Packages/RemoteCommands
```### Dependencies
This project use following resources.
- [Unity_SingletonMonoBehaviour](https://github.com/XJINE/Unity_SingletonMonoBehaviour)
- [Unity_IInitializable](https://github.com/XJINE/Unity_IInitializable)## How to Use
Set ``RemoteCommand`` attribute and the unique id.
Then, call ``RemoteCommander.Command()`` with id. That's all.```csharp
[RemoteCommand(ID = "SampleCommandA")]
public void SampleCommandA()
{
Debug.Log("SampleCommandA");
}RemoteCommander.Instance.Command("SampleCommandA");
```Function name will be set as ID when omitting it.
```csharp
[RemoteCommand]
public void SampleCommandB()
{
Debug.Log("SampleCommand");
}
```### Various Types
``RemoteCommand`` attribute is valid for ``public``, ``private``, ``protected`` and ``static`` methods.
```csharp
[RemoteCommand]
private void SampleCommandPrivate(){}[RemoteCommand]
public static void SampleCommandStatic(){}
```### Args and Return Value
``Command`` method can be set some args and we can get the return value from it.
```csharp
[RemoteCommand]
public float SampleCommandArgsReturn(int ivalue, float fvalue)
{
Debug.Log("SampleCommandReturn " + ivalue + ", " + fvalue);
return ivalue + fvalue;
}object sum = RemoteCommander.Instance.Command("SampleCommandArgsReturn", 999, 3.14f);
```## Limitation
``RemoteCommand`` must be declared in ``MonoBehaviour`` (or that inheritance).
And the instances are must be in the scene before it starts.``RemoteCommand.ID`` is must be unique in your scene.
### Override
```csharp
public class SampleA : MonoBehaviour
{
[RemoteCommand(ID = "SampleCommandVirtual")]
public virtual void SampleCommandOverride()
{
Debug.Log("SampleA.SampleCommandOverride");
}
}
public class SampleB : SampleA
{
[RemoteCommand(ID = "SampleCommandOverride")]
public override void SampleCommandOverride()
{
Debug.Log("SampleB.SampleCommandOverride");
}
}
…
RemoteCommander.Instance.Command("SampleCommandVirtual");
RemoteCommander.Instance.Command("SampleCommandOverride");
```When the ``Command("SampleCommandVirtual")`` and ``Command("SampleCommandOverride")`` are invoked with ``SampleB`` instance, it shows the same result.
The results are ``"SampleB.SampleCommandOverride"``.