Frameworks

Momiji Framework

Momiji Framework

Developed Unity2018.x

Use Assets

  • UniRx
  • DoTween
  • Zenject

Setup

git submodule add https://github.com/MizoTake/MomijiFramework.git

Web API Client

[WIP] Swagger Codegen for Momiji

swagger-codegen-momiji

Usage Example

Sample で叩いてる WebAPI: livedoor Weather Hacks

上記の WebAPI を叩くのに必要なもの

SampleParamter.cs

public class SampleParamter : IPathParameterizable
{
	public int city;

	public SampleParamter (int city)
	{
		this.city = city;
	}

	public string QueryPath ()
	{
		return this.CreatePath (nameof (city) + "=" + city.ToString ());
	}
}

SampleRequest.cs

interface ISampleRequest
{
	IObservable<SampleResponse> Get;
}

public class SampleRequest : GetRequestable<SampleParamter, SampleResponse>, ISampleRequest
{
	public SampleRequest ()
	{
		HostName = "http://weather.livedoor.com/forecast/webservice/json/v1";
	}
}

SampleResponse.cs

public class SampleResponse  : IResponsible
{
	public string title;
}

Requester は実際に API を叩いて結果を得る実装

Requester.cs

public class Requester : MonoBehaviour
{

	void Start ()
	{
		var request = new SampleRequest ();

		request.Get
			.Subscribe (_ =>
			{
				Debug.Log (_.title);
			})
			.AddTo (this);

		/ ..省略.. /

		var param = new SampleParamter (city: 130010);

		request.Dispatch (param);

		/ ..省略.. /
	}
}

Request クラスで実装した API メソッドに合うメソッドを購読

Dispach で API を叩きにいく処理

License

MIT