Skip to main content

PhysicalMaterialPart

A class in Root.Township, the global namespace.

Gives an item its physical material (iron, wood and so on): sets renderer materials, scales impact damage and hardness, updates durability, and syncs and saves the choice. Server picks a random one from its distribution on spawn.

Constructors​

MemberWhat it is
PhysicalMaterialPart()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

9 private and internal fields
MemberWhat it is
private DurabilityModule durabilityModuleParent durability module updated with the new material on every change.
private ImpactGenerator[] impactorsImpact generators whose damage multiplier and hardness level follow the material.
private MonoBehaviour[] listenToPhysicalMaterialComponents implementing IListenToPhysicalMaterial that are told about every material change.
private static Logger loggerNLog logger for this class.
private PhysicalMaterialChannel materialChannelWhich of the material's render materials this part's renderers use.
private Distribution materialDistributionServer: when set, a random material is picked from it by spawn attributes at generation.
private PhysicalMaterial physicalMaterialBacking field for PhysicalMaterial. The inspector value is applied on server start.
private Renderer[] renderersRenderers given the material's render material. Skipped on headless servers.
private MethodSync syncMaterialMethod sync that sends the material hash to chunks on change and to each player on connect.

Properties​

MemberWhat it is
PhysicalMaterial PhysicalMaterial { get; }The item's current physical material.

Events​

MemberWhat it is
event PhysicalMaterialPart.ChangedMaterial MaterialChangedRaised after the material is set, with the material and the channel used.

Methods​

MemberWhat it is
override void Initialize()Creates the material sync.
override void InitializeAsServer(SpawnData spawnData)Server: applies the starting material.
override void OnConnected(Player player)Sends the current material to a joining player.
void SetMaterial(PhysicalMaterial physicalMaterial)Applies a material: impactors, listeners, renderers (not on headless) and durability. Server: syncs to clients. Null is ignored.
protected override void Generate(SpawnData spawnData)Picks a random material from the distribution using the spawn attributes.
7 private and internal methods
MemberWhat it is
private bool Alta.Inventory.IInterfereWithDocking.CheckAllowed(IInterfereWithDocking other)Explicit IInterfereWithDocking method: only allows docking with another part of the same physical material.
private void Alta.Utilities.ISpawnArguments.CheckArguments(string[] arguments)Explicit ISpawnArguments method: sets the material to the first spawn argument that names a physical material.
private bool Alta.Utilities.Atlas.IPreventAtlasing.IsPreventAtlasing(Renderer renderer)Explicit IPreventAtlasing method: true for renderers this part recolours, so they aren't atlased.
private void OnValidate()Empty.
private void IBuildRendererPostBake.PostBake()Explicit build step: strips null entries from renderers.
private void Alta.Networking.IEntityReplaceHandler.ReplacedWith(NetworkEntity entity, ReplaceAvoidFlags replaceAvoidFlags)Explicit IEntityReplaceHandler method: copies this material onto the replacement entity unless the replace is internal.
private void Sync(IPlayer player, Stream stream)Writes the material hash; remote clients read it and call SetMaterial.

Used in​

Members of other types that take, return or hold a PhysicalMaterialPart: