Adventure interactionSystem Structure (ScriptableObject,MonoBehavior,POO?)
Hi, I'm working on an 2d P&C Adventure and I want to design my Player-Interactions. I'm kind of stuck and could use some guidance. So far, I've got Characters (e.g. Player) and Interactable Objects, Interaction is driven by a MouseController and handled by an EventManager.
User clicks on Interactable (GameObject,MonoBehavior)
MouseController calls OnUse(player,interactionType) // type = USE,LOOK,KICK,PICKUP etc.
Interactable notifies EventManager
All subscribers do their thing (Update GUI, play sound, whatever)
Now what I want is a System for Interactable, that decides what to do OnUse
My Idea:
Every Interactable has a Set of Reactions that are bound to Conditions, when Conditions are met, the Reactions are executed.
Conditions could be "Has Inventory Item X", "Has Quest Stage X","Some global Bool is true" etc.
Reactions could be "Display Message X","Add InventoryItem X to Interactor","Set some bool" etc.
I would like to design the Interactable Conditions and Reactions in the Editor (or in external text file) and avoid making 100 Scripts that inherit Interactable and each implement OnUse. (The possible Interactions would be designed by a non-programmer in Unity Editor if I can get it to work somehow..)
How would you implement such an Interactable-Script and the components?
Examples/Current ideas:
public enum InteractionType{LOOK,USE,KICK,TALK}
public class Interactable : MonoBehaviour{
Reaction[] condReactions;
Reaction defaultReaction;
public void OnUse(Character c, InteractionType type){
foreach (Reaction r in condReactions){
if (r.AllConditionsMet()) r.execute();
}
//... if nothing matches
defaultReaction.execute();
}
}
public class Reaction : ? {
public Condition[] conditions;
// needs some more dynamic params like interactor,interactable etc.
public bool AllConsitionsMet(){ //return true if all are met}
public void execute(){
// Add something to inventory
// Display some text
// destroy Interactable
// ....
}
}
public class Condition : ? {
string condName;
SomeClass value; // SubClass for BoolConditions,HasInventoryConditions etc ?
public bool IsMet(){
// some evaluation ?
}
}
Could anybody shed some light and give me some guidance?