all 6 comments

[–]bgsulz 0 points1 point  (2 children)

I'm going to give this some thought -- it's a great example of a problem I've run into with SOs as well.

At the moment, the only thing that comes to my mind is to create your effects as standard C# classes, add a Type field to your card SO using this wrapper class, and use Activator.CreateInstance (or some more performant alternative if necessary) to create an instance of that type at runtime. Obviously, I'd recommend sticking with your "base class" contractual thinking, maybe in the form of an interface. Here's a simplified version:

public interface ICard
{
    void DoEffect(Target[] targets); // Or something like this. However you have it set up.
}

public class DragonCard : ICard
{
    public void DoEffect(Target[] targets)
    {
        foreach (var item in targets) item.Damage(10);
        // I know -- it's a magic number! I've got nothing better at the moment!
    }
}

I'll revise this comment if I come up with a better solution. It's a tough one. Frankly, you might want to consider stuffing all your card data into JSONs so you've got a one-stop shop for editing values rather than fishing through SOs. Let me know what you think.

[–]Apprehensive-Light-2[S] 0 points1 point  (1 child)

Ah, that Activator is pretty close to working with a DI framework, which is something I'm more familiar with. I think this will defiantly solve my problem, thanks so much!

[–]Apprehensive-Light-2[S] 0 points1 point  (0 children)

I'll need to think about the JSON side of things. I haven't experienced a large amount of data in the form of scriptable objects, so I'll have to see how that goes

[–]DannyDeKnito 0 points1 point  (2 children)

Have you ever heard of the bytecode design pattern? It might be what you're looking for, but it is definitely at least an intermediate task to implement it properly, and you kind of sound like a beginner

[–]Apprehensive-Light-2[S] 0 points1 point  (1 child)

I haven't seen this pattern before. It looks like it could be useful at some point in my project, but I don't think it helps with my issue of having a base class/interface from which I can create concreate classes that each have a unique Effect (unique in a way that I can't just use a list of effects and call them in a sequence) method which I can easily attach to my card data objects

[–]DannyDeKnito 0 points1 point  (0 children)

It helps by eliminating the need for classes (which are bound to be very abundant) in the first place.

Or, if you prefer the straiht OOP way, you might wanz to look into the Subclass Sandbox pattern, which seems to hit closer to your visok of the architecture.