Topic: [Tutorial] Unlockable Characters - Using included functions

In this thread, I'll give you information on the character unlocking functions included in UFE and also an example of how you can use them in your game.

This first post is informational about each of the included functions.  You won't need Source to use the functions, but Source will help you understand them better and possibly help with creating your own functions should you need them.

Click here to skip to the tutorial.

Unlocking Related Methods
All Character Unlocking related methods are located in UFE.cs, inside the region "public class methods: methods related to the character selection".  Each of these can be used with the prefix UFE. (e.g. UFE.LoadUnlockedCharacters();).

public static void LoadUnlockedCharacters()
This function loads the currently unlocked characters.  It is run automatically in UFE.cs Awake() method.  You may want to call this function after any new characters have been unlocked (to ensure they're loaded).


public static void SaveUnlockedCharacters()
This function saves the currently unlocked characters.  If you right click and select Find References in MonoDevelop, you'll see this is called from a number of the other functions below.  If you coded your own function and need to save the currently unlocked characters, then you should call this function with SaveUnlockedCharacters() if your code is in UFE.cs, or UFE.SaveUnlockedCharacters() if elsewhere.


public static void RemoveUnlockedCharacterInStoryMode(CharacterInfo character)
This function removes the provided character from Story Mode selection.  Use this for removing a single character from story mode selection.


public static void RemoveUnlockedCharacterInVersusMode(CharacterInfo character)
This function removes the provided character from Versus Mode selection.  Use this for removing a single character from versus mode selection.


public static void RemoveUnlockedCharactersInStoryMode()
This function removes all unlocked characters from Story Mode selection.  Use this to remove all unlocked characters from story mode selection.


public static void RemoveUnlockedCharactersInVersusMode()
This function removes all unlocked characters from Versus Mode selection.  Use this to remove all unlocked characters from versus mode selection.


public static void UnlockCharacterInStoryMode(CharacterInfo character)
This function unlocks the provided character in Story Mode selection.  Use this to unlock a specific character for story mode.


public static void UnlockCharacterInVersusMode(CharacterInfo character)
This function unlocks the provided character in Versus Mode selection.  Use this to unlock a specific character for versus mode.

Share

Thumbs up +1 Thumbs down

Re: [Tutorial] Unlockable Characters - Using included functions

Example Usage
This example unlocks the next available character upon finishing Story Mode.

First, set up your Story Mode.  I've removed all characters except Mike from the available selections in Story Mode and Versus Mode. 

http://i.imgur.com/jdEwZkH.png

I'm also using the default Story Mode example but I've changed it so it's just 2 battles - one against a random opponent between Mike/Joan/MecanimJoan, and the last is a boss battle with Robot Kyle.

http://i.imgur.com/GgHFOSA.png

Either open StoryModeTextureScreen.cs or copy it and modify it as your own.  Inside, we need to add three things.

First, in the public override void OnShow () method just below:

base.OnShow ();

add:

UFE.OnStoryModeCompleted += this.OnStoryModeCompleted;

Then just below the OnShow function, create an OnHide() method like the below:

    public override void OnHide() {
        base.OnHide();

        UFE.OnStoryModeCompleted -= this.OnStoryModeCompleted;
    }

These will take care of hooking into the UFE Event OnStoryModeCompleted, which we'll use to trigger the unlocks.

Finally, create the actual OnStoryModeCompleted function like the below:

    public void OnStoryModeCompleted(CharacterInfo character) {
        /*
         * This function hooks into the UFE event OnStoryModeCompleted,
         * which is triggered when Story Mode is completed.
         * 
         * Characters are unlocked in order they are listed in Global Config.
         * When the last character is played, 
         * 
         */

        // Loop through the Characters list and find the corresponding ID for played character
        int currentCharacterID = 0;
        for (int i=0; i<UFE.config.characters.Length; i++) {
            if (character.characterName == UFE.config.characters[i].characterName) {
                currentCharacterID = i;
                break;
            }
        }

        CharacterInfo newCharacter = null;

        // Prevent trying to unlock a character outside of the list
        if (currentCharacterID < UFE.config.characters.Length-1) {
            newCharacter = UFE.config.characters[currentCharacterID+1];
        }

        // Finally, unlock the character in Story and Vs
        if (newCharacter != null) {
            UFE.UnlockCharacterInStoryMode(newCharacter);
            UFE.UnlockCharacterInVersusMode(newCharacter);
            Debug.Log("Unlocked " + UFE.config.characters[currentCharacterID+1].characterName + "!");
        } else {
            Debug.Log("We've unlocked all the characters now, none left to unlock!");
        }

    }

Share

Thumbs up +3 Thumbs down

Re: [Tutorial] Unlockable Characters - Using included functions

Thanks for the awesome tip, but will this work for 1.7 ?

Thanks

Share

Thumbs up Thumbs down

Re: [Tutorial] Unlockable Characters - Using included functions

Hello, I just followed the intructions here and I am getting several errors., any guidance would be much appreciated.

THE ERRORS IM GETTING:

Assets\UFE\Engine\Scripts\UI_Templates\StoryModeTextureScreen.cs(18,3): error CS0123: No overload for 'OnStoryModeCompleted' matches delegate 'UFE.StoryModeHandler'

Assets\UFE\Engine\Scripts\UI_Templates\StoryModeTextureScreen.cs(40,9): error CS0123: No overload for 'OnStoryModeCompleted' matches delegate 'UFE.StoryModeHandler'

Assets\UFE\Engine\Scripts\UI_Templates\StoryModeTextureScreen.cs(56,27): error CS1061: 'CharacterInfo' does not contain a definition for 'characterName' and no accessible extension method 'characterName' accepting a first argument of type 'CharacterInfo' could be found (are you missing a using directive or an assembly reference?)

Assets\UFE\Engine\Scripts\UI_Templates\StoryModeTextureScreen.cs(62,38): error CS0037: Cannot convert null to 'CharacterInfo' because it is a non-nullable value type

Assets\UFE\Engine\Scripts\UI_Templates\StoryModeTextureScreen.cs(66,28): error CS0029: Cannot implicitly convert type 'UFE3D.CharacterInfo' to 'UnityEngine.CharacterInfo'

Assets\UFE\Engine\Scripts\UI_Templates\StoryModeTextureScreen.cs(70,13): error CS0019: Operator '!=' cannot be applied to operands of type 'CharacterInfo' and '<null>'

Assets\UFE\Engine\Scripts\UI_Templates\StoryModeTextureScreen.cs(71,44): error CS1503: Argument 1: cannot convert from 'UnityEngine.CharacterInfo' to 'UFE3D.CharacterInfo'

Share

Thumbs up Thumbs down