My problem is very specific and difficult to search for, so I have not been successful so far. I have been thinking about this special problem of mine for a while now but I don't seem to be intelligent enough. Maybe someone else is:
This is supposed to be a statemachine for a Unity-Game with a Game class managing the levels by using a simple StateMachine taking the type of its states as a generic parameter. It gets complicated when I am adding an In-Game script SceneMaster to the structure which is a StateMachine itself.
Level (State of LevelMachine) should have a SceneMaster as an Actor but LevelMachine should not care about what specific type the LevelStates (states of Level) are.
Enough talk, maybe someone even has a more logical and simpler solution. Thanks a lot in advance for any help
//LevelMachine takes States of type Level
public class LevelMachine : StateMachine<Level> {} //<---here is the problem, I don't want Level to be generic here
//Level is a State of LevelMachine, Level should be acting on a LevelMaster
public abstract class Level<S> : StateObject<LevelMaster<S>> where S : LevelMaster<S> {}
public interface ILevelMaster : IStateObject {}
//LevelMaster itself is a StateMachine as well, it takes states of type LevelState
public abstract class LevelMaster<S> : StateMachine<LevelState<S>>, ILevelMaster where S : ILevelMaster {}
//StateObject takes an Actor of type LevelMaster
public abstract class LevelState<A> : StateObject<A> where A : LevelMaster<A> {}
public class Level01_State : LevelState<Level01_Master> {
public Level01_State (Level01_Master actor) : base (actor) {}
}
public class Level01_Master : SceneMaster<Level01_Master> {}
public class LEVEL01 : Level<Level01_Master> {
public void Act () {
Debug.Log (Actor); //Actor is supposed to be of type Level01_Master
}
}
public class Game {
//levelMachine should not care about what kinds of LevelStates the Levels in it take
public static LevelMachine levelMachine = new LevelMachine();
public static initialize() {
levelMachine.AddState (new LEVEL01());
}
}
to make it non-generic (which I need for LevelMachine) ended up incompatible in one or the other spot. So now I opted dirty adding a var of type S in Level– RodK Aug 13 '14 at 19:10which is assigned in a method receiving a ILevelMaster, by casting to S. Anyway, Thanks a bunch!