Topic: Questions about CSS Coding

So I figure I'd attempt to add costume selection to my project manually, but I'm not sure how to start. I'm using UFE 2.3 Source, and I have 2 ideas on how I want to implement this features, but I'm having a hard time figuring out what line of code does what. I know it involves the default CSS script, but I don't know what to do with it. My questions are these:

1. What lines in the character select script controls the actual selection of characters? If I know that, then I could maybe add on to that part of the script.

2. Say I decide to just create a new CSS. Would I need the default CSS script, or could I use a custom script, and if I can use a custom script, what UFE functions would I need to incorporate?

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

You can use a custom script as long as it inherits from CharacterSelectionScreen

public class MyCustomCharacterSelectScreen : CharacterSelectionScreen {

}

from there you're free to override any of the methods used within CharacterSelectionScreen as you see fit.

You'll find character selection in the OnCharacterSelectionAllowed method. In there, you can follow the comments for each block of code. I'd recommend just copying the method and pasting it in your custom select screen, replacing virtual with override.

public override void OnCharacterSelectionAllowed(int character Index, int player) {

}

But in short, I'd change the this.GoToNextScreen() to some new method that is something like this.StartCostumeSelection() if you're having the user select costume on the same screen, or otherwise if its on a new screen then just alter the Next Screen to be the costume select screen. Most typically, you'd be on the same screen, so it's just best to update/add an if check that doesn't go to next screen until the costume has been selected.

In terms of handling costume selection, there's no one way to do that, but I'd recommend starting with displaying a panel that renders an option for each costume type in an array for the selected character. Then making it so directional changes change the highlighted option, and pressing Button1 selects that outfit array. Then you can store which outfit was selected and use that to help set the player character and its set costume option.

Share

Thumbs up +2 Thumbs down

Re: Questions about CSS Coding

MrPonton wrote:

You can use a custom script as long as it inherits from CharacterSelectionScreen

public class MyCustomCharacterSelectScreen : CharacterSelectionScreen {

}

from there you're free to override any of the methods used within CharacterSelectionScreen as you see fit.

You'll find character selection in the OnCharacterSelectionAllowed method. In there, you can follow the comments for each block of code. I'd recommend just copying the method and pasting it in your custom select screen, replacing virtual with override.

public override void OnCharacterSelectionAllowed(int character Index, int player) {

}

But in short, I'd change the this.GoToNextScreen() to some new method that is something like this.StartCostumeSelection() if you're having the user select costume on the same screen, or otherwise if its on a new screen then just alter the Next Screen to be the costume select screen. Most typically, you'd be on the same screen, so it's just best to update/add an if check that doesn't go to next screen until the costume has been selected.

In terms of handling costume selection, there's no one way to do that, but I'd recommend starting with displaying a panel that renders an option for each costume type in an array for the selected character. Then making it so directional changes change the highlighted option, and pressing Button1 selects that outfit array. Then you can store which outfit was selected and use that to help set the player character and its set costume option.


I see. Thanks for the help!

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

MrPonton wrote:

In terms of handling costume selection, there's no one way to do that, but I'd recommend starting with displaying a panel that renders an option for each costume type in an array for the selected character. Then making it so directional changes change the highlighted option, and pressing Button1 selects that outfit array. Then you can store which outfit was selected and use that to help set the player character and its set costume option.

I'm interested in having a costume selection screen like MrPonton suggested. Would be cool to see a tutorial writeup since costume selection screen are a very common feature in fighting games. Could even add the modified CSS script and any other scripts needed to support it to the community scripts as a template to help get people started with it.
https://i.imgur.com/3V1JUxw.png

I'd be willing to commission MrPonton or someone else for taking the time to setup the scripts needed to make this work. Just PM me or reply here if interested.

Share

Thumbs up +4 Thumbs down

Re: Questions about CSS Coding

FreedTerror wrote:
MrPonton wrote:

