Thought this might be useful to the people here. I coded a simple framework for IF in Unity / C#.
Uploaded the Game here.
For those not familiar with Unity
- The code all resides in /Assets/Scripts
- /Core is where all the Unity interfacing and game management happens (ie. taking player input, displaying text, keeping track of game state, etc)
- The Unity lifecycle for this intent is Awake() → OnEnable() → Start(). Update() is called once per frame.
Explaining my decisions a bit more
- I used the Unity Inspector as little as possible. I dislike managing my objects in that interface so I put stuff in code when ever I could aside from the few UI elements.
- Delegates are my event bus.
- I use static for most things. Didn’t feel the need for DI system and not really worried about threading.
- Command pattern seemed pretty good for Player Actions.
A typical flow of player action looks like
- PlayerInputBox (Unity text input box)
- PlayerInputHandler (C#)
a. Reads in input from player and decides appropriate action - Action.execute() (C#)
a. Updates world state, player, etc. - StoryTextHandler (C#)
a. Displays results of player action to UI - StoryTextBox (Unity text box)
Basically it has all the stuff needed for a simple IF, with a (hopefully) straightforward way of adding and expanding to it.
- Actions
- Rooms
- NPCs
- UI
- Dialogue System