I want to be able to assign each spell(scriptable object) an ‘effect’, and a ‘targetType’
Example:
Controlled blink:
fireball
lineTarget
rangeTarget
globalTarget
this way one could easily make a wide variety of spells such as: “Line blink”, “Global fireball”, etc, by combining effects and targetTypes.
My issue is I don’t know where to put the effect code. I don’t want to put it inside my spell script, as it doesn’t feel like it belongs there.
I’d like to create a base effect class, a bunch of subeffects (fireball, controlled blink) and then assign these in the inspector to each spell. But this doesn’t work, you can’t assign classes to scriptable objects.
I want my spells to be scriptable objects because a spell shouldn’t need a transform.
I probably am just going to put the effect code in the spell script though: as an enumerator and have a long string of if statements for each effect.
Create an Effect and your specialized FireballEffect, Blink, et al. as ScriptableObjects too. Then if you give your Spell a List of Effects, rather than a single Effect, you can stack all sorts of wacky outcomes.
I’m trying out singleton scriptable objects. I still need enumerators, and I can’t get inheritance from a base effect class to work, but here’s what I’m working with atm.
[CreateAssetMenu]
public class spell : ScriptableObject
{
public enum effectE { controlledBlink, flameLine, consume}
public effectE spellEffect;
public void processEffect(tile target)
{
if (spellEffect == effectE.controlledBlink)
{
controlledBlink.instance.processEffect(target);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class controlledBlink : ScriptableSingleton<controlledBlink>
{
public void processEffect(tile target)
{
if (target.myUnit == null)
{
gameControl.Instance.playerUnit.moveToTile(target);
}
}
}
I didn’t want to have create instances of all my scriptable objects so I used the singletons. I don’t really love it but whatever it works. And using a list of effects is a cool idea, I’ll probably add it in when I need it.
Aren’t scriptable object singletons an Editor Only tool? Won’t that cause issues when it comes to building your game?
It might work to break down spell effect scriptable objects into their basics. Damage, movement, etc. Rather than a ‘controlledBlink’ scriptable object spell effect, you just have a ‘movement’ effect, and can make multiples of that with various max distances, speed, etc, that you then slot into their appropriate overarching spells.
Maybe the pattern will be of use to you. After all, a fireball, icebolt and lightning-zap are all just projectiles that do damage. You could make a ‘projectile spell’ scriptable object class, and give yourself the room to customise its appearance in the SO, and define the effect by overriding a virtual method. Maybe even use interfaces for other effects. Food for thought.