Cheers! I had a two enums, describing my entityes: Players and guns types:
public enum PlayersType {
Scout,
Tank
}
public enum GunsType {
Machinegun,
Tesla
}
I had a generic a struct generic class, and 2 realizations of it:
public class EntityType<T> where T: struct, IConvertible {
public GameObjectType ObjectType;
}
public class PlayerEntity: EntityType<PlayersType> { }
public class TowerEntity: EntityType<GunsType> { }
And i want to create class, who has EntityType field and inherite ScriptableObject class.
I did this:
public class ObjectTypeConfig: ScriptableObject
{
public EntityType<Enum> EntityType;
}
But its return error:
The type 'System.Enum' must be a non-nullable value type in order to use it as type parameter `T' in the generic type or method.
Does anyone know how can i create necessary field? As a result i'm want to create Class, who will be has a Array of ObjectTypeConfigs, containing Players and Towers Entitiyes.
-
Did any of the following answers helped you understand and solve the problem?Gilad Green– Gilad Green2017年10月15日 09:02:54 +00:00Commented Oct 15, 2017 at 9:02
2 Answers 2
You declared the property as EntityType<Enum> but EntityType has the generic constraint of EntityType<T> where T : struct.
The struct constraint means:
The type argument must be a value type. Any value type except Nullable can be specified
If You check Enum you see it is a class - and therefore can be assigned null and fails the generic constraints specified.
I suspect you want one of two:
- Change property to be
EntityType<GunsType>orEntityType<PlayersType> - Make the
ObjectTypeConfigclass generic too with the same constraints and thenEntityType<T> EntityType
Comments
public class ObjectTypeConfig<T>: ScriptableObject where T: struct, IConvertible
{
public EntityType<T> EntityType;
}