Skip to content

Instantly share code, notes, and snippets.

@inertiave
Created December 5, 2019 01:51
Show Gist options
  • Save inertiave/83b203d3c7a1856484fb91a79bd24258 to your computer and use it in GitHub Desktop.
Save inertiave/83b203d3c7a1856484fb91a79bd24258 to your computer and use it in GitHub Desktop.
using System;
using UnityEngine;
[DefaultExecutionOrder(ExecuteOrder.LOGIN_INIT)]
public class LoginModule : MonoBehaviour
{
void Awake()
{
byte[] bytes = new byte[0];
ILoginModule loginModule = new LocalLoginModule();
loginModule.Login(bytes, result =>
{
switch ((ELoginError)result) {
case ELoginError.Undefined:
Debug.Log("Undefined");
break;
case ELoginError.PortClosed:
Debug.Log("Login Failed");
break;
case ELoginError.Success:
Debug.Log("Login success");
break;
default:
throw new ArgumentOutOfRangeException(nameof(result), result, null);
}
});
}
}
public class LocalLoginModule : ILoginModule {
public void Login(byte[] bytes, Action<int> loginResult)
{
Debug.Log("Try Log in...");
if (UnityEngine.Random.Range(0, 10) % 9 == 0) {
loginResult.Invoke((int) ELoginError.PortClosed);
}
else {
loginResult.Invoke((int) ELoginError.Success);
}
}
}
public interface ILoginModule {
void Login(byte[] bytes, Action<int> loginResult);
}
public enum ELoginError {
Undefined = -1,
Success = 0,
PortClosed = 100,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment