8

This is an incredibly complicated problem. I had an old series on blog about it but (a) I no longer recommend that approach and (b) old posts on my blog can't be read easily due to a snafu with a plugin and me not having time to fix it all. The gist of what you need to do on the "simple" end is to keep a table of IProperty objects which are specialized to ...


7

Yes, this is possible. Because it's making heavy use of reflection and uncontrolled strings, it can be both slow and unsafe, so I would not recommend it for regular game behaviour. For a console use case though, it's probably OK. If you intend to ship the console with a released game, I'd recommend adding some extra error-checking and sanitization of ...


4

The best way I've seen is to make use of some custom introspection. As Sean pointed out, this is pretty difficult to do on your own since it's not a direct standard C++ feature in any way. So if you're up for implementing something more advanced then read on. I actually implemented this (not the editor, just generic properties) in an open source project. ...


4

I use XNAGameConsole. http://code.google.com/p/xnagameconsole/ It was written for XNA 3.1, but I updated it to XNA 4.0. You can find those changes here: http://code.google.com/r/jameswalkoski-xnagameconsole-xna4/source/browse


3

First of all, I would consider making an ability a component, so that it can be attached to any GameObject: abstract class Ability : Component { public abstract byte Id { get; } public abstract Execute(); } By making the byte id a property, you can easily override the property in each class and give it a unique value, without having to worry about ...


3

I don't really get it, you are using polymorphism and then you don't? So far I understand it as the following, you have a base class Ability and derived classes that actually implement the ability. So something like: abstract class Ability { abstract public void Execute(); } class CastMagicMissile : Ability { override public void Execute() { ...


3

You could also simply use AllocConsole. AllocConsole is a Win32 Windows native function. In short, the AllocConsole method allows you to allocate a standard Windows console to the calling process. Once you have done this, you can use standard C# console input/output within your application using Console.ReadLine(), Console.WriteLine(), etc. To use this ...


2

If your system can deserialize the data on the other end regardless of the field order, you don't need to enforce that order. But you probably want to anyway, because it's better. If you have any dependency on that ordering (as in, you enumerate the results of getFields() on the receiving end and deserialize each field in succession), you had best make sure ...


1

The error identifies exactly what the problem is: TargetException: Non-static field requires a target System.Reflection.MonoField.GetValue (System.Object obj) Since the field isn't static, that means the values of the field are stored on an instance of the type. So when you ask the FieldInfo to fetch the values for you, you need to tell it from which ...


1

Fundamentally you're looking at creating a mapping from some piece of data (the "key") to some instance of your effect classes (ChangeHealth, SetPosition, et cetera). A straightforward way to accomplish this is to use some kind of delegate (Func<...> in C#, for example) to manage the generic creation of effect instances and some kind of associative ...


1

If you are looking for a certain method by a specific name, why don't you use interfaces instead? That way you can make any MonoBehaviour class implement that interface. Of course, this wouldn't let you make use of custom attributes (like RPC) for you to state a method to call by its name. But it would solve the problem (although not with your desired ...


1

Only way to change a class without extending it (or without access to the source) is by using reflection. For java there is the rather comprehensive Java Reflection API that is made for this task. It might be a bit daunting at first. Anyway the operation you are looking for is called injection. Here is an example of injecting a method into the class at ...


1

You have separate classes for each Ability, although the type of each ability is already defined by ByteID. As such, an "ability" is really just a link between each ByteID and a unique callback. You are unnecessarily defining the callbacks via inheritance. A static Execute() can "index" which execute() to use with only ByteID. In this way, all ability ...


1

I'm not saying either your approach is good or not! Just simply note that it's very complex and might later give you a headache if you even need to change simplest things. But there is an issue with your current implementation. C++ compilers doesn't care about the order they initialize static variables. this won't cause that much problem with primitive types ...


Only top voted, non community-wiki answers of a minimum length are eligible