State machine implementing a state transition graph to use for a classic game scenes structure.
(TODO: add more infos)
Only state and data management system, no game is provided.
Details about each element can be found in the project's documentation.
(TODO: REWRITE) Samples are provided(TODO: LINK SAMPLES - make other document?), allowing to use the engine straight away, either for testing/exploring, or to use as a base for a new game.
This document describes how to create a basic game using the engine, based on the ... sample(TODO: LINK in 'code'?).
The "State Graph Engine" project was built and tested in Unity 6.
To use the engine, a number of steps are required:
- Setup the Unity Project
- Design the State Graphs
- Define the game Data
- Build the Graph Managers
- Create the States
- Prepare the game Levels
NOTE: This will be changed when project becomes a package.
The first step consists in creating a Unity project ready to use the engine:
- 
Download the latest release (or clone the repository for latest changes). 
- 
Extract the downloaded repository to a temporary directory. 
- 
Create a new Unity project. 
 Any type of project can be created depending on the desired game type. The state engine is independent of the project type.
- 
Copy the StateEnginedirectory from the extracted repository to the project'sAssetsfolder.
- 
Set the scripts execution order. 
 Some scripts need to be executed early at the start of the application for proper initializations. This can be managed by changing the script execution order:- Go to Project Settings->Script Execution Order
- Add GlobalManagerbeforeDefault Time
- Add GameManagerbeforeDefault Time(just afterGlobalManager)
 
- Go to 
The game will contain 2 graphs: a global graph and a game graph.
Graphs are defined in XML files. They can be created manually or by using the unity-state-engine-graphview tool.
... => explain default global graph (xml) very basic graph, with minimal functionality.
- menu
- newgame
- quit
global_states.xml eg in 'resources' folder => at least 1 state, to start a new game, and to quit the graph/application
... => explain default game graph (xml)
game_states.xml eg in 'resources' folder => at least a level state... if no map state: ...(setlevel, etc.)
LEVEL SUCCESS FAILURE GAME_END GAME_OVER CONTINUE QUIT_GAME
(no map state, directly in level state)
(...?) (no global data...)
... => explain default game data (xml)
!!!! add health + points in StateEngine6_TEST
- create data xml file (game data) eg in 'resources' folder values.xml scripts eg in 'Scripts' folder GlobalDataManager.cs GameDataManager.cs => explain simple data
script + prefabs (global + game)
- create data managers prefabs eg in 'Prefabs' folder GlobalDataManager GameDataManager
...
Build the 2 graph managers prefabs.
Save the new prefabs in a new Prefabs folder for example.
Create the Global Manager prefab:
- 
Create a global data manager prefab. - Either create an empty object and add a GlobalDataManagerscript component, or drag and drop the script in the Hierarchy panel.
- Save the prefab . Name it GlobalDataManagerfor example.
- Delete the instantiated prefab in the Hierarchy panel.
 
- Either create an empty object and add a 
- 
Create the global graph manager prefab: - Instantiate the provided GlobalManagerprefab.
 The prefab should already have aGlobalStateManagerprefab set for itsGlobal State Managerporperty, as well as aGlobalStateControllerscript component attached to it.
 TheGlobalStateControllercomponent in instantiated prefabs will be replaced by an overridden script for global states requiring specific actions or behavior.
- Set the GlobalManagerprefab properties:- Set the GlobalDataManagerprefab for theGlobal Data Managerproperty (the prefab itself, NOT an instance).
- Set the global_statesXML file for theGlobal States Graphproperty.
- Set the valuesXML file for theGame Dataproperty.
 
- Set the 
- Save the prefab (as a variant), and delete it in the Hierarchy panel.
 
- Instantiate the provided 
Create the Game Manager prefab:
- 
Create a game data manager prefab. - Either create an empty object and add a GameDataManagerscript component, or drag and drop the script in the Hierarchy panel.
- Save the prefab. Name it GameDataManagerfor example.
- Delete the instantiated prefab in the Hierarchy panel.
 
- Either create an empty object and add a 
- 
Optionally create a global data manager prefab from the script with the same name. - Either create an empty object and add a GlobalDataManagerscript component, or drag and drop the script in the Hierarchy panel.
- Save the prefab. Name it GlobalDataManagerfor example.
- Delete the instantiated prefab in the Hierarchy panel.
 
- Either create an empty object and add a 
- 
Create the game graph manager prefab: - Instantiate the provided GameManagerprefab.
 The prefab should already have aGameStateManagerprefab set for itsGame State Managerporperty, as well as aGameStateControllerscript component attached to it.
 TheGameStateControllercomponent in instantiated prefabs will be replaced by an overridden script for game states requiring specific actions or behavior.
- Set the GameManagerprefab properties:- Set the GameDataManagerprefab for theGame Data Managerproperty (the prefab itself, NOT an instance).
- Optionally check the Use Global Data Managercheckbox and set theGlobalDataManagerprefab for theGlobal Data Managerproperty.
- Set the game_statesXML file for theGame States Graphproperty.
- Set the valuesXML file for theGame Dataproperty.
- Set the levelsXML file for theGame Levelsproperty.[*]
 
- Set the 
- Save the prefab (as a variant), and delete it in the Hierarchy panel.
 
- Instantiate the provided 
[*]: The level tree is not yet defined at this point, so an empty file can be used (it will be edited later when [creating the levels](TODO: LINK LEVELS)). TODO: check if OK to have no level defined at runtime?
TODO: might make more sense to make section for each state (+main split global/game))?
- create states
=> for each state
- scene (create, add graph manager, etc.) (- state controller) => optional scripts global => override 'GlobalStateController' game => override 'GameStateController'
- other specific resources/data...
 
- create scene with name + build settings (! - first one!)
- instantiate graph manager
- if necessary override state controller
...
... actions...
... actions...
- create levels (+ update XML)
- scenes (1 per level or shared)
- whatever the game requires...
 
...
- create level tree xml file eg in 'resources' folder levels.xml => can be completed later (as probably don't know all levels yet), but should at least already provide an empty file (easier for later, simply edit the file). => show basic tree (3 levels) (as in StateEngine6_TEST)
TODO: change example? levels.xml:
<?xml version="1.0" encoding="utf-8"?>
<levels>
	<level id="1" name="Level 1" scene="Level1" startup="true">
		<data
			beginAnim="..."
			endAnim="..."
			test="testvalue"
		/>
		<nextLevels>
			<nextLevel id="2"/>
		</nextLevels>
	</level>
	<level id="2" name="Level 2" scene="Level2">
		<nextLevels>
			<nextLevel id="3"/>
		</nextLevels>
	</level>
	<level id="3" name="Level 3" scene="Level3"/>
</levels>
... (shared)
... 1 per level (can make template, with instanced game graph manager and level controller - overridden state controller)


