/// <summary> /// Adds ElementConsumer range previews to the specified building def. /// </summary> /// <param name="def">The preview to add.</param> private static void AddConsumerPreview(BuildingDef def) { GameObject complete = def.BuildingComplete, preview = def.BuildingPreview, inBuild = def.BuildingUnderConstruction; var consumers = complete.GetComponents <ElementConsumer>(); int n = consumers.Length; var existing = DictionaryPool <CellOffset, int, ElementConsumer> .Allocate(); foreach (var consumer in consumers) { // Avoid stomping the range preview of Wall Vents and Pumps if (consumer.GetType().FullName != IGNORE_WALLPUMPS) { int radius = consumer.consumptionRadius & 0xFF; var sco = consumer.sampleCellOffset; var color = Color.white; var offset = new CellOffset(Mathf.RoundToInt(sco.x), Mathf.RoundToInt( sco.y)); // Make secondary consumers a color related to their element if (n > 1 && consumer.configuration == ElementConsumer.Configuration. Element) { var target = ElementLoader.FindElementByHash(consumer. elementToConsume); if (target != null) { color = target.substance.conduitColour; } } if (!existing.TryGetValue(offset, out int oldRad) || radius != oldRad) { PUtil.LogDebug("Visualizer added to {0}, range {1:D}".F(def.PrefabID, radius)); ElementConsumerVisualizer.Create(complete, offset, radius, color); // Consumer found, update the preview and under construction versions if (preview != null) { // Previews should always be white as other colors are hard to see // on overlays ElementConsumerVisualizer.Create(preview, offset, radius); } if (inBuild != null) { ElementConsumerVisualizer.Create(inBuild, offset, radius, color); } existing[offset] = radius; } } } existing.Recycle(); }
/// <summary> /// Adds ElementConsumer range previews to the specified building def. /// </summary> /// <param name="def">The preview to add.</param> private static void AddConsumerPreview(BuildingDef def) { GameObject complete = def.BuildingComplete, preview = def.BuildingPreview, inBuild = def.BuildingUnderConstruction; // Check the complete building for a consumer foreach (var consumer in complete.GetComponents <ElementConsumer>()) { // Avoid stomping the range preview of Wall Vents and Pumps if (consumer.GetType().FullName != IGNORE_WALLPUMPS) { int radius = consumer.consumptionRadius & 0xFF; var sco = consumer.sampleCellOffset; var color = Color.white; var offset = new CellOffset(Mathf.RoundToInt(sco.x), Mathf.RoundToInt( sco.y)); // Special case: make the algae terrarium's secondary consumer blue if (radius == 1 && def.PrefabID == AlgaeHabitatConfig.ID) { color = TERRARIUM_SECONDARY; } PUtil.LogDebug("Visualizer added to {0}, range {1:D}".F(def.PrefabID, radius)); ElementConsumerVisualizer.Create(complete, offset, radius, color); // Consumer found, update the preview and under construction versions if (preview != null) { ElementConsumerVisualizer.Create(preview, offset, radius, color); } if (inBuild != null) { ElementConsumerVisualizer.Create(inBuild, offset, radius, color); } } } }