Day Five

We figured out a great way to help with game speed on the Wayfarer Games Discord server! Join below:

There’s now a base class with a bunch of helper methods, which makes handling game speed much easier to manage. However, there’s a new field on some 80 objects - it would be pain to have to manually assign every one. Luckily, this is where editor scripting comes in incredibly useful. Writing little tools like this can save hours of pain, if not dozens of hours on larger projects. In Unity, you can add [UnityEditor.MenuItem] to a static method, and it will appear in a nice little dropdown menu in the top bar. Here’s the code:

#if UNITY_EDITOR
[UnityEditor.MenuItem("Polyfury/Assign GameSpeed")]
public static void AssignGameSpeedFloat()
{
    var objects = FindObjectsOfType<BaseTimeSyncedObject>(true);
    var gameSpeed = Resources.FindObjectsOfTypeAll<GameSpeedFloat>().First();
    
    int count = 0;
    foreach (var o in objects)
    {
        if (o.gameSpeed == null)
        {
            o.gameSpeed = gameSpeed;
            Debug.Log("Adding GameSpeed to " + o.name);
        }
    }
}
#endif

As you can see, all I’m doing is grabbing all the BaseTimeSynced objects in the scene (the true parameter here just means “include inactive objects), then setting the gameSpeed field to the first GameSpeedFloat it finds in the project.

We use Unity’s Resources system here - this is actually one of the few uses where it’s actually okay to do so 😂 searching the whole project by a string is generally a bad idea, doing it by a Type is much quicker.

This little function is added to a menu item that appears like this:

You can see I’m using #if UNITY_EDITOR here to make sure this editor code isn’t included in the project build. Being comfortable with editor scripting in Unity can speed you up an awful lot, feel free to ask any questions you’ve got about tooling if you get stuck.

What’s next?

Oops, I’m still doing UI stuff sorry 😂 tomorrow I’ll sort the making balance tweaks for the Hexagon in preparation for the next round of testing, and talk about how I’m handling collision detection.


I hope you enjoyed reading about my Polyfury progress. If you have any questions or thoughts, please feel free to leave a comment below. Thanks for reading, and maybe check out the demo:

Making your own games? Check out Artificer Pro - released this month!

Previous
Previous

Day Six

Next
Next

Day Four