Game.Prefabs.BrandPrefab
Assembly:
Assembly-CSharp (typical game assembly; the class is defined in the game's primary assembly)
Namespace: Game.Prefabs
Type:
class
Base:
PrefabBase
Summary:
BrandPrefab is a prefab class used to define a "brand" in the Companies/brands system. It holds references to CompanyPrefabs that belong to the brand and a palette of Colors (m_BrandColors) which are copied into the ECS BrandData component when the prefab is initialized. The class also declares its dependency on the BrandData component so the prefab system knows which components the resulting entity will require. The ComponentMenu attribute places this prefab under the "Companies/" menu in the editor.
Fields
-
public CompanyPrefab[] m_Companies
Array of CompanyPrefab references that belong to this brand. Used by GetDependencies to add those prefabs as dependencies so they are loaded/created together with the brand. -
public Color[] m_BrandColors
Array of UnityEngine.Color values representing the brand color palette. During Initialize these colors are copied into the BrandData component on the entity created from this prefab. Ensure the BrandData.m_ColorSet has capacity >= m_BrandColors.Length to avoid index issues.
Properties
- (none)
Constructors
public BrandPrefab()
Default parameterless constructor inherited from PrefabBase/UnityEngine.Object. No custom construction logic in this class.
Methods
public override void GetDependencies(List<PrefabBase> prefabs)
Adds any required prefabs to the provided list. Implementation:- Calls base.GetDependencies(prefabs).
-
Iterates m_Companies and adds each CompanyPrefab to the prefabs list. Use: ensures company prefabs are considered dependencies of this brand prefab.
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Registers ECS component types required by this prefab. Implementation: - Calls base.GetPrefabComponents(components).
-
Adds ComponentType.ReadWrite
() to the components set. Use: informs the prefab-to-entity creation system that entities spawned from this prefab will include a BrandData component. -
public override void Initialize(EntityManager entityManager, Entity entity)
Initializes ECS component data on the created entity. Implementation: - Calls base.Initialize(entityManager, entity).
- Creates a default BrandData struct.
- Copies each Color from m_BrandColors into componentData.m_ColorSet at the corresponding index.
- Calls entityManager.SetComponentData(entity, componentData). Notes:
- No bounds checking is performed when copying colors; ensure componentData.m_ColorSet is large enough and m_BrandColors is not longer than the component's color array.
- Assumes entity already has BrandData component type (which GetPrefabComponents registers).
Usage Example
// Example: typical prefab initialization is handled by the prefab system.
// This example demonstrates what Initialize does: copying colors into BrandData.
public class ExampleUsage
{
void SetupBrandEntity(EntityManager entityManager, Entity brandEntity, BrandPrefab prefab)
{
// Prefab.Initialize would normally be called by the prefab system.
// Calling it directly to illustrate behavior:
prefab.Initialize(entityManager, brandEntity);
// After Initialize, the entity's BrandData will contain the colors from prefab.m_BrandColors.
BrandData data = entityManager.GetComponentData<BrandData>(brandEntity);
// Use data.m_ColorSet as needed...
}
}
Notes and Tips: - The ComponentMenu attribute (ComponentMenu("Companies/", new Type[] { })) places this prefab under Companies/ in Unity's component/prefab menu — useful for editor organization. - Ensure m_Companies and m_BrandColors are assigned in the prefab asset; null or empty arrays will result in no dependencies or colors copied. - Be careful with the fixed-size nature of BrandData.m_ColorSet (if fixed): mismatched lengths can cause out-of-range writes—validate sizes or add guards if modifying Initialize.