0

No products in the cart.

How InstLife Works

A quick ~behind the scenes~ look at how we develop InstLife.

Why?

We’ve had a few requests asking how we handle menu based gameplay within Unity, so here we are!

UIWidgets

The main force behind InstLife is a great asset called UIWidgets, this has been a life saver with it’s expanded UI elements – but more importantly it’s EasyLayout functionality.

This is great for auto spacing and padding your elements.

Check out a demo here. Store link here, which also reminds me that I need to rate this asset…

Changing Screens

Each page is its own GameObject, with all relevant UI for this page as children to this GameObject.

I have created a MenuManager script which controls which GameObjects (pages) should be displayed dependant on what page you have selected.

We also have page specific scripts that initiate when the new page has been enabled. One example of this is job history. I don’t want this updating when we’re not looking at it. Only update this page when it is enabled by the player.

I don’t know if this is best practise, but it works.

Handling The World

In the game world we have the player, obviously, but we also generate GameObjects for people like potential partners, your parents, company CEOs, burglars etc.

Each ‘person’ is sent through the game’s WorldHandler script. This script updates their health, education, their outgoings, manages their job life (gets them a new job, or finds one if they’re unemployed), all that kind of stuff.

        // Sim every person in the game world
        Person[] people = Object.FindObjectsOfType<Person>();
        foreach (Person p in people)
        {
            if (p.alive) // Make sure they're alive, a dead guy can't pay bills
            {
                updatePerson(p); // Send the alive person we've found through the cycle
            }
        }

Most of the time the player will go through the same cycle except for careers and events as they only directly affect the player.

Triggering Events

So, after we have sent our player through the cycle of having their salary paid, health updated etc. we then hit them with events! If they’re still alive that is.

Each ‘module’ of the game has its own handler script.

This allows me to have a master function for each module that decides if a random event has been selected, and if it has – are the conditions met for the player to experience this event?

            else if (randomEventChooser == 3) // burglary
            {
                if (player.houses.Count > 0)
                {
                    if (player.bankBalance > 0 || player.currentJob.annualSalary >= player.CountryLivingIn.avgCountryIncome || player.famous)
                    {
                        Burglary();
                    }
                }
            }

Once all of these events are out the way, the player can then begin their year and decide what to do for themselves.

Again. I don’t know if this is best practise, but it works.

Summary

I hope this write up has been useful, I’ve never really done anything like this before.

Any feedback would be great – even if you’re telling me how bad my code examples are.

Comments

  • Syaz Amirin

    July 17, 2017 at 5:00 pm

    Wow! Really nice!

  • PanFist

    July 17, 2017 at 5:00 pm

    It’d be nice if you made a plugin spot where we could make our own plug-ins

Your email address will not be published.