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); }