Part 2: Customize Menus

🚧

Have you read Part 1: Create Prefabs yet?

Before you start on Part 2: You need to have your structure prefab ready. Click the link on the left side of the documentation under Buildings called Part 1: Create Prefabs to follow those steps.

Part 2: Customize Menus

Continuing from Part 1: Create Prefabs, we will now edit the game menus in Unity to customize the existing menu sprite images for the structure and fill the store menu with ScriptableObject data. Part of this documentation will overlap with the documentation from the Store section.

The easiest way to get started understanding the kit is to customize the existing structures. So for this example we're going to replace the Dobbit Toolhouse sprite with the Schoolhouse sprite in the game menus.

3 Important Tips First...

🚧

Replace similar structures in the kit

For example, if you're doing a storage structure for resource #1, then replace the existing gold vault (storage structure) for resource #1 (gold). Ensure the storage structure prefab size is the same (design a storage structure that matches the object's existing grid size) and ensure that the ScriptableObject data you replace is the exact same one as before. This is because the ScriptableObject order, Prefab order, and game object names need to all match if you don't do any script changes.
Replace the name into the ScriptableObject for Buildings :

  • Economy Building --> (Assets/CityBuildingKit/Resources/Assets/BuildingsCategory.asset)
  • Military Building --> (Assets/CityBuildingKit/Resources/Assets/MilitaryCategory.asset)

Don't replace any random structure in the list unless you know what you're doing. If you switch prefabs for any random structure then strange performance or errors may occur for the script changes described in Part 3 that only advanced developers should do. Plus the ScriptableObject order won't match the prefab order anymore and you'll have text for other structures appearing on the wrong prefab item in the store.

And

🚧

Adding new structures to your game?

First, read the tip above. We highly recommend you replace similar structures first to understand how the kit works. Spend a couple weeks playing with the source code first before attempting to add new structures beyond the existing examples. Most importantly, you'll need to be comfortable with the GameManager Inspectors and scripts.

Each new structure you add in one of the Inspectors must also be added in the ScriptableObjects for buildings:

  • Economy Building --> (Assets/CityBuildingKit/Resources/Assets/BuildingsCategory.asset)
  • Military Building --> (Assets/CityBuildingKit/Resources/Assets/MilitaryCategory.asset)

Plus, you need to increment the arrays in the Creator Inspector like Grass Types (grid size grass colliders and grass prefabs to use), Construction Types (grid size construction prefab to use), Pivot Corrections (for odd/even grid size structures 1x1 and 3x3 / 2x2 and 4x4), Is Array (for field rows like walls rather than single structures), and Is Instant (for instant builds like the walls where ScriptableObject TimeToBuild is set to zero)

And also, the ScriptableObject order must match the exact same prefab order in these Creators.

Lastly, special coding changes are necessary as described in Part 3: Advanced Scripting Changes

And

🚧

Keep backups of the entire project

Before you edit structures - we recommend you make a backup copy of the entire project folder. This will help you revert to a previously working copy if something goes wrong in your changes.

1. Structure ScriptableObjects

