准备给单元素泵添加多选择项,各位懂得都来指点一下,给点回复反应
目前我做到吸收单种元素的泵,然而每种元素都添加一个很麻烦,我准备改进一下,奈何水平有限组装不成功。单元素泵的灵感来之于空气净化器和碳素过滤器,他们都吸收单一元素然后转换,我就翻查看他们的代码发现
都是用ElementConsumer
ElementConsumer elementConsumer = go.AddOrGet<ElementConsumer>();
elementConsumer.elementToConsume = SimHashes.ContaminatedOxygen;
然后elementToConsume 参数设置不一样
泵也是使用ElementConsumer
ElementConsumer elementConsumer = go.AddOrGet<ElementConsumer>();
elementConsumer.configuration = ElementConsumer.Configuration.AllGas;
不过他在configuration 使用的所有元素,所以我将其改成上面那个成功实现了单元素
这次我又参考了气体过滤器和气体元素传感器,他们都有一个选择菜单
也就是下面这个
go.AddOrGet<Filterable>().filterElementState = Filterable.ElementState.Gas;
LogicElementSensor logicElementSensor = go.AddOrGet<LogicElementSensor>();
logicElementSensor.manuallyControlled = false;
logicElementSensor.desiredState = Element.State.Gas;
我也将其搬到泵上,把选择添加上了如下图,
然后也找到了选择好的参数在那
也就是filterable中的selectedtag
现在问题是如何链接ElementConsumer和selectedtag?
我直接在config中改动,但是更换选择不起效
下面是我造的泵代码
using System;
using TUNING;
using UnityEngine;
public class GasMiniPumpConfig3 : IBuildingConfig
{
public override BuildingDef CreateBuildingDef()
{
string id = "GasMiniPumpC";
int width = 1;
int height = 2;
string anim = "minigaspump_kanim";
int hitpoints = 30;
float construction_time = 60f;
float[] tier = BUILDINGS.CONSTRUCTION_MASS_KG.TIER1;
string[] any_BUILDABLE = MATERIALS.ANY_BUILDABLE;
float melting_point = 1600f;
BuildLocationRule build_location_rule = BuildLocationRule.Anywhere;
EffectorValues tier2 = NOISE_POLLUTION.NOISY.TIER2;
BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(id, width, height, anim, hitpoints, construction_time, tier, any_BUILDABLE, melting_point, build_location_rule, BUILDINGS.DECOR.PENALTY.TIER1, tier2, 0.2f);
buildingDef.PermittedRotations = PermittedRotations.R360;
buildingDef.RequiresPowerInput = true;
buildingDef.EnergyConsumptionWhenActive = 60f;
buildingDef.ExhaustKilowattsWhenActive = 0f;
buildingDef.SelfHeatKilowattsWhenActive = 0f;
buildingDef.OutputConduitType = ConduitType.Gas;
buildingDef.Floodable = true;
buildingDef.ViewMode = OverlayModes.GasConduits.ID;
buildingDef.AudioCategory = "Metal";
buildingDef.PowerInputOffset = new CellOffset(0, 0);
buildingDef.UtilityOutputOffset = new CellOffset(0, 1);
buildingDef.ThermalConductivity = 0f;
buildingDef.LogicInputPorts = LogicOperationalController.CreateSingleInputPortList(new CellOffset(0, 1));
GeneratedBuildings.RegisterWithOverlay(OverlayScreen.GasVentIDs, "GasMiniPumpC");
return buildingDef;
}
public override void DoPostConfigureComplete(GameObject go)
{
go.AddOrGet<LogicOperationalController>();
go.AddOrGet<LoopingSounds>();
go.AddOrGet<EnergyConsumer>();
go.AddOrGet<Pump>();
go.AddOrGet<Storage>().capacityKg = 2100000f;
ElementConsumer elementConsumer = go.AddOrGet<ElementConsumer>();
elementConsumer.elementToConsume = SimHashes.CarbonDioxide;
elementConsumer.consumptionRate = 210000f;
elementConsumer.storeOnConsume = true;
elementConsumer.showInStatusPanel = false;
elementConsumer.consumptionRadius = 36;
ConduitDispenser conduitDispenser = go.AddOrGet<ConduitDispenser>();
conduitDispenser.conduitType = ConduitType.Gas;
conduitDispenser.alwaysDispense = true;
conduitDispenser.elementFilter = null;
go.AddOrGet<Filterable>().filterElementState = Filterable.ElementState.Gas;
LogicElementSensor logicElementSensor = go.AddOrGet<LogicElementSensor>();
logicElementSensor.manuallyControlled = false;
logicElementSensor.desiredState = Element.State.Gas;
go.AddOrGetDef<OperationalController.Def>();
go.GetComponent<KPrefabID>().AddTag(GameTags.OverlayBehindConduits, false);
}
public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag)
{
ElementDropper elementDropper = go.AddComponent<ElementDropper>();
elementDropper.emitMass = 100f;
elementDropper.emitTag = new Tag("Gas");
elementDropper.emitOffset = new Vector3(0f, 1f, 0f);
}
public const string ID = "GasMiniPumpC";
}
我的理念是已有的东西拿来就用,不想去重写,能最小化改动最好不行只好写一个核心
就像Filterable这个液体过滤器,气体过滤器,固体过滤器,气液固管道检测,逻辑里的气液类型检测都是用这个
页:
[1]