In-game programming in Unity Demo

In several past articles, I discussed an approach to setup a Unity scene to support object interactions and control in 3D, similar to a number of time management and programming games.

Prototyping a robotic factory game in unity3d
Creating in game programmed components in Unity
Extending in game programming in Unity

Virtualizing a computer, or in this example a microcontroller as a script interpreter is reduced to processing commands one line at a time, the extra effort is for the visualization and animation to show how the program go through the instructions. The additional consideration is for the programming interface which uses drag and drop controls similar to MIT Scratch, Google Blockly  or Human Resource Machine  to simplify the programming creation instead of using a typical text editor and possibly work better with mobile and tablets.

The project is implemented using only built-in Unity components, the core logic is implemented on Unity C# scripts, movement and animations are handled by Coroutines and the Animator Component and UI uses the Canvas, Panels, Button and Text. I implemented my own UI Scrollable List to support the drag and drop, insert and re-order element animations.

The scene is composed of the following elements:

ProgramDemo-1-Components

The main scene actor is the yellow capsule representing the programmable player. The player is on a plane with Input, Output and Storage cubes. Supported code instructions are dragged into the program area to be executed by the player.

The storage areas support “put” and “get” instructions for storage and retrieval. Arithmetic operations “add” and “sub” is applied to the item in storage and the player carried object. Branching or conditional operations are done through the jump  (jmp) commands that support equal to (jeq), less than (jlt) or greater than zero (jgt) comparisons to the player carried object.

ProgramDemo-2-Program

Program creation and editing is handled by drag and dropping instructions from the instruction palette in to the program area. Double clicking an instruction on the palette automatically adds it to the end of the program. Instructions on the program can be dragged up or down the list and dragged out of the area to be removed.

ProgramDemo-3-Parameters

Instruction parameters are set by clicking on the number and then selecting either another instruction in the program for the jump commands or storage cubes for the put/get and add/sub operations.

To further enhance the processing capabilities, I will add 2 more instruction types in later versions:

• Increment / Decrement convenience functions for the values in storage
Indirect Memory Addressing — that is, using a value in storage to identify another storage location

To complete the demo — I will setup a configured input and expected output to define program success or failure and some performance metrics.

An interactive WebGL demo is setup at:

http://orbitalfoundry.com/WebGL/ProgramAlphaV010/index.html

ProgramDemo-4-WebGL

For questions, comments or contact – follow/message me on Twitter @rlozada