Hi,
I’m working on a project where I want to dynamically change the way certain function calls behave.
basically it’s your typical Strategy patern where I have something like this:
class MyClass : MonoBehavior {
public IBehavior myBehavior
// class code
}
interface IBehavior {
void DoSomething();
}
class BehaviorImpl1 : MonoBehavior , IBehavior {
void DoSomething(){
// one way of doing something
}
}
class BehaviorImpl2 : MonoBehavior , IBehavior {
void DoSomething(){
// another way of doing something
}
}
so all I need to do do change the implementation dynamically is to change which implementation I’m using by doing something like
myClassInstance.myBehavior = new BehaviorImpl2();
But what I’d like to be able to do, is to set, via the inspector, which implementation of behavior I have when my scene is loaded. But the inspector doesn’t expose myBehavior. I guess there’s a way to do this with a custom Inspector script, but I have no idea how to. Any ressource (or perhaps a piece of code) to enlighten my quest for encapsulation?
By the way, I don't know why I extended MonoBehavior in my IBehavior implementations. A reflex I guess :-) but ultimately they don't HAVE to be a MonoBehavior
– jeangoconsider creating an enum of behaviour type
– Louis_Watson