Okay, so I've been trying this all afternoon, but can't make it work properly.
I'm making a basic kinda of event-system for our Unity3D project, and I'm having trouble.
Basically, I want to have two(for now) strings in every class that derives from the class EventCommand.
Those variables are then going to be read by the Unity editor script by using something like
foreach (EventCommand cmd in eventCommands) {
if (cmd.CommandName != null) {
eventBase.tabs[selectedTab].commands.Add(cmd);
}
}
that will then add the command to a list of commands.
Problem is that I can't get it to read anything more than an empty string, or whatever is set in the EventCommand class.
So I want to be able to change those two variables (or functions, if that's better) into returning custom strings for each class that inherits from it.
I've tried using functions (both normal like the ones below, as well as using virtual or abstract and overriding them)
public class EventCommand {
// Preview of command configuration
public string CommandString() {
return "";
}
// Name shown in list of commands
public string CommandName() {
return "";
}
}
public class EventMessage : EventCommand {
public new string CommandString() {
return "Show Message: Text here";
}
public new string CommandName() {
return "Show Message";
}
}
And I've tried using normal variables (as below, as well as using const, basically, I've tried everything I can think of.)
public class EventCommand {
// Preview of command configuration
public string CommandString = "";
// Name shown in list of commands
public string CommandName = "";
}
public class EventMessage : EventCommand {
public new string CommandString = "Show Message: Text here";
public new string CommandName = "Show Message";
}
Am I just stupid, missing something, or is there a better way to do this?
If someone experienced could help me with this, as it's a school project that's pretty important, I'd be very grateful.