Skip to content

nekomimi-daimao/EasyHttpRpcExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyHttpRpcExample

example of EasyHttpRpc

execute-api

private EasyHttpRPC _easyHttpRPC;

private void Start()
{
    // newするとサーバが起動する.CancellationTokenが必要.
    // 任意でポート番号も指定できる.デフォルトは1234.
    _easyHttpRPC = new EasyHttpRPC(this.GetCancellationTokenOnDestroy());

    // 外から呼び出すメソッドを登録する.
    _easyHttpRPC.RegisterRPC(nameof(Instantiate), Instantiate);
}

// 引数のNameValueCollectionにはGetのパラメータがそのまま入っている.
// Taskなので終了まで待ってからレスポンスを返せる.
private async Task<string> Instantiate(NameValueCollection arg)
{
    await UniTask.SwitchToMainThread();

    var argColor = arg["color"];
    if (string.IsNullOrEmpty(argColor) || !ColorUtility.TryParseHtmlString(argColor, out var color))
    {
        color = Color.white;
    }

    var argCount = arg["count"];
    if (!int.TryParse(argCount, out var count))
    {
        count = 0;
    }

    await _primitiveSupplier.Instantiate(color, count);
    return "SUCCESS";
}

How to use (en)

  1. Install the VSCode plugin REST Client.
  2. Clone this repository.
  3. Open and run Assets/Scenes/EasyHttpRPCExample.unity.
  4. Open http/rest.http in VSCode.
  5. Enter the address displayed on the screen into rest.http.
  6. Run API.

How to use (ja)

  1. VSCodeのプラグイン REST Client をインストールします。
  2. このリポジトリをクローンします。
  3. Assets/Scenes/EasyHttpRPCExample.unityを開いて実行します。
  4. http/rest.httpをVSCodeで開きます。
  5. 画面に表示されたアドレスをrest.httpに入力します。
  6. APIを実行します。

API

  • instantiate
    Instantiate cube. count, color.
  • count
    Count instantiated cube.
  • error
    throw error
  • post
    post string

About

example for EasyHttpRpc

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages