So I’m working on a Card game, and this game actually has somewhat complex logic. Every card in the game has its own behaviour, and as a result, coding in the logic directly in unity with GameObjects became very hard and unruly, so I decided to implement the logic separately in a Visual Studio project, and then import the logic code into unity as a DLL or in source code form, whichever is more convenient. I could then just have an empty gameobject contain a gamelogic object, and then other classes written in unity act according to that logic. I realized this was a good idea when I found this answer.
So here’s something I keep wondering about: how to handle user input.
My current idea is to have my GameLogic class accept a reference to an object which implements an interface that contains callbacks functions. The GameLogic class can then call these callback functions whenever it needs user input. The UI class that implements the interface can then perform the necessary steps to obtain user input. In the case of unity, the UI class will probably do different things with GameObject depending on the kind of input needed.
This works for command line games, which is what I am currently implementing real quick to test my logic. However, will this work in Unity? I will need to make the callbacks run in a separate thread than the game. How convenient/inconvenient is this?
Should I implement user input into my library in another way that suits Unity?
The same thing applies for “Game Events”… for example, if my logic class decided to draw a card from a deck, I want the UI to show this action, so I make the logic class call a callback function that a Unity object implements, and then that unity object performs the animations and everything. Is this practical/realistic?