In terms of handling costume selection, there's no one way to do that, but I'd recommend starting with displaying a panel that renders an option for each costume type in an array for the selected character. Then making it so directional changes change the highlighted option, and pressing Button1 selects that outfit array. Then you can store which outfit was selected and use that to help set the player character and its set costume option.

I'm interested in having a costume selection screen like MrPonton suggested. Would be cool to see a tutorial writeup since costume selection screen are a very common feature in fighting games. Could even add the modified CSS script and any other scripts needed to support it to the community scripts as a template to help get people started with it.
https://i.imgur.com/3V1JUxw.png

I'd be willing to commission MrPonton or someone else for taking the time to setup the scripts needed to make this work. Just PM me or reply here if interested.

I'm currently trying to figure it out with the posts above as a sort of guide, but definitely agree. A tutorial would be great, especially since costume selection is a pretty essential feature in most fighting games.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

I was also trying to figure this out, have you made any progress @GriffinSTatum?
Was looking at the DefaultCharacterSelectionScreen and saw a color change code but it gives errors when uncommented.
https://i.imgur.com/rE5t2gY.png
We just need a demo menu to help us all get started

Share

Thumbs up Thumbs down

7 (edited by GriffinSTatum 2021-06-12 16:23:00)

Re: Questions about CSS Coding

FreedTerror wrote:

I was also trying to figure this out, have you made any progress @GriffinSTatum?
Was looking at the DefaultCharacterSelectionScreen and saw a color change code but it gives errors when uncommented.
https://i.imgur.com/rE5t2gY.png
We just need a demo menu to help us all get started

I haven't figured it out unfortunately.

My current solution was to add Character Files inside of Character Files. I then also added a public integer to allow for someone to enter how many costumes the character has. By doing this, in the OnCharacterSelectionAllowed method, I added a check to see if the character has more than one costume(by checking that public integer), and if so, it then goes into the Character File and loads those as the selectable characters rather than the ones in the Global Editor.

Character Files inside a Character File

The main issue I'm currently running into is getting the Character Selection to switch from the ones in the Global Editor to the ones in the Character File. Once I figure that out, I think it'll be easy from there.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

Nice keep us posted with your progress

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

My brother did our alternate costume code a few years back, maybe it can come in handy.

http://www.ufe3d.com/forum/viewtopic.php?id=776

Me encontraste en un negro camino como un peregrino sin rumbo ni fe, pero la luz de tus ojos divinos cambió mi suerte por dicha y placer.

Re: Questions about CSS Coding

Thanks @StriderSpinel. I'll try it out in a blank ufe project and see if it works. I'll keep you all posted with results.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

StriderSpinel wrote:

My brother did our alternate costume code a few years back, maybe it can come in handy.

http://www.ufe3d.com/forum/viewtopic.php?id=776

Thanks for the link! I was able to follow it until the very end, I am getting this compile error:

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

Any suggestions?

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

So, I've been trying to work out my own solution to this, and I think I'm close, but I'm a bit stuck.

So for starters, I decided to build a new CSS from the ground up, and so far I've gotten to the point where the game will recognize a character is selected. With how I've set up the CSS, each of the small portraits contain two sets of lists: A list containing alternate costumes, and lists inside of those lists containing each variation of those costumes. The reason I did it like this is to support an idea that came to me while looking at GriffinSTatum's solution. I realized that, so long as the individual models aren't too large, in theory I could make copies of the base character, and just replace each prefab with the corresponding costume, and since they would all pull from the same movelist, it wouldn't take up too much info to just copy the character info files.

So at this point I'm able to create the list of costumes, then create sublists that contain the different costume palettes, and within the sub list are character info files. Where I'm stuck at is actually displaying this list in game. What I want to do is have the player cycle through a list of costumes when selecting a character. Then when the costume is selected, they would then select the color. Once, they do that, the corresponding info file will be applied to the player who selected it.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

https://i.ibb.co/NpqHzDx/Solution-A.png
image post

Here's an image to show where I'm at now.

