Social Game — Dev Blog 2

胡琦
Hu Chi
Published in
5 min readMay 26, 2020
TL;DR: The interface of the game is DEFINITELY improved.

So this month I enrolled in Unity’s Student Plan. It includes one-year Unity Pro, which comes with the dark theme, and some more benefits.

Also, since the last update, much has been improved, with mostly focus on the visuals and custom tools to utilise the Yarn Spinner.

Finally getting the dark theme!

Using the Yarn Spinner

Yarn Spinner is a tool for writing game dialogue. It is free, flexible, and most importantly, open-source. It is used by some games like Night in the Woods and Far From Noise.

Yarn Spinners are used in Unity through a language called Yarn. A Yarn dialogue is fed to a Dialogue Runner line by line. Each dialogue is node-based, making branching dialogue possible. So my main goal is to write my own tools that parse Yarn Programs correctly based on the requirements I need, so I can also write the dialogue on my own with ease. Yarn dialogue can be written with any text editor, or with the Yarn Editor that visualise the nodes of the dialogue.

Here is a demonstration of one section of my game, the left image is the screenshot of the Yarn Editor, and the right image is a Yarn dialogue excerpted from the node BreakIce.WhereTo_Player, featuring nested shortcut options:

In this section, the player is given two options to speak at first: “Well you know what’s the problem of life?” and “I guess there’s always later.” The indent indicates the dialogue is branched, and the lines with the same indents have the same hierarchy. Player then continues to speak. At the end of this section the program waits for two seconds before continue to run.

The following example demonstrates how commands (enclosed with angle brackets) and dialogue text interleaves in a Yarn Program:

Left: a Yarn dialogue section. Right: how this section looks like in the game.
  1. <<playSequence intro noWait>>: play the intro sequence without delay.
  2. <<wait 4.5>>: wait for 4.5 seconds before running next line.
  3. <<doExclaimation A-Exclaimation ARRRRGH!!! 2>>: make the speaker A (i.e. the player) exclaim for 2 seconds with content ARRRRGH!!!
  4. <<setDefaultSpeaker Player>>: make the Player as the default speaker.
  5. Player: WHAT THE HECK WAS THAT: make the Player say “WHAT THE HECK WAS THAT” (well it’s straightforward)

Context-Based Speech Bubbles

A custom tool I implemented is the speaker tool. Here are the features of a speaker in the game:

  1. A speaker has a name and their position in the world.
  2. A speaker has multiple speaking states, i.e. the “speaking” and “thinking” state.
  3. A speaker may have more than one possible dialogue to choose from.

Based on the features above, I wrote some simple commands for Yarn Programs to read. See the demonstration below: a setSpeakerState command can change the speaking bubble of the speaker. Also, based on a character’s reply, variables can be saved and stored as well (this is a built-in feature of Yarn Spinner).

Left to right: Speaker component, dialogue text, and the final results (including debug texts showing stored variables).

Custom seamless ambient sound system

Another part of the development I am working on recently is implementing a fully functional ambient sound system that can play seamless audio clips and is compatible with Yarn Programs.

  1. Soundscape: a combination of loop clip events and non loop clip events, together they construct a sound environment. An example of this can be a soundscape of a forest.
  2. Looping clip events: able to be played seamlessly, even for non-seamless audio files. An example of a forest soundscape can be the sound of rivers and winds (which is played without stopping).
  3. Non-looping clip events: audio events or “bursts” randomly that are not seamless. In addition to the clip we want to play, we also need to assign the minimum and maximum wait time, before the next “burst” is played. An example of a forest soundscape can be the sound of chirping birds (which is played with random gaps), after playing the chirping sound effect, we wait for an amount of time, before playing it again.

Based on the above requirements, I created a Soundscape type component, and two classes: NonLoopClipEvent and LoopClipEvent:

And during the initialising of a soundscape, audio sources are instantiated:

Soundscape events are being instantiated in realtime (line 3).

Here is the explanation of the following code: For each audio clip, two audio sources are created, source A and source B. In the beginning, source B starts to play the clip starting from a random time of the clip (line 6–12), then when the clip is about to reach the end, the source fades out, where source A simultaneously fades in, playing the same clip again. From here, source A and source B play the same clip at intervals (line 14–24), creating a seamless ambient loop:

A diagram visualising the above code section. Source A and source B interleave and play the same clip, and with the overlay time, creating a seamless ambient loop.
Left: A soundscape inspector component. Right: How the seamless audio playing works in realtime.

Now we have the main structure done, we can create our custom command handlers so a Yarn dialogue can “read” the new commands: addSoundScape and removeSoundScape:

This demonstrate how the Yarn Program can “talk” with the soundscape manager to play the corresponding soundscapes.
In Yarn Programs, simply call “addSoundScape” or “removeSoundScape” to change the ambient mood of the game.

To be continued…

--

--