Ambient Decorations

👍

Reminder - Keep Daily Backups

When working on a strategy game with a kit as big as the Complete Kit - always keep a working daily backup! Save yourself the trouble of rolling-back changes and losing work.

All types of structures in the City Building Kit documentation pages are actually controlled by a single multi-functional StructureCreator. It builds anything, different prefabs and XML descriptors; this includes array-builds, for walls and fences, instant builds (without construction sequence) and whatever you can dream up for your game.

What are decorations?

The City Building Kit includes decorations which are called ambient objects. These are objects the player can construct which offer no value other than aesthetically pleasing images - like a flag or a tree. These objects you can place around your city or village to decorate your base.

Most free-to-play strategy games include them as they not only provide players with a way to spend excess resources but also customize their base (increasing return value for recurring players)

The following screenshot shows 3 different examples, a flag, a flower, and a tree - that are included in the City Building Kit. You can customize these objects with your own or remove the ambient menu all together if you would not like to have decorations in your game.

The following page talks about how ambient objects are done.

677

Decorations examples. Click to view larger

Decoration Store

In the UIAnchor - center main store item, you'll find the walls element which contains everything you see in the below screenshot.

746

Ambient object store. Click to view closer.

Where to find the decoration store menu in Unity?

Open the game scene hierarchy and locate the ScrollViewAmbient in UIAnchor > Anchor - Center > Shop > Main. Look at the below screenshot.

270

UIAnchor. Click to view larger.

Where are the prefabs?

All of the game object prefabs are set in the Game scene Game manager. Look at the below screenshots:

275

Game scene Game Manager > SaveLoadMap

273

Inspector Ambient prefabs. Click to view closer.

In addition, you will want to look at GameManager > Creators > AmbientCreator (prefabs are also there) and Map01 scene GameManager > SaveLoadBattle. This is discussed in the Buildings > Part 2: Customize Menus section of the documentation. Prefabs are used by the creator for construction and by SaveLoadBattle for loading during battle.

GameManager > Creators > AmbientCreator

The Game scene GameManager > Creators > AmbientCreator has all of the prefabs and their corresponding settings.

273

Game scene Game Manager

358

Ambient prefabs in the AmbientCreator Inspector

In the Inspector you'll notice a few arrays, here's a description of each one. It's the same for every type of game object you can build in the game except for the RemovableCreator (removables are not for players to construct but rather remove -- see Player Removable Objects doc for details)

Array TitleDescription
Structure PfThe structure prefab. Order in this list matches the exact order of the XML items which the Creator matches the prefab with.
Grass Pf1x1 to 5x5 dark green grass collider grid prefabs list. These you don't have to edit, they are shared by all structures in the game based on their grid size.
Construction PfUnder construction prefab list. There's 3 different sizes of this for 1x1 to 3x3 grid size construction projects.
Grass TypesSize of this array matches the the Structure Pf array size. We tell which Grass Pf element to use with each structure. Depends on structure size whether they take 1x1 (Grass Pf element 0) like a wall segment or 3x3 (Grass Pf element 2) like the large gold vault. Tatami is the only object that takes grass collider 5x5 ( Grass Pf Element 4).
Construction TypesArray size matches Structure Pf. Like grass types, we match the construction prefab grid size too. Since there's 3 different sizes of construction prefabs, this ranges from values 0 to 2. By default, we set most structures to use the 3x size.
Pivot CorrectionsArray size matches Structure Pf. Odd size grid structures (1x1 and 3x3) need a pivot correction so they don't appear accidentally off-center, taking more grid space than necessary. Pivot Correction does this.
Is ArrayArray size matches Structure Pf. If set to 1, uses the row making field builder for construction instead of the usual construction. The only objects that use this are the wall segments that let you pick a start and end point and automatically constructs a repeating row of the structure between the points.
Is InstantArray size matches Structure Pf. For items you set TimeToBuild to 0 (instant build) in the XML, you also want to set the elements Is Instant boolean to 1 in this array. The only objects that use this in the demo are the wall segments.

XML Example (Flag Decoration Object)

Here's an example of one of the ambient decoration elements from XML/ambient.xml used by the centralized creator script Scripts/Creators/BaseCreator.cs

<Ambient>							
		<Name>Flag</Name>	
    <!--  name displayed in the store -->	
    
		<Description>Flag description.</Description>		
    <!--  description displayed in the store -->			
    
		<Currency>Gold</Currency>		
    <!-- save as Gold, Mana, Crystals to buy -->	
    
		<Price>100</Price>	
    <!-- amount of resource necessary to pay for the object -->
    
		<TimeToBuild>10</TimeToBuild>			
    <!-- the time (in minutes) needed to create the building -->	
    
		<XpAward>100</XpAward>	
    <!-- experience awarded for the completion of building this -->
	</Ambient>

Prefabs

Prefabs are connected in the game scene GameManager > SaveLoadMap Inspector as seen in the below screenshots. Also you'll find the same in the Map01 scene Game Manager > SaveLoadBattle. This is similar to th einstructions in Buildings > Part 2: Customize Menus which teaches about how to customize the prefab images used in menus and the game.

203

SaveLoadMap in the Game Manager. Click to view closer.

Here's an excerpt from the SaveLoadMap and SaveLoadBattle Inspectors which show the prefabs - matching the XML.

273

SaveLoadMap Inspector. Click to view closer.

Why aren't decorations attacked in battle?

In the Scripts/Helios/Helios.cs FindNearestBuilding() function we define which type of structures can be attacked as Building and Weapon game objects only. See the excerpt below:

// Scripts/Helios/Helios.cs
// Excerpt from FindNearestBuilding() function which 
// locates structures to attack during battle

// ......

			// Limit attackable structures to game objects with structureClass 
			// of Building or Weapon only
			if (allGrassPatches [i].GetComponent<GrassSelector> ().structureClass == "Building" ||
				allGrassPatches [i].GetComponent<GrassSelector> ().structureClass == "Weapon") 
			{
				selectedGrassPatches.Add (allGrassPatches [i]);
			}
		}

// ......