Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Creating custom interfaces

A topic by ratuspro created Dec 12, 2018 Views: 247 Replies: 7
Viewing posts 1 to 3
Submitted

Hello, 

I've started to play a little bit with your Unity Client and found some troubles when changing the default interfaces.

My goal is to create new interfaces for the log in, registration, and other functionality available in SUGAR's API. However, to what extent can a developer change the default interfaces?

After adding the SUGAR prefab into a scene, I'm not able to remove the components for such functionalities (Account Unity Client, Evaluation Unity Client, etc...). Does this mean that to create custom screens, I need to work with this components and link some "custom panel prefabs" to each one of them? If so, seems to me that this approach compromises the extensibility of the framework. 

I was not able to find on the documentation any detail about this. Can someone please advise on this subject?

Thanks in advance!

Host

Hey ratuspro,

There are 2 approaches for using custom interfaces with SUGAR. 

1. Edit the default interfaces to match your game style/needs

This is the simpler approach, locate the prefabs in SUGAR/Example/Prefabs and make changes as required. 

These example prefabs are controlled by the SUGAR Prefab in scene and can be displayed easily using the SUGARManager. If you want to replace the interface with your own prefab, you will need to add the Interface Component (eg. AccountInterface), which can be found at SUGAR/Example/Scripts, these classes extend their base interfaces

2. Create custom interfaces

This process requires understanding of the SUGAR Client API, Set up your own panel as you would normally for your game, and instead of using the interfaces and unity client classes, you will now need to integrate using SUGARManager.Client to make requests to SUGAR. 

For example, to log in, you would use SUGARManager.Client.Session.Login(gameId, accountRequest);  - See here

To display the panel in game, you will still need to use the SUGARManager to control UI, as this will order your UI correctly to make sure that the current UI is the topmost. To do this, add the prefab to the "Custom Interface List" in the SUGAR Prefab, making sure to give it a unique name. For example, creating a custom interface called "TestPanel" could be activated using SUGARManager.Unity.EnableObject(SUGARManager.Unity.CustomInterfaces["TestPanel"]);

I Hope this helps to clear things up!

Thanks

Submitted

Thanks! 

It was very helpful. I'm going to stick with the second option. 

But you mention the need to use the SUGARManager to control the UI. Is it mandatory? 

What if I have my own manager for the UI? It looks like it is not easy to decouple the SUGAR Unity Manager from custom logic for the game. 

Should I try to use the SUGAR API directly?

Thanks a lot.

Host

It is not necessary to use the SUGARManager to control UI, this is to help your custom UI work with the existing UI templates. If you intend to use only your own UI, then yes, it is perfectly fine to not use the manager, just use SUGARManager.Client in your code to use SUGAR features. This will help to manage requests and callbacks

Thanks

Submitted

Nice! Hopefully, I'll be able to customize the UIs.

However, now that I'm directly trying to instantiate the SUGARClient, I'm getting some errors in the following (simple) code:

        _sugarClient = new SUGARClient("http://gamejam.sugarengine.org/");
        GameClient gc = _sugarClient.Game;
        var game = gc.Get();

If I execute the code above, I'll get an error on the third line, when calling gc.Get(). The log I get is:


I'm not able to get any usefull information from that Log. Do you have any idea of what is going on? 

Thanks in advance.

Host (2 edits)

Are you using the SUGAR prefab in your scene, regardless of if you intend to use the default UI or not, this will make integration simpler and will allow you to use the SUGARManager.Client for API calls, make sure that you are logged in before making calls to the API.

To give an example of how you would do this, see below:

SUGARManager.Client.Session.LoginAsync(Id, new AccountRequest { Name = "[x]", Password = "[y]", SourceToken = "SUGAR" },
success => {
var example = SUGARManager.Client.Game.Get().First();
Debug.Log(example.Name);
}, exception => {
Debug.LogError(exception);
});

where Id is known from the admin panel, x and y are the login details provided.

In the Success callback we are just checking a game is returned in Game.Get(), this code is merely an example and probably not be very useful :)

If you want to use SUGARClient directly, it may be wise to host your own version of SUGAR locally so that you can debug it easily. We have provided details of how to setup its docker container here

Thanks

Submitted

Hello again,
Thank you very much.  I missed the login part, namely in the same example you gave. I thought to retrieve details about the game, such as the game's id, a login wasn't necessary.
Still, I don't think I'm going to host my server. The one you provided for the game jam suits my needs.
Thanks again!

Host

Hi ratuspro,

Just to reiterate some of the getting started with SUGAR steps (to make sure its clear), you should know the game token (name of the game) and id, through the game creation in the admin panel. This information is then set in the SUGAR prefab, to be used for API calls, you should not have to retrieve these through code. See Getting Started  (see step 4. Configure It!)

Thanks