We are trying to integrate some Custom Analytics SDK (lets call it TGA for short) in the game and we are in trouble
Currently our game uses save profiles locally to separate each player on the same device. It works perfectly because it doesn't need any authorization and it only needs saveslot ID to load the scene.
We need separate profile type where each player can authorize with the TGA online with 2 part ids (first entering a classID then a studentID )
Is it possible to make 2 different AC profiles with some kind of attributes to separate them?
for example:
Native Profile: current setup uses only a local saveID
TGA Profile: using the local saveID to get the TGA authorization details and then autologon
we need the players to be able to:
- chose which type of profile they are making on profile creation
- freely switch between the 2 types of profiles in the menus
- optional: having the visual cue what type of profile they are switching to (some way of reading profile attributes when rendering profile lists )
Comments
Profiles can be managed through custom scripting if need be - you can see the provided functions in the Options class here.
The key to this may be the Linked to option the Variables Manager. Any Global Variable can be set to link to Options Data, and this causes its value to be stored in PlayerPrefs (i.e. the user profile) instead of save data - see Section 9.4 of the Manual. This is intended for things like screen-resolution options that are save-independent, but could feasibly be used here as well.
While you could try some hackery that involves creating two profiles instead of one, I wonder if it would be easier to simply combine both and have a Global Boolean Variable that acts as a switch between the two, i.e. a Bool named "Is TGA" that's then linked to Options Data, gets toggled between True/False (either by custom scripting or by linking it to a Button/Toggle menu element).
In order to set the initial value on creation, you could use a separate "temporary" boolean value that is set with a Menu (and Variable: Set Actions) and is then copied to the option-linked Variable by using the Variable: Copy Action.
Save Profiles are covered in Section 9.8 of the Manual if you haven't seen it already, but so far as manipulating things through script go, you'll want to look at the Options and OptionsData classes in the scripting guide.
I'll try to summarise its behaviour, however:
Each save profiles works by storing a single instance of the "Options Data" class in a PlayerPrefs key. That PlayerPrefs key is logged in the Console when read from and written to.
The OptionsData class contains variables for things like SFX volume, chosen language, etc, that are used by all AC games. It also contains a string that represents a set of linked-variable values that can be "de-coded" into a proper array of values.
Global Variables, like Local Variables are normally save-dependent, i.e. each save file has its own value of each Variable. This means you can use them to keep track of a game's progress, e.g. whether or not an important cutscene has occured.
Individually they can, however be linked to Options Data via the Variables Manager. This causes them to become save-independent and instead stored within the Options Data (and, in turn, in the save profile and in PlayerPrefs).
By "save-independent", I mean that you can load up a different save and that Variable's value will not be changed as a result. It will only be changed if the variable itself is changed (using e.g. the Variable: Set Action). Each profile will now have its own value of this Variable.
It is possible to create an instance of OptionsData without switching profile - you just need the ID number of the profile you want to load:
OptionsData myOptionsData = AC.Options.LoadPrefsFromID (int profileID);
That will create a new instance of OptionsData that you can then read from as required. The variables data, condensed to a string, can be found with:
myOptionsData.linkedVariables
This string stores all linked variable IDs and values in one text, using pipes and colons to separate them. The SaveSystem's AssignVariables function converts this text and updates the real Variables accordingly - but you can copy the code inside it and use it to simply read their values instead. In the case of a Boolean variable, something like this would do it:
string[] varsArray = myOptionsData.linkedVariables.Split (SaveSystem.pipe[0]);
foreach (string chunk in varsArray)
{
string[] chunkData = chunk.Split (SaveSystem.colon[0]);
int _id = 0;
int.TryParse (chunkData[0], out _id);
if (_id == 2) // Or whatever the ID number of the Variable you want to check for is
{
int _value = 0;
int.TryParse (chunkData[1], out _value);
if (_value == 1)
{
// Value is True
}
else
{
// Value is False
}
}
}
Options.SavePrefsToID (myPrefsID, myOptionsData);
This allows you to update a profile with an OptionsData. You could load the OptionsData from a profile, read/modify it, and then update the original profile this way.
Each save profile should have its own independent value of any linked-variables. If you're getting different behaviour, please share the steps you took to reproduce it.