Hm, I may be misinterpreting the question here, but I’ll give what I think you might be looking for?
If you’re trying to create a type of system in your game to be able to attach ‘tags’ to objects in game, couldn’t you create a custom class like GameObject
that takes a model and tag parameter; then, somewhere, you could create a List
of GameObject
.
GameObject
class could look something like this:
public class GameObject {
private Model m_ObjectModel; // The model of the game object.
private string m_ObjectTag; // A tag that can be used to find this particular game object later.
private bool m_ObjectEnabled = true; // Whether the model should be rendered or not.
public GameObject(Model model, string tag) {
m_ObjectModel = model;
m_ObjectTag = tag;
}
public string GetTag() {
return m_ObjectTag;
}
public bool IsEnabled() {
m_ObjectEnabled;
}
//Do other stuff...
}
Then, where ever you have your list of game objects stored, you could create a function to find a specific game object with a tag with something like this:
public GameObject FindObjectWithTag(string tag) {
GameObject foundObject = null;
gameObjectList.ForEach(gameObj =>
{
//Check the tag of each game object in the scene.
if(gameObj.GetTag().Equals(tag, StringComparer.OrdinalIgnoreCase) {
foundObject = gameObj; // this is the game object we want.
break;
}
});
//Throw an exception if no object was found.
if(foundObject is null)
throw new Exception($"GameObject with tag {tag} does not exist!");
return foundObject;
}
If you’re also lacking a sort of trigger system, think of maybe adding something like an update function for the GameObject
type where you could have a sort of sphere cast (sorry, I’m not too familiar with MonoGame’s 3D side) to check whether an object has just entered the radius.
So, in the case of having a bomb, you could do something like this if you have/add the above trigger-type system:
// this should be an event that is called when any game object enters the bombs area.
void override ObjectEnteredRadius(GameObject object) {
if(object.GetTag().Equals("Enemy") {
((Enemy)object).Kill();
}
}
And if your bomb had an function to have it explode, with this gameobject system you could do this easily anywhere:
((BombObject)Game.FindGameObjectWithTag("Bomb")).Explode();
XML wise, this is all totally possible to save to a file. You could potentially take a look at this post on Stack Overflow here for more help. I am absolutely horrible working with XML but my 2D MonoGame project has a sort of generic list XML saver & loader, if you want to see it, look here. This code is pretty old, so it’s gross, don’t be too hard on me, lol.
I hope this was kind of what you were looking for, if not this can at least maybe help someone else. This code was not put into any kind of compiler, so I don’t know for sure if the syntax is 100% correct, but this should be good enough to get the general idea of what I’m explaining, I hope.