Before you can use it, you need to:
Initialization needs to take all settings, prepare all Fireball modules and as result create FireballSession
object:
FireballSession
FireballSettings
for initialize Fireballpublic IFireball fireball;
...
public void Start()
{
fireball = Fireball.Game.Client.Fireball.Instance;
}
or just add Fireball.cs
script on scene and get it reference.
fireball.Init((session) =>
{
// success initialization
},
(error) =>
{
// handle error
});
FireballSettings
scriptable object - right-click inside the assets folder in Unity Editor and chose: Create > Fireball > New Settings
NOTE: Some operators require additional parameters, for this purpose you can use
Extra
field to set up these parameters as key-value pairs.
- Initialize Fireball with newly created settings:
public FireballSettings CustomSettings;
...
fireball.Init(CustomSettings, (session) =>
{
// success initialization
},
(error) =>
{
// handle error
});
You can create a few different
FireballSettings
files to easily switch between different operators and players, or setup differently other settings during developing games into Unity Editor.
AuthRequest request = new AuthRequest(session);
fireball.Authorize(request,
(response) =>
{
// success authorization
Debug.Log($"Balance: {response.Currency} {response.Balance}");
},
(error) =>
{
// handle error
Debug.LogError($"Error: {error.Reason}");
});
If you need to pass some additional data into server game function and back to client on authorization, you can easily create your own custom authorize request (and response) based on Fireball AuthRequest and AuthResponse class.
public class CustomAutorizeRequest : AuthRequest
{
public int CustiomId;
public string CustomField;
public CustomAutorizeRequest(int id, string field, FireballSession session) : base(session)
{
CustiomId = id;
CustomField = field;
}
}
public class CustomAutorizeResponse : AuthResponse
{
public int SomeIntField;
public string SomeStringField;
public Dictionary<string, string> AdditionalData;
}
var request = new CustomAutorizeRequest(123, "test", fireball.CurrentSession);
fireball.Authorize<CustomAutorizeRequest, CustomAutorizeResponse>(request,
(response) =>
{
// success authorization
Debug.Log($"SomeIntField: {response.SomeIntField}");
Debug.Log($"SomeStringField: {response.SomeStringField}");
},
(error) =>
{
// handle error
Debug.LogError($"Error: {error.Reason}");
});
Here is a complete code for the simplest way to initialize and authorize Fireball:
public IFireball fireball;
public FireballSettings CustomSettings;
...
public void Start()
{
if (fireball == null)
{
fireball = Fireball.Game.Client.Fireball.Instance;
}
fireball.Init(
#if UNITY_EDITOR
CustomSettings,
#endif
(session) =>
{
// success initialization
fireball.Authorize(new AuthRequest(session),
(response) =>
{
// success authorization
Debug.Log($"Balance: {response.Currency} {response.Balance}");
},
(error) =>
{
// handle error
Debug.LogError($"Error: {error.Reason}");
});
},
(error) =>
{
// handle error
Debug.LogError($"Error: {error}");
});
}
For successful authorization process simulation, you can use Demo authorization. It will create a successful auth response no matter what data you enter. It can be used for players to try the game locally in demo mode without connection to the fireball server. NOTE: all other fireball features (like messaging, jackpots etc.) will not work, so all game server calculations must be passed locally on the game client
fireball.DemoAuthorize("EUR", 50000,
(response) =>
{
// success demo authorization
Debug.Log($"Balance: {response.Currency} {response.Balance}");
});
Also, you can use the custom authorize request class (it will create and return a new instance of your class):
_fireball.DemoAuthorize<CustomAutorizeResponse>("EUR", 50000,
(response) =>
{
// success demo authorization
Debug.Log($"Balance: {response.Currency} {response.Balance}");
Debug.Log($"SomeIntField: {response.SomeIntField}");
Debug.Log($"SomeStringField: {response.SomeStringField}");
});