Share

Thumbs up +1 Thumbs down

Re: Questions about CSS Coding

So I think I'm closer to figuring this out, I just need to know one more bit of info and I should be good. I want to set the character data to the corresponding player when they've finalized their selection. I would like to know if there's a way to use UFE.SetPlayer1(CharacterInfo player1) for this. I want to get the character info data from the menu object, and apply it to P1, for example, however I get error when trying to do so. Is there a different function to use, or am I not using this one right?

Share

Thumbs up Thumbs down

15 (edited by GriffinSTatum 2021-07-28 15:07:31)

Re: Questions about CSS Coding

RetroX wrote:

So I think I'm closer to figuring this out, I just need to know one more bit of info and I should be good. I want to set the character data to the corresponding player when they've finalized their selection. I would like to know if there's a way to use UFE.SetPlayer1(CharacterInfo player1) for this. I want to get the character info data from the menu object, and apply it to P1, for example, however I get error when trying to do so. Is there a different function to use, or am I not using this one right?

Have you tried using UFE.SetPlayer(int player, UFE3D.CharacterInfo info)

That's what the base CSS script uses, whereas UFE.SetPlayer1 and UFE.SetPlayer2 are used to make the player entries null on entering the CSS.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

GriffinSTatum wrote:
RetroX wrote:

So I think I'm closer to figuring this out, I just need to know one more bit of info and I should be good. I want to set the character data to the corresponding player when they've finalized their selection. I would like to know if there's a way to use UFE.SetPlayer1(CharacterInfo player1) for this. I want to get the character info data from the menu object, and apply it to P1, for example, however I get error when trying to do so. Is there a different function to use, or am I not using this one right?

Have you tried using UFE.SetPlayer(int player, UFE3D.CharacterInfo info)

That's what the base CSS script uses, whereas UFE.SetPlayer1 and UFE.SetPlayer2 are used to make the player entries null on entering the CSS.


Tried that. I got errors when I tried to use it.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

I get this error when I attempt to select the character

NullReferenceException: Object reference not set to an instance of an object

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

So I managed to find a way to get my own Costume Selection to work, I had to hard code it though. I made quite a few changes, so I'll compile all the stuff I did and post it here as well as the reasonings why I made the changes. But for now, here's a video of it working in my project. I was dropping frames, probably because I was running Unity, OBS and a moving background for my CSS.

https://www.youtube.com/watch?v=GOeUg6a … ffinSTatum

Share

Thumbs up +1 Thumbs down

Re: Questions about CSS Coding

@GriffinStatum in this thread http://www.ufe3d.com/forum/viewtopic.php?id=776 did you look at the last post it has a fix for 'AbstractInputController' error you got. I still haven't got around to testing out the code in that thread.

Share

Thumbs up Thumbs down

20 (edited by GriffinSTatum 2021-08-06 23:42:50)

Re: Questions about CSS Coding

Here was my process in getting it to work. I had to use my own method because it made the most sense to me, hopefully anyone reading this can use something from this for themselves, although since it's hardcoded it won't be specifically applicable to anyone else's project.

FreedTerror wrote:

@GriffinStatum in this thread http://www.ufe3d.com/forum/viewtopic.php?id=776 did you look at the last post it has a fix for 'AbstractInputController' error you got. I still haven't got around to testing out the code in that thread.

I completely avoided that way of implementing the costumes, so I never had to deal with the AbstractInputController, fortunately.

The first extension I made was in CharacterInfo.cs. I added

public Texture2D profilePictureCostume;

after

public Texture2D profilePictureBig;

Then I went over to CharacterEditorWindow.cs and added

EditorGUIUtility.labelWidth = 180;
EditorGUILayout.LabelField("Portrait Costume Big:");
characterInfo.profilePictureCostume = Texture2D)EditorGUILayout.ObjectField(characterInfo.profilePictureCostume, typeof(Texture2D), false);
EditorGUILayout.Space();

after

