Topic: Alternate Costumes [SOLUTION]
I wrote this code some time ago Because when my brother taught me how movesets and character models worked on UFE my first thought was" that should make easy to create characters with multiple costumes", but when he told me UFE hadn't implemented that I make the commitment to myself that I should do it for our Game Tzompantli. So I already did it some months ago, but did not have time to post it until now, here it is the way I made the alternate costumes work on UFE.
First
on CharacterInfo.cs just add
public GameObject alternateCharacterPrefab;
after
public GameObject characterPrefab;
Now add
public bool alternativeCostume = false;
after
public string characterDescription;
Thats all on CharacterInfo.cs, now we can go to GlobalInfo.cs and do a minor change
add the variable
public ButtonPress altButton;
In the InputOptions class.
Now for easy use we are going to give us access to those variables throught the Edition window, to make that happen we are going to change CharacterEditorWindow.cs and add
characterInfo.alternateCharacterPrefab = (GameObject) EditorGUILayout.ObjectField("Character Alt Prefab:", characterInfo.alternateCharacterPrefab, typeof(UnityEngine.GameObject), true);
after
characterInfo.characterPrefab = (GameObject) EditorGUILayout.ObjectField("Character Prefab:", characterInfo.characterPrefab, typeof(UnityEngine.GameObject), true);
Now in GlobalEditorWindow.cs add
globalInfo.inputOptions.altButton = (ButtonPress) EditorGUILayout.EnumPopup("Alt Button:", globalInfo.inputOptions.altButton, enumStyle);
after this line
globalInfo.inputOptions.cancelButton = (ButtonPress) EditorGUILayout.EnumPopup("Cancel Button:", globalInfo.inputOptions.cancelButton, enumStyle);
after this if you go to the global editor window on Unity this new option will appear
And in the character editor will look like this
Now we can go to the last part of this simple tutorial and make the game chose the costume we want, as you can imagine, in the altButton option in the input options that you now have in your global editor you must choose a button that when pressed will set the option to load the alternateCharacterPrefab when the variable alternativeCostume is true, so after you add an alternate character prefab to your character and choose the button you want to use to select the alternate costume function we will write the rest of the code.
Now in controlsScript.cs in the start function after
if (myInfo.characterPrefab == null)
Debug.LogError("Character prefab for "+ gameObject.name +" not found. Make sure you have selected a prefab character in the Character Editor");
Add these lines
//JUST A DEBUG FOR CHECKING HOW IS WORKING ALL
Debug.Log ("ControlScript,Player:"+playerNum+"Alternate Costume Value:" + myInfo.alternativeCostume);
if (myInfo.alternativeCostume) {
if (myInfo.alternateCharacterPrefab == null)
{
character = (GameObject)Instantiate (myInfo.characterPrefab);
Debug.Log("Character prefab for "+ gameObject.name +"The Character Doesn't Have Alternate Costume. Make sure you have selected a prefab character in the Character Editor");
}
else
character = (GameObject)Instantiate (myInfo.alternateCharacterPrefab);
} else {
character = (GameObject)Instantiate (myInfo.characterPrefab);
}
As you can see, the code changes the default character loading behavior so if the alternativeCostume variable is true it will load the alternative prefab we added to the character info, in any case there were an error and the character doesn't have a alternate costume, the game will load the regular one, so you don't have to give al characters an alternative costume if you don't want.
Now in CharacterSelectionScreen.cs let's add this lines to the OnCharacterSelectionAllowed
after
if (character != null && character.selectionSound != null) UFE.PlaySound(character.selectionSound);
add this
if((player == 1 && this.p1AltCustom==true) || (player == 2 && this.p2AltCustom==true))
{
character.alternativeCostume=true;
}
else
{
character.alternativeCostume=false;
}
//I really like to send debugs
Debug.Log("Character Select,Player "+player+" alternate:"+character.alternativeCostume);
and after
protected int p2HoverIndex = 0;
You must add
protected bool p1AltCustom=false;
protected bool p2AltCustom=false;
The last bit of code is to be able to put in true or false the p1AltCustom or p2AltCustom, so in DefaultCharacterSelectionScreen.cs on the doFixedUpdate function after:
base.DoFixedUpdate();
just add:
if(p1InputController.GetButtonDown(UFE.config.inputOptions.altButton)){
this.p1AltCustom =!(this.p1AltCustom);
Debug.Log("Boton Alterno player 1:"+this.p1AltCustom);
//this.TrySelectCharacter(this.p1HoverIndex, 1);
}
if(p2InputController.GetButtonDown(UFE.config.inputOptions.altButton)){
this.p2AltCustom =!(this.p2AltCustom);
Debug.Log("Boton Alterno player 2:"+this.p2AltCustom);
//this.TrySelectCharacter(this.p1HoverIndex, 1);
}
So, that's all, you now can make alternate Costumes for your characters in the way the first Soul Blade or Tekken Worked, some warnings, I never added a little window or something on the character selection screen so it show the player if he/she es choosing the regular or alternate costume, I have had no time for it yet, if I make it I will add it to this post.
Second, I know and figured out that if we could change the alternateCharacterPrefab and characterPrefab to merge them in one characterPrefab[] (an array) and make some modifications to this code we can simply have infinity and variable alternate costumes for any character, like in Dead or Alive where the female characters have like 15 costumes and male characters have only 2, but I'll try it for the next game we make but if anyone wants to give a try just post it so everyone here can use it.
Last, the characters need to have the same bone structure, so the animations can run correctly, also you can add functionality so characters on alternate costumes can perform an alternate fighting intro animation, but I'm just talking nonsense.
Thank you and I hope anyone can use this options and doubts and complain are accepted by DM or twitter @seekerofpower
I only have this video from when I finished the script
https://www.facebook.com/seekerofpower/ … 8122777617
But I will ask mi brother if he can upload to youtube one nicer looking, sorry for my english