All structure data is stored in the (Assets/CityBuildingKit/Resources/Assets/ folder. It's one of the ways we keep data centralized and easy to edit. The following table breaks down which structure file has which elements

Here's an excerpt from the Assets/CityBuildingKit/Resources/Assets/BuildingsCategory.asset Dobbit toolhouse item with comments we've added next to each item:

625
483

Sample store item. Click to view larger.

To update the store text to your structure, it's as easy as adjusting the text in the ScriptableObject asset like the title or the price.

For this page's example of customizing your structures in the game menus, we're going to leave the item name, description, and settings the same as the original dobbit toolhouse and only replace the prefab in the next step.

2. Shop Structure Graphic

To start, look in the screenshot below, the Dobbit Toolhouse building:

743

Dobbit toolhouse item in the store. Click to view larger.

If you want to change the image for the Dobbit Toolhouse, simply, go to the ScriptableObject for Buildings (Assets/CityBuildingKit/Resources/Assets/BuildingsCategory.asset), expand "Dobbit Toolhouse" from the list and change the value for the property "Id Of Big Icon" like the image below:

850 850

Play the game scene and open the Store > Resources panel. You'll see the updated prefab.

677

Click to view larger.

3. Update Structure Prefab

Once you've updated the structure sprite in the store - there's a couple more places we need to adjust in the kit so that structures in your home base use the new prefab.

  • For Resource Structure: Open the GameManager > Creators > BuildingCreator Inspector
  • For Military Structure: Open the GameManager > Creators > BuildingCreator Inspector
  • For Walls: Open the GameManager > Creators > WallCreator Inspector
  • For Defense Weapons: Open the GameManager > Creators > WeaponCreator Inspector
  • For Ambient Decorations: Open the GameManager > Creators > AmbientCreator Inspector

The below screenshots are from the BuildingCreator, but the other Creators use the same organization. This is the prefab the building creator uses when placing the structure from the store onto the map.

260

Click to view larger.

In the BuildingCreator Inspector, you'll see an array that matches the same list in the ScriptableObjects for Buildings (both two):

  • Economy Building --> (Assets/CityBuildingKit/Resources/Assets/BuildingsCategory.asset)
  • Military Building --> (Assets/CityBuildingKit/Resources/Assets/MilitaryCategory.asset)
    Since we're replacing the Dobbit toolhouse prefab, that's the first item in the BuildingsCategory.asset and the first element in this Structure Pf array (Pf stands for prefab).
273

Click to view larger.

Select the 00_Toolhouse prefab in the array. A Select GameObject window will open. Select a different prefab in this window. In this case we're using the 07_Classroom prefab already included in the kit, so we'll select that one.

496

Click to view larger.

Now that we've selected the 07_Classroom prefab, the Element 0 item in the Structure Pf array will show the prefab we've selected.

266

Click to view larger.

Also - if you need to change any special qualities about your structure like the grass prefab size, construction prefab size, pivot corrections, or change to an array field builder - you'll need to edit the corresponding Creator Inspector variables below.

🚧

Please make a backup first of your entire kit project!

We cannot stress this enough. As you work with a kit as big as this one, you'll revert to previous copies at least once. Regular backups save your work! It makes reverting changes easy if you make regular backups.

And spend a few weeks to understand the kit and how these settings work in the BaseCreator.cs script before you change the preset values. We highly recommend that you replace similar structures with the same special settings rather than try changing these values without understanding what or how they work in the scripts like BaseCreator.cs script among others.

Inspector Array ItemDescription
Grass TypesGrid size grass colliders and grass prefabs to use
Construction TypesGrid size construction prefab to use
Pivot CorrectionsFor odd/even grid size structures. Odd grid sizes like 1x1 or 3x3 need Pivot Correction set to true.
Is ArrayFor repeating field rows like walls set to true rather than single structures which is defaulted at false. Used by Verify() in BaseCreator.cs to choose the right Placement actions.
Is InstantFor instant builds like the walls where ScriptableObject TimeToBuild is set to zero. Used by BaseCreator.cs to choose the right Placement function.

Now run the scene in Unity. Go to the shop > IAP tab, click the 500 crystal pack to load up on crystal first. Then click the resources tab and buy the Dobbit toolhouse. You'll notice the prefab that appears in the game is now the prefab we've customized.

568

Where does my structure belong in this Inspector? Look at the following table for a list of the different structure types and which array they belong to in the SaveLoadBattle Inspector.

What should I do next?

To customize all of the buildings, we recommend you work with the existing samples included in the kit first. It's more straightforward to customize a resource building into a resource building rather than converting a resource building into a defense structure (rather, customize the defense buildings into new defense buildings)

There are a few specific changes necessary to do in the scripts for some ScriptableObject settings like Resource generation, resource storage, military unit storage, or builder huts. See the sections below...

Script changes for resource generator and storage builings...

If you would like to customize a resource structure - see the Buildings > Resource Generators or Resource Storage documentation which describes the scripts that disperse and store with resources. You'll need to make minor changes to the structure names in these scripts if you customize any of the existing prefabs or want to add more.

Script changes for unit storage structures...

If you would like to customize a military unit storage structure - see the Buildings > Military documentation which describes the small references in scripts you need to edit if you make changes to the structure names in these scripts if you customize any of the existing prefabs or want to add more.

Script changes for builder huts....

If you would like to add more structures like the dobbit builder tool house builder hut that expand the number of builders, see the Buildings > Builder Hut documentation for minor script changes you'll need to make.

What about adding more game structures?

To add additional structures to the kit, we recommend you first replace the existing samples. If you have more structures than we've provided as examples, continue the same the same naming conventions and design as the existing structures. But save this for later - first we recommend you get comfortable prototyping with the existing structure before attempting to add new structures. If you understand the fundamentals of how everything connects together - the rest is a breeze.

If you add new structures, please don't forget to update GameUnitsSettings.asset file. Read more info at Documentation > XML files VS ScriptableObjects