TilePlus Demo Apps

The TilePlusExtras folder has a number of demo programs. Most of them have a .txt or .md doc file in the demo's folder.

The contents of this online copy may be different or newer than what's in the distribution.

Animated Tiles

AnimTilesDemo.png

Purpose

Basic Demo

BasicTilesDemo.png

Purpose

Top-Down Layout

Important:

This demo requires the New Input System and won't work unless it's enabled.

Layout Demo.png

Purpose

This demo uses almost every main feature of the TilePlus system.

If you aren't yet familiar with what a SRS is, please see this.

If you look in the Demo code you'll see a SRS folder. There you'll find several SRS scripts:

Next, look at the Demo code's Components folder. Here you'll find:

ChunkingGameController's Start doesn't do much:

At this point the code mostly runs on its own: events from PlayerController cause re-layout as the player character moves around.

As the player character moves around, its position is messaged to all tiles implementing ITpMessaging<PositionPacket>.MessageTarget. This packet is used to send the current Tilemap position of the player character to each of these tiles. If the position sent matches the position of a tile, it posts an Event to TpEvents.

TpEvents is outwardly pretty simple: it just stores references to any tile which 'posts' an event. The ChunkingDemoGameState Service subscribes to TpEvents, and gets notified when an event is posted; setting a flag variable.

Note that ChunkingDemoGameState is less of a 'service' and more like a global variables class; that is, a singleton. In a non-demo app you probably don't want to use this approach but it's easier to understand.

The Update method of ChunkingDemoGameState AND the UpdateTiles method of ChunkingDemoLayout both use TpEvents.ProcessEvents.

Why both?

In ChunkingDemoLayout, TpEvents.ProcessEvents is called after we have sent position data to tiles. So it makes sense to process events here. However, if the app is using the "TileUi" feature of TPT, these tiles can and will send events if a tile is clicked on (or otherwise messaged via the 'New Input System'). Hence, ChunkingDemoGameState's UpdateMethod handles any of these type of UI events.

If you look at the code for ProcessEvents it doesn't look like it does much. However it's a really important part of the system.

Basically, what it does is look at all the tiles in the HashSet of tiles which had posted events. Unless you have a lot of overlapping tiles receiving position messages, there will usually be only one instance to evaluate.

A really simple method would be to look at each tile, determine its type, and have custom code for each situation. Obviously, that's really bad. Hard to add features, easy to create bugs, hard to maintain.

In the TPT system, each tile instance has a field for a scriptable object called an EventAction. There's also one for a ZoneAction, which is a different thing I'll discuss a bit later.

Event Actions have one method: Exec, and one property: Incomplete.

As ProcessEvents looks at each tile in its HashSet it sees if there is an EventAction reference. If there is, it calls Exec and passes in the tile reference along with an optional object called the EventActionObject, which is an object (c# object) with whatever sort of data that you want to pass to EventAction.Exec.

You can see the use of EventActionObjects in UiButtonTile. Here, we pass along a tag string, the zone bounds, and the tile instance (which is redundant). The TileUi demo has UiButtonToAsciiEventAction which uses this mechanism to pass along the target control.

Being able to pass-in arbitrary data from the tile to the EventAction means that the EventAction itself does not have any state information. That's important because it's a ScriptableObject and changing anything in it during Editor-Play will alter the fields. Not good. Avoiding state info in the EventAction means that we can use this S.O. for several tiles of the same type or of any other type.

If the Incomplete property is true, the event isn't discarded and is returned ProcessEvents' caller for further custom processing.

As implemented in this demo, everything is done via Event and Zone actions. Hence, no list for returned tile instances is even provided to ProcessEvents.

Let's examine an EventAction used for TreasureChests.

The minigame's goal is to get all of the chests. Can't change to another level (TScene) until that's met.

Open the Scripts/Actions/TreasureChestEventAction.cs and look at Exec().

After some simple validity checks, the treasure chest count is incremented. This is saved on a per-level basis in the game data which is periodically saved to the filesystem.

It checks to see if it's 'parent' tile actually implements the ITpPersistence interface. If it does, the tile's save data is obtained and 'Poked' into the save data using the ChunkingDemoGameState Service.

Next it does something sort of fun: opens a tile-based dialog box. The dialog box is a pre-made TileBundle which is just loaded to a separate tilemap for UI tiles.

After setting a flag in the GameState to temporarily block other UI (ie - a modal dialog) it just waits for a callback to unblock ui, which occurs when the user closes the box.

Here's an EventAction used for Waypoints

You can find WaypointEventAction in the same folder.

This action checks for the proper type of tile, disables all other waypoints, and checks to see if the waypoint is marked as a level change waypoint.

If not, it saves the game, directly from this S.O. `` If this IS a level change waypoint, is the SceneExitGoalAchieved?

If it is, Save the game and change levels (TScene).

As you can see, the EventActions are away to move object-specific code from a core part of your app back to the object itself. The relatively simple mechanism used by ProcessEvents can handle it all.

Side-Scroll Layout with Parallax

Requires 'New Input System'

This simple example shows how to implement side-scrolling behaviour while using the TilePlus Layout system and Parallaxing.

SideScroll.png

This example also shows how to directly use ZoneLayout and ZoneManagers without the Scene Manager.

In SsLayoutGameController, the Start method enables the Zone Managers via TileFabLib and then uses the ZoneLayout component to initialize it, then performs the initial layout. The OnPlayerHasMoved callback also updates the layout as the player moves. Only left-right movement is possible.

The SsDemoPlayerController is similar to the one used in the Top-down Layout demo with the added feature of limiting directions to left-right only and enforcing limits for the left and right boundaries.

The scene's middle and rear Tilemaps have a TilemapParallax component. This merely shifts the Tilemap transform based on a target's position.

This example was created specifically to ensure that the Layout system could properly handle a position-shifted Tilemap.

TileUi

TileUiDemo.png

Purpose

Requires 'New Input System'

This is an example of how to use TpActionToTile and the TpInputActionToTile component as well as hovering for tooltips and hovering for animation.

On the left is an AnimatedButtonTile. It supports changing animation on hover and on click. It uses a simple event action which changes the value of the AsciiChar tile just above it.

Clicking on a number in the Keypad area will

  1. change color of the number for a few hundred mSec (this is set via a variable in the tile instance).
  2. make a noise using a callback to this component. The noise is different depending on if a tile was clicked or not.

The box next to the keypad is a toggle and the two sets of boxes underneath that are two sets of radio buttons. One uses tags and the other uses Zones to create a radio group.

The number dials comprise up/down arrows and a UiAsciiCharTile to show the number.
Clicking on the arrow buttons will make the numbers go up/down. That's done with ZoneActions. Each one of these buttons implements a 1x1 zone that's placed over the number tile that's between the buttons. You can see this with Painter's Edit mode: select one of these and click visualize in the Zone controls section.

The 'HZ' tiles are Hover Zones. These can be used for tooltips. In this example, they're used to print a description of the Control in the text box.

All of the "which tile is it" code etc is in TpActionToTile.cs which is managed by the TpInputActionToTile mono-component.

Tweening

tween-demo.png

Purpose