In my project we use Unity with Gamesparks and want to handle in a efficient way our errors which are sent from Gamesparks to Unity. We have foreach Response an own Class which parse the right error from Gamesparks and save them in a class like this: public class GetMiniGameTutorialResponse { public enum ErrorCodes { TIMEOUT, INVALID_MINI_GAME_ID }
public bool hasErrors;
private ErrorCodes _error;
public ErrorCodes error {
set {
hasErrors = true;
_error = value;
}
get { return _error; }
}
public string tutorial;
public string control;
}
Next is that we handle these errors in a script of our scene in Unity and handle them with a switch case like this:
private void getMiniGameTutorialResponseErrorHandler(GetMiniGameTutorialResponse.ErrorCodes error)
{
switch (error)
{
case GetMiniGameTutorialResponse.ErrorCodes.TIMEOUT:
showConnectionError();
break;
case GetMiniGameTutorialResponse.ErrorCodes.INVALID_MINI_GAME_ID:
Debug.LogWarning("UNKNOWN STATE ERROR");
break;
default:
Debug.LogError("UNKNOWN ERROR");
break;
}
}
We need to do this in every script where we want to use the GetMiniGameTutorialResponse class.
My question now is if everyone of you want to help me to refactor this so that my code styling will be better :D
Aucun commentaire:
Enregistrer un commentaire