Skip to content

Map Scripting

SqueegeeDinoToy edited this page Sep 26, 2020 · 15 revisions

Table of Contents

Welcome

This guide will cover the introduction of setting up scripts on your Skater XL maps, that will then function in game. Although this is not directly supported in the games default map importer, both the XL Menu Mod and Map Patch mod allow us to use custom scripts in our maps. Although it may take a short while to become familiar with this process, the possibilities are quite literally endless with map scripts, and the surface has only barely been scratched so far with what can be accomplished.

Getting Started

For this example, we will be making a script that opens and closes a UI menu. Even a script as simple as this can allow us to do very powerful things, as utilizing Unity's UI system alone opens up a large amount of possibilities. As you can see in the example below, I've started off by just creating a button. We will use a script to toggle this button on and off. (This is not a guide on using Unity's UI system, please refer to official Unity documentation or other online tutorials for this information.)

image

To set up any scripts for mapping, we need to install Visual Studio, which can be found here. Go through the installation process as you would normally for any program. When prompted with the screen asking what packages to install, select .Net desktop development (and check Game Development with Unity too, because why not.)

image

Setting Up the VS Project

Once VS is installed, create a new project

image

We want to create a Class Library (.NET Framework) in C#

image

DO NOT use Class Library (.NET Standard)

You can name your project anything you'd like, although something at least similar to your map is wise. You can save this to anywhere on your computer.

image

Before writing any code, it's important to set up the references we need. This is how we can tell VS what code from Unity's engine we will be using. Expand the References dropdown on the right side of the screen, right click, and select Add Reference.

image

Click the Browse button, and navigate to your SXL install folder. Then go to Skater XL > SkaterXL_Data > Managed, this is where we will find the Unity engine DLLs that we will want to reference.

image

You can also reference the DLLs directly from where your Unity is installed as well, but I find it best to reference the exact same files that SXL is referencing. This can help in case the game updates what engine version it uses.

For this simple script, all we need to reference is UnityEngine.dll, UnityEngine.CoreModule.dll, and UnityEngine.InputLegacyModule. It is likely that with more complex scripts, you will need to reference other Unity API. Please refer to the Unity Manual for more API information.

image

It is generally bad practice, and bloats our project, to go through referencing everything in sight. We recommend only referencing what is needed

Be sure to go to the references you add, and select the Copy Local dropdown, and set this value to False to prevent VS from copying these DLL files over to the build path.

image

It's very annoying when you forget to do this...not that I've ever accidentally built all of the Unity DLLs back to Unity...

Next we can set up our build settings to build straight to the Unity project when we are ready. In the top bar open the Project dropdown, then at the bottom select [ProjectName] Properties. Press Ctrl + S when done adjusting these settings to save changes to the project properties.

image

In the Build tab, change the Configuration to Release. Then set the Output Path to the desired location in your Unity project.

image

Creating a Basic Script

Our script is going to be called MenuManager, so lets go ahead and rename the class on the right to reflect that.

image

You can create a new class (or script to be compiled into our DLL by going to Project > Add Class

The Script

using UnityEngine;

public class MenuManager : MonoBehaviour
{
    // This creates an input field in our component where you add your menu GameObject to toggle on and off
    public GameObject optionsMenu;

    // At step zero, disable the optionsMenu and hide the mouse cursor
    private void Awake()
    {
        optionsMenu.SetActive(false);
        Cursor.visible = (false);
    }

    // Update is called once per frame
    void Update()
    {
        // Every frame, check to see if F8 is pressed. If F8 is pressed, execute the function within this statement
        if (Input.GetKeyDown(KeyCode.F8))
        {
            // Checks the current active state of the optionsMenu GameObject.
            // If it is active, it gets deactivated, the mouse is hidden and also locked.
            // If it is inactive, it gets activated, and the mouse is unhidded and unlocked.
            if (optionsMenu.activeSelf)
            {
                optionsMenu.SetActive(false);
                Cursor.visible = false;
                Cursor.lockState = CursorLockMode.Locked;
            }
            else
            {
                optionsMenu.SetActive(true);
                Cursor.visible = true;
                Cursor.lockState = CursorLockMode.None;
            }
        }
    }
}

This is not a C# or coding in Unity lesson. To learn more about writing more complex scripts for your maps, google it

Now that our code is written, press Ctrl + Shift + S to save all in the project. Then swap the build mode from Debug to Release

image

Next, go to the Build dropdown menu, and select Build Solution (or press F6.) This will take a moment, and upon completion should say Build Succeeded at the bottom of the window.

Applying the Script in Unity

After building our script out in VS, we can now go back to Unity and put this into action. In Unity, your scripts are now built out into a DLL file. We can click the arrow button on the right of the icon to expand it and see all the classes compiled into the DLL.

image

Create a new Empty in the hierarchy, this will act as our master object hosting our map scripts. Then simply drag and drop the class from the expanded DLL file into the components field of the master objects inspector.

image

Now we can add our Button (the object to be toggled on/off with F8) to the Options Menu public field.

image

Once this has all been set up, we can actually test our script quickly in the editor before going to SXL. Simply enter play mode and press F8 to toggle the button on and off!

image

Sharing and SXL

Once you have set all this up, getting it into game is simply a matter of copying our map file and the DLL to our Maps folder. The only caveat being that the DLL must have the exact same name as the map file. As long as one of the above mentioned mods is installed, the game will load up the appropriate DLL for the map, and allow the scripts to function in game.

Please keep in mind that this wiki is constantly under development. If you are looking for something in particular, feel free to ask!

Clone this wiki locally