Game.RandomLikeCount
Assembly:
Assembly-CSharp
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase
Summary:
RandomLikeCount is a prefab helper component used by the Chirp/ social-post prefab pipeline to configure how many "likes" a chirp will receive at runtime. Values set in the inspector are copied into the ECS component RandomLikeCountData during LateInitialize so systems can use deterministic/randomized data for simulating likes, viral behavior and time-based activity.
Fields
-
public float m_EducatedPercentage
Percentage of educated people who will give a like. Exposed in the inspector with a Range(0,1). Default: 0.8. -
public float m_UneducatedPercentage
Percentage of uneducated people who will give a like. Exposed in the inspector with a Range(0,1). Default: 0.5. -
public float2 m_ActiveDays
A float2 pair defining the minimum and maximum days (or normalized day range) during which the like count will actively increase. Default: float2(0.1f, 1f). Tooltip: "The like count of the chirp will actively increase during these days". -
public int2 m_GoViralFactor
An int2 pair (min,max) defining the "go viral" multiplier/factor applied at the beginning when a chirp goes viral. Default: int2(20, 60). Tooltip: "Go viral means the like count will increase significantly at the beginning in short time". -
public float2 m_RandomAmountFactor
A float2 pair (min,max) used to add randomness to the amount of likes produced. Default: float2(0.01f, 0.8f). Tooltip: "Use random amount factor to make the like amount result more randomly)". -
public float m_ContinuousFactor
A float value in [0,1) that controls whether the like count changes appear continuous or discrete. Default: 0.2. Tooltip: "Use continuous factor to make the like count change continuous of not continuous, value belong to random[0,1))". -
Attributes on fields (Inspector metadata)
Each public field carries Unity attributes: Tooltip(...) and for the percentage fields Range(0f, 1f). These make the fields editable and self-documented in the Unity Inspector.
Properties
- This component exposes no properties (only public fields and inherited members).
Constructors
public RandomLikeCount()
Implicit default constructor. This MonoBehaviour-style prefab component relies on field values set in the inspector; no custom construction logic is declared in the source.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Registers the runtime ECS component this prefab will add to prefab entities. Implementation adds ComponentType.ReadWrite() so the RandomLikeCountData struct is present on the prefab entity. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Declared override but empty in this class. Leave blank if no additional archetype components are required at archetype creation time. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Copies the inspector-configured values into a RandomLikeCountData instance and writes it to the provided entity using entityManager.SetComponentData(entity, componentData). This is the bridge from the MonoBehaviour prefab to the ECS world. The method copies: - m_EducatedPercentage
- m_UneducatedPercentage
- m_GoViralFactor
- m_ActiveDays
- m_RandomAmountFactor
- m_ContinuousFactor
Notes: - The code depends on the existence of a RandomLikeCountData ECS IComponentData struct with matching fields. Ensure that type is defined and included in the prefab archetype (GetPrefabComponents registers it). - This component is intended to be placed on a prefab asset (ChirpPrefab) so that when the prefab is instantiated, its ECS counterpart receives these configuration values.
Usage Example
// This is essentially what RandomLikeCount does in LateInitialize.
// It shows how the inspector values are copied to the ECS component.
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
var componentData = new RandomLikeCountData
{
m_EducatedPercentage = m_EducatedPercentage,
m_UneducatedPercentage = m_UneducatedPercentage,
m_GoViralFactor = m_GoViralFactor,
m_ActiveDays = m_ActiveDays,
m_RandomAmountFactor = m_RandomAmountFactor,
m_ContinuousFactor = m_ContinuousFactor
};
entityManager.SetComponentData(entity, componentData);
}
Additional tips: - Edit the public fields on the prefab instance in the Unity Inspector to tune social/viral behavior. - Ensure RandomLikeCountData is referenced by your runtime systems that simulate likes so they read these values from the entity and apply the intended randomness/temporal logic.