Game.Prefabs.SelectedSoundData
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary:
A lightweight ECS component that stores a reference to an Entity representing the currently selected sound for a prefab or UI element. Typically used in prefab or selection systems to remember which sound entity is chosen so other systems can read/play/update that sound. The component is a plain data container with no behavior.
Fields
public Unity.Entities.Entity m_selectedSound
Holds the Entity reference for the selected sound. May be Entity.Null to indicate no selection. When used in systems, check for Entity.Null before attempting to use the entity (e.g., to play audio or retrieve additional components).
Properties
- (none)
This struct exposes its data via a public field and does not define properties.
Constructors
public SelectedSoundData()
Default value-type constructor provided by C#. Use an object initializer to set m_selectedSound when creating an instance. Example:new SelectedSoundData { m_selectedSound = someEntity }
.
Methods
- (none)
This type contains only data and implements marker interfaces for use with the Unity DOTS query system.
Usage Example
using Unity.Entities;
[UpdateInGroup(typeof(SimulationSystemGroup))]
public partial class SelectedSoundExampleSystem : SystemBase
{
protected override void OnCreate()
{
base.OnCreate();
// Example of adding the component to an entity (e.g., a prefab entity)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity prefabEntity = /* obtain or create prefab entity */;
var soundEntity = /* obtain or create sound entity */;
var data = new Game.Prefabs.SelectedSoundData { m_selectedSound = soundEntity };
if (!entityManager.HasComponent<Game.Prefabs.SelectedSoundData>(prefabEntity))
{
entityManager.AddComponentData(prefabEntity, data);
}
else
{
entityManager.SetComponentData(prefabEntity, data);
}
}
protected override void OnUpdate()
{
// Reading the selected sound in a jobified ForEach
Entities
.WithName("UseSelectedSound")
.ForEach((ref Game.Prefabs.SelectedSoundData selected) =>
{
var soundEntity = selected.m_selectedSound;
if (soundEntity != Entity.Null)
{
// Use soundEntity: play sound, update parameters, etc.
}
}).Schedule();
}
}
Notes: - Because this is an IComponentData, it is meant for use with Unity's Entities API (DOTS). - Being an IQueryTypeParameter may allow this type to be used in certain query APIs as a parameter marker; consult the specific DOTS version docs for query usage patterns.