EditorGUIUtility.labelWidth = 180;
EditorGUILayout.LabelField("Portrait Big:");
characterInfo.profilePictureBig = (Texture2D) EditorGUILayout.ObjectField(characterInfo.profilePictureBig, typeof(Texture2D), false);
EditorGUILayout.Space();

This allowed me to add the Texture for the selection(such as the one below) to the character file.

https://i.imgur.com/2jmjrBc.png
https://i.imgur.com/TnoFkWE.png

Before we get into the Character Selection Screen, I want to explain that I had a Character.asset file for each individual costume, plus an additional character file for the Character Selection Screen. I have a total of 73 Character.asset files while my CSS holds 35 total characters.

https://i.imgur.com/nXNY4Ml.png

For this method as well, you will need to know how many costumes each character has and which value that specific character takes on the CSS.

To make it simple, I will use my first character, Medaka. She is the first selectable character on the CSS, and her index value is 0.

In DefaultCharacterSelectionScreenEditor.cs I added the lines

EditorGUILayout.PropertyField(this.serializedObject.FindProperty("costumePlayer1"));        EditorGUILayout.PropertyField(this.serializedObject.FindProperty("costumePlayer2"));

after

EditorGUILayout.PropertyField(this.serializedObject.FindProperty("portraitPlayer1"));            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("portraitPlayer2"));

Now in DefaultCharacterSelectionScreen.cs, add

public Image costumePlayer1;
public Image costumePlayer2;

after

public Image portraitPlayer1;
public Image portraitPlayer2;

Scroll down and then once you find:

if (this.displayMode == DisplayMode.CharacterPortrait){
                        if (this.portraitPlayer1 != null){
                            this.portraitPlayer1.sprite = Sprite.Create(
                                character.profilePictureBig,
                                new Rect(0f, 0f, character.profilePictureBig.width, character.profilePictureBig.height),
                                new Vector2(0.5f * character.profilePictureBig.width, 0.5f *                 character.profilePictureBig.height)
        );
    }
}

Update the code so it looks like the following:

if (this.displayMode == DisplayMode.CharacterPortrait){
                        if (this.portraitPlayer1 != null){
                            this.portraitPlayer1.sprite = Sprite.Create(
                                character.profilePictureBig,
                                new Rect(0f, 0f, character.profilePictureBig.width, character.profilePictureBig.height),
                                new Vector2(0.5f * character.profilePictureBig.width, 0.5f * character.profilePictureBig.height)
                            );
                        }
                        if (this.costumePlayer1 != null)
                        {
                            this.costumePlayer1.sprite = Sprite.Create(
                                character.profilePictureCostume,
                                new Rect(0f, 0f, character.profilePictureCostume.width, character.profilePictureCostume.height),
                                new Vector2(0.5f * character.profilePictureCostume.width, 0.5f * character.profilePictureCostume.height)
                            );
                        }
                    }

You will do the same for the player 2 version of the Code a little further down:

if (this.displayMode == DisplayMode.CharacterPortrait){
                        if (this.portraitPlayer2 != null){
                            this.portraitPlayer2.sprite = Sprite.Create(
                                character.profilePictureBig,
                                new Rect(0f, 0f, character.profilePictureBig.width, character.profilePictureBig.height),
                                new Vector2(0.5f * character.profilePictureBig.width, 0.5f * character.profilePictureBig.height)
                            );
                        }
                        if (this.costumePlayer2 != null)
                        {
                            this.costumePlayer2.sprite = Sprite.Create(
                                character.profilePictureCostume,
                                new Rect(0f, 0f, character.profilePictureCostume.width, character.profilePictureCostume.height),
                                new Vector2(0.5f * character.profilePictureCostume.width, 0.5f * character.profilePictureCostume.height)
                            );
                        }
                    }

