public static DefType AddOrGetDef <DefType>(this GameObject go) where DefType : StateMachine.BaseDef
    {
        StateMachineController stateMachineController = go.AddOrGet <StateMachineController>();
        DefType val = stateMachineController.GetDef <DefType>();

        if (val == null)
        {
            val = Activator.CreateInstance <DefType>();
            stateMachineController.AddDef(val);
            val.Configure(stateMachineController.gameObject);
        }
        return(val);
    }
Beispiel #2
0
        public static void RemoveDef <DefType>(this GameObject go) where DefType : StateMachine.BaseDef
        {
            StateMachineController stateMachineController = go.AddOrGet <StateMachineController>();
            DefType defType = stateMachineController.GetDef <DefType>();

            if (defType != null)
            {
                defType.Configure(null);
                stateMachineController.cmpdef.defs.Remove(defType);

                //defType = Activator.CreateInstance<DefType>();
                //stateMachineController.AddDef(defType);
                //defType.Configure(stateMachineController.gameObject);
            }
        }