Unity C# - IF Skeleton Framework Project

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

  1. PlayerInputBox (Unity text input box)
  2. PlayerInputHandler (C#)
    a. Reads in input from player and decides appropriate action
  3. Action.execute() (C#)
    a. Updates world state, player, etc.
  4. StoryTextHandler (C#)
    a. Displays results of player action to UI
  5. 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
6 Likes

Updated with

  • Inventory
  • Saving and loading
  • Redid Rooms so they are not Scriptable objects so I could serialize them to save/load
2 Likes
  • Updated dialogue to actually be tied to the NPC
  • Added scenery elements that can be examined but not picked up
  • Renamed a bunch of stuff and reworked some existing logic

Somebody stop me if i’m not supposed to be replying with updates here.

  • Can now give items to npcs
  • Made containers to hold items
  • Can open and close containers and put stuff in them
  • Made commands a bit smarter so can give directly from a room instead of needing to put in inventory first.
1 Like

Replies are fine; we prefer replying to a single thread over making a new thread for every update, in fact!

2 Likes
  • Created a custom rule engine T__T (I’m never going to actually make a game am I?)

Well I spent about 2 years futzing with Rez before seriously knuckling down to make a game with it so I’d say you’re good a while yet :smiley:

1 Like