I am using Unity to build a visualisation of a serious game. I am using C# programming language.
My problem is that I receive data from a JSON and I parse it and I end up with a list of different ‘words’ saying for example:
Player - walks to - Carl
or
Carl - says … to - Player
(note that this list is not limited to 3 words, it can be a longer statement, and it doew not HAVE to contain Player or NPC or whatever, it’s very flexible)
I have a list containing all the possible actions & NPC names , so Carl in this example, would be in my NPC list of names so I can recognize him as an NPC. Same goes for the ‘actions’ to perform.
However now i need to map a lot of these different actions to visualisations in the game itself.
Thus I think I need a way to store:
the order of the words
the ‘meaning’ (NPC or Player or Action)
the word itself
Can anyone point me in the direction of a very efficient structure or design pattern to use to make this work? Thanks
While I don’t know if that’s what you are looking for, Enums seem to be a good way for the “meaning”.
As for the “order”, I guess an incrementing integer should do the trick.
(this was written on the fly, might need some corrections)
[Serializable]
class Word{
public enum WordMeaning{
Source, Target, Content
}
public int order;
public WordMeaning meaning;
public string content;
}
EDIT: I know it’s not the script forums, but it really felt like it is what was demanded.
Ok thank you for taking the time and read/help me. I will try to give a more advanced explanation. So I load a JSON file in my game and it looks for example like this:
Now I can successfully parse this file, and thus logically, in this example, i would be starting with g0. So I call my method which returns me a list of strings containing “player” “walks to” “carl” (in that order).
Now as you can see, there will be a lot more g’s. This is where I am stuck, how do i efficiently save this data and map it something that Unity has to do. (in this case I would want an object to be highlighted in the world and the player can manually walk here). But there can be other cases, if for example we turn the ,previous example around. The list could be “carl” “walks to” “player”, this would imply that the NPC carl will be walking to where the player currently is.
So basically I need a way to save three things:
the order of the words
the meaning (NPC or action) < explained this in my main post
the word itself
I am not skilled enough in Unity (and just patterns in general) to know what is the most efficient (or just any) way to solve this.