Now under the public override void OnShow(){ function, you will have to update the end of the function to look like this:

this.SetHoverIndex(1, Mathf.Clamp(this.defaultCharacterPlayer1, 0, this.selectableCharacters.Length - 1));
        if (UFE.gameMode == GameMode.StoryMode){
            if (this.namePlayer2 != null){
                this.namePlayer2.text = "???";
            }

            if (this.portraitPlayer2 != null){
                this.portraitPlayer2.gameObject.SetActive(false);
            }

            if (this.costumePlayer2 != null){
                this.costumePlayer2.gameObject.SetActive(false);
            }

            this.UpdateHud();
        }else{
            this.SetHoverIndex(2, Mathf.Clamp(this.defaultCharacterPlayer2, 0, this.selectableCharacters.Length - 1));

            if (this.portraitPlayer2 != null){
                this.portraitPlayer2.gameObject.SetActive(true);
            }

            if (this.costumePlayer2 != null)
            {
                this.costumePlayer2.gameObject.SetActive(true);
            }
        }

These lines of code allows us to have these options in the CSS Editor Window

https://i.imgur.com/Mw3o5sU.png

Now in the final script we'll be editing, CharacterSelectionScreen.cs, under the OnCharacterSelectionAllowed(int characterIndex, int player) function, we will add the following code:

if (characterIndex == 0) //Medaka
                    {
                        if (player == 1)
                        {
                            UFE.SetPlayer1(null);
                            this.SetHoverIndex(1, 35);
                        }
                        else if (player == 2)
                        {
                            UFE.SetPlayer2(null);
                            this.SetHoverIndex(2, 35);
                        }
                    }

After

this.SetHoverIndex(player, characterIndex);
                    UFE3D.CharacterInfo character = this.selectableCharacters[characterIndex];
                    if (this.selectSound != null) UFE.PlaySound(this.selectSound);
                    if (character != null && character.selectionSound != null) UFE.PlaySound(character.selectionSound);

Now, as I said previously, this is hardcoded and character specific. The reason why I have Medaka's hover index set to 35 is because 35-40 are the values which I have set all 6 of Medaka's other character files at. You will have to replace the number 35 with whatever number your character's costume starts at.

You also need to make sure

UFE.SetPlayer(player, character);

is enclosed in an else statement, like so:

else
    UFE.SetPlayer(player, character);

This is to make sure that it doesn't automatically select the first costume that you set the hover index to.

Now under public void TryDeselectCharacter(int player), add

if (this.GetHoverIndex(player) >= 35 && this.GetHoverIndex(player) <= 40) //Medaka's Costumes
        {
            this.SetHoverIndex(player, 0);
        }

to the beginning of the function. This will place the player back to hovering Character 0(Medaka). Then at the end, alter the code to include an else statement:

else
    this.TrySelectCharacter(-1, player);

as we don't want the player to exit to the main menu immediately after exiting the costume selection process.

Finally, under public override void OnShow(), we will change the final line of the function

this.SetHoverIndex(2, this.GetMaxCharacterIndex());

to

this.SetHoverIndex(2, 34);

to ensure the second player is hovering the main CSS.

Now that we are all done with coding, we go over to the Unity Project and open up the CSS prefab. Duplicate the Portrait_Player1 and Portrait_Player2 GameObjects and rename them to Costume_Player1 and Costume_Player2 respectively.

https://i.imgur.com/UbZVMNp.png

Now drag those panels over into the CSS Editor window, so they populate the corresponding options:

https://i.imgur.com/GCZt3Ur.png

Now you want to set up the button inputs manually. Get all the Character Buttons organized on the CSS as you want and manually set up the buttons. It is tedious, but worth it.

https://i.imgur.com/ua9AwAt.png

Now that you have the paths of the buttons all set up, you will do something similar with the costume selection. Move the Buttons for the costumes(in my case 35 and on) outside of the camera bounds, but still within the "Selectable Characters" GameObject's bounds. This will make it so the Player cursor doesn't hover randomly around the CSS when selecting costumes.

https://i.imgur.com/3YCwvdq.png

The process for setting up the costume buttons is fairly straight forward. Much like the regular CSS, you will want to manually set up the button mapping, this way it only loops within the specific character's costumes. Since Medaka's costume values are 35-40, I have set it up so they only cycle through those specific buttons.

https://i.imgur.com/QBIMMcX.png

Now at the beginning of the post I said that I set up character files dependent on the number of costumes a character had +1. This is more of an aesthetic thing, so you don't have to have the +1 if you really don't want to.

Essentially, in Character slot 0, I have this Medaka:
https://i.imgur.com/aspQY2w.png

The only difference between this Medaka and Medaka in Character Slot 35 is the "Portrait Costume Big" sprite
https://i.imgur.com/TnoFkWE.png

This way, when hovering over slot 0, there is no "Costume Selection UI" on screen, as the sprite is completely transparent. Once the player selects on Character 0, it then sets the hover to 35 and presents the "Costume Selection UI".

The end result is the video I posted before.

I know this post is really long, but I hope this helps someone. If you have any other questions I'll try to answer them as best as possible.

Share

Thumbs up +1 Thumbs down

Re: Questions about CSS Coding

So I finally figured out the issue I was having with setting Player 1 and 2 as the character. Turns out I had to actually put the CSS in UFE itself for it to work (I was using a separate scene to test out the functionality). The solution I came up with is complete, I just need to redo it in a cleaner project, since there was a lot of trial an error with this one. When I do that, I'll share the steps here with you all.

Share

Thumbs up +1 Thumbs down

Re: Questions about CSS Coding

GriffinSTatum wrote:

I haven't figured it out unfortunately.

My current solution was to add Character Files inside of Character Files. I then also added a public integer to allow for someone to enter how many costumes the character has. By doing this, in the OnCharacterSelectionAllowed method, I added a check to see if the character has more than one costume(by checking that public integer), and if so, it then goes into the Character File and loads those as the selectable characters rather than the ones in the Global Editor.

Character Files inside a Character File

The main issue I'm currently running into is getting the Character Selection to switch from the ones in the Global Editor to the ones in the Character File. Once I figure that out, I think it'll be easy from there.

I'm looking to load in characters to the character files, I can't quite figure it out. Since you've already done it, can you share what you did to get it to work? I'm getting some odd errors.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

Starcutter wrote:
GriffinSTatum wrote:

I haven't figured it out unfortunately.

My current solution was to add Character Files inside of Character Files. I then also added a public integer to allow for someone to enter how many costumes the character has. By doing this, in the OnCharacterSelectionAllowed method, I added a check to see if the character has more than one costume(by checking that public integer), and if so, it then goes into the Character File and loads those as the selectable characters rather than the ones in the Global Editor.

Character Files inside a Character File

The main issue I'm currently running into is getting the Character Selection to switch from the ones in the Global Editor to the ones in the Character File. Once I figure that out, I think it'll be easy from there.

I'm looking to load in characters to the character files, I can't quite figure it out. Since you've already done it, can you share what you did to get it to work? I'm getting some odd errors.

I was getting too many errors that way as well, so I had to change the way I approached costume selection and ended up with this: http://www.ufe3d.com/forum/viewtopic.ph … 129#p11129

It's hard coded, so not exactly apples-to-apples to your project, but hopefully it helps get you set up.

Share

Thumbs up Thumbs down

Re: Questions about CSS Coding

GriffinSTatum wrote:

I was getting too many errors that way as well, so I had to change the way I approached costume selection and ended up with this: http://www.ufe3d.com/forum/viewtopic.ph … 129#p11129

It's hard coded, so not exactly apples-to-apples to your project, but hopefully it helps get you set up.

Thanks! I ended up figuring it out myself somehow, everything works the way I wanted on the character select screen.

That said, for some reason after all that the cursor placement on the main menu screen doesn't work anymore??? I have no idea how that happened but at least my CSS functions hahaha. I'm sure I'll figure that out eventually

Share

Thumbs up Thumbs down