Skip to content

Game.Prefabs.ResourcePrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: PrefabBase

Summary:
Represents a resource "prefab" used by the game's economy systems. This class stores configuration for a single resource type (visual color, editor reference, economy flags, weight, price, consumption/age modifiers and production requirements). The prefab informs both editor UI and runtime systems. At runtime the prefab contributes an ECS component (ResourceData) to entities representing the resource so relevant systems can read resource properties.


Fields

  • public UnityEngine.Color m_Color
    Color used for UI/visualization of the resource. Marked [SerializeField] so it is editable in the inspector. Typically used by UI lists, icons and in-game overlays to visually distinguish this resource.

  • public ResourceInEditor m_Resource
    Editor-side reference describing the resource. Likely contains localized name, icon and other editor metadata. This ties the prefab to the resource definition used by tools and the editor.

  • public bool m_IsProduceable
    If true the resource can be produced by industries/production buildings. Controls whether production systems consider this resource as a producible output.

  • public bool m_IsTradable
    If true the resource can be bought/sold on trade markets / by trading buildings and vehicles. Controls trading logic and whether commercial/industrial/trader entities include it.

  • public bool m_IsMaterial
    Marks the resource as a raw or intermediate material (versus e.g. a finished good or service). Used by production/processing logic to differentiate material flow.

  • public bool m_IsLeisure
    Indicates the resource is a leisure/good consumption type rather than an industrial/commercial material. Affects household consumption behavior and possibly commercial demand.

  • public float m_Weight
    The physical weight of a single unit of the resource. Determines how many units a cargo vehicle can carry (vehicle capacity calculations use this value).

  • public Unity.Mathematics.float2 m_InitialPrice
    Initial pricing vector: x = initial selling price for the resource; y = initial profit amount a Commercial company receives when selling this resource. Expressed as a float2 (Unity.Mathematics).

  • public float m_WealthModifier
    How much household wealth influences the probability of shopping for this resource. Higher values increase sensitivity of demand to household wealth.

  • public float m_BaseConsumption
    Base chance/weight for households to consume/purchase this resource. Higher values increase general baseline demand.

  • public int m_CarConsumption
    Additional consumption weight contributed when a household has a vehicle; typically multiplied by the number of vehicles in the household. Expressed as an integer.

  • public int m_ChildWeight
    Relative importance (weight) of consumption by Children.

  • public int m_TeenWeight
    Relative importance (weight) of consumption by Teens.

  • public int m_AdultWeight
    Relative importance (weight) of consumption by Adults.

  • public int m_ElderlyWeight
    Relative importance (weight) of consumption by Seniors/Elderly.

  • public bool m_RequireTemperature
    If checked/true, producing this resource requires the ambient temperature to be at or above m_RequiredTemperature.

  • public float m_RequiredTemperature
    Minimum ambient temperature required for production when m_RequireTemperature is true.

  • public bool m_RequireNaturalResource
    If true, producing this resource requires the presence of a natural resource (e.g., Fertile Land, Forest, Ore, Oil). Controls which map tiles/locations can produce the resource.

  • public Unity.Mathematics.int2 m_NeededWorkPerUnit = 1
    Work requirement per produced unit, expressed as an int2. Typically encodes two different work types (for example x = industrial-type work required, y = commercial-type/service work required). Default initialized to 1.

Notes: Many fields have [Tooltip] attributes in the source to explain editor semantics; those tooltips are preserved in the inspector for designers.

Properties

  • This class does not declare any C# properties. All configuration is exposed via public fields (serialized for the Unity inspector) and via the prefab/component mechanism.

Constructors

  • public ResourcePrefab()
    No explicit constructor is defined in the source; the default parameterless constructor from C# is used. Instances are typically created/edited in the Unity editor (ScriptableObject/MonoBehaviour prefabs) rather than constructed manually at runtime.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Override that contributes the runtime ECS components this prefab requires. Implementation:
  • Calls base.GetPrefabComponents(components).
  • Adds ComponentType.ReadWrite() to the provided components set. This ensures that entities instantiated from this prefab will include the ResourceData component so ECS systems can access resource configuration at runtime.

Usage Example

// Create and configure a resource prefab instance (typical usage in editor scripts or mods)
var myResource = ScriptableObject.CreateInstance<Game.Prefabs.ResourcePrefab>();
myResource.name = "Berry";
myResource.m_Color = UnityEngine.Color.magenta;
myResource.m_Resource = /* assign a ResourceInEditor reference from assets */;
myResource.m_IsProduceable = true;
myResource.m_IsTradable = true;
myResource.m_Weight = 0.5f;
myResource.m_InitialPrice = new Unity.Mathematics.float2(2.0f, 0.5f);
myResource.m_BaseConsumption = 1.0f;
myResource.m_WealthModifier = 0.2f;
myResource.m_CarConsumption = 1;
myResource.m_ChildWeight = 5;
myResource.m_TeenWeight = 3;
myResource.m_AdultWeight = 2;
myResource.m_ElderlyWeight = 1;
myResource.m_RequireNaturalResource = true;
myResource.m_NeededWorkPerUnit = new Unity.Mathematics.int2(1, 0);

// At runtime, entities created from this prefab will include ResourceData
// because GetPrefabComponents adds ComponentType.ReadWrite<ResourceData>().

Additional tips for modders: - Most fields are serialized for the Unity inspector — prefer editing via the prefab asset in the editor when possible so tooltips and serialization behave correctly. - The ResourceData component is the runtime bridge: to change how systems consume/produce resources you may need to extend or read ResourceData in relevant ECS systems. - Use m_NeededWorkPerUnit to balance production between industry and commercial workflows (x/y elements typically map to different job systems).