General information

Date completed May 2019
Role in team Solo project, Developer
Environment Unity 2018.2.10f1
Language C#

Description

The SkillTool is a tool I developed for one of the core module lessons at the university I attend. The function of the tool is to make the ability creation process for game designers easier. I wanted to make it possible to create simple skill behaviour without having to do any programming whatsoever, while still giving the user as much control on what the skill does as possible. Here you can see an example of about half of the information that the user can change according to their preferences.

I’m not too happy about the visual design, so that would be my first priority in a next iteration

Reflection

One of the biggest challenges for creating this tool was learning about reflection in C#. I wanted my users to be able to change variables from their scripts, without having to do any writing in a script. To do this, I had to display and edit variables, both public and private, from any script they might want to change. A teacher let me know reflection is most likely the way to go for such a project.

I had no prior knowledge of reflection, so I had to do quite a bit of research. Luckily, there was a lot of material online about the use of reflection, and with a bit of Googling I quickly started learning about all the possible functionalities.

By the end of the project, I had applied all of my knowledge on reflection in such a way that a user could select ANY script they would like, and my program would automatically find all the variables and display them. The user could then choose any of these variables and set them, add to them or subtract from them as much as they’d like. The user could also choose to simply run a method in the target script or destroy the entire gameobject.

    /// <summary>
    /// Goes through the possible effects a skill can have and enables those that have been chosen by the user
    /// </summary>
    /// 
    /// 
    private void DoEffect(GameObject go, Skill skill) {
        switch(skill.effectOptionsChoice) {
            //If a variable needs to be changed in the script
            case 0:
                var script = go.GetComponent(skill.selectedScript.name);
                var type = GetType(skill.selectedScript.name);
                var fields = type.GetFields();

                FieldInfo field = script.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)[skill.fieldChosenChoice];

                switch (skill.variableChangeChoice) {
                    //If the variable is set
                    case 0:
                        if (field.GetValue(script) is float) {
                            field.SetValue(script, skill.fieldValueFloat);
                        }
                        else if (field.GetValue(script) is int) {
                            field.SetValue(script, skill.fieldValueInt);
                        }
                        if (field.GetValue(script) is double) {
                            field.SetValue(script, skill.fieldValueDouble);
                        }
                        field.SetValue(script, skill.fieldValue);
                        break;

Final product

While there are many iterations to be made when it comes to visual design and usability, I am quite content with the functionality of the tool. I added a video tutorial on how my tool can be used and made a user flow diagram to show my teacher what the creation process looks like.

User flow diagram