Giter Club home page Giter Club logo

unity_remotecommand's Introduction

Unity_RemoteCommand

RemoteCommand provides a simple logic to execute your methods from remote.

Import to Your Project

Import this .unitypackage and the dependencies.

How to Use

[RemoteCommand(ID = "SampleCommandA")]
public void SampleCommandA()
{
    Debug.Log("SampleCommandA");
}
RemoteCommander.Instance.Command("SampleCommandA");

Set RemoteCommand attribute and the unique id. Then, call RemoteCommander.Command() with id. That's all.

[RemoteCommand]
public void SampleCommandB()
{
    Debug.Log("SampleCommand");
}

Function name will be set as ID when omitting it.

Various Types

RemoteCommand attribute is valid for public, private, protected and static methods.

[RemoteCommand]
private void SampleCommandPrivate(){}

[RemoteCommand]
public static void SampleCommandStatic(){}

Args and Return Value

Command method can set some args and we can get the return value.

[RemoteCommand]
public float SampleCommandArgsReturn(int ivalue, float fvalue)
{
    Debug.Log("SampleCommandReturn " + ivalue + ", " + fvalue);
    return ivalue + fvalue;
}object sum = RemoteCommander.Instance.Command(1, 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

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.

unity_remotecommand's People

Contributors

xjine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.