/// <summary> /// Gets the value of a singleton component. /// </summary> /// <typeparam name="T">The <see cref="IComponentData"/> subtype of the singleton component.</typeparam> /// <returns>The component.</returns> /// <seealso cref="EntityQuery.GetSingleton{T}"/> public static T GetSingleton <T>(this ComponentSystemBase sys) where T : class, IComponentData { var type = ComponentType.ReadOnly <T>(); var query = sys.GetSingletonEntityQueryInternal(type); return(query.GetSingleton <T>()); }
/// <summary> /// Sets the value of a singleton component. /// </summary> /// <param name="value">A component containing the value to assign to the singleton.</param> /// <typeparam name="T">The <see cref="IComponentData"/> subtype of the singleton component.</typeparam> /// <seealso cref="EntityQuery.SetSingleton{T}"/> public static void SetSingleton <T>(this ComponentSystemBase sys, T value) where T : class, IComponentData { var type = ComponentType.ReadWrite <T>(); var query = sys.GetSingletonEntityQueryInternal(type); query.SetSingleton(value); }
/// <summary> /// Checks whether a singelton component of the specified type exists. /// </summary> /// <typeparam name="T">The <see cref="IComponentData"/> subtype of the singleton component.</typeparam> /// <returns>True, if a singleton of the specified type exists in the current <see cref="World"/>.</returns> public static bool HasSingleton <T>(this ComponentSystemBase sys) where T : class, IComponentData { var type = ComponentType.ReadOnly <T>(); var query = sys.GetSingletonEntityQueryInternal(type); return(query.CalculateEntityCount() == 1); }