游戏达人
  
- 贡献度
- 270
- 金元
- 17914
- 积分
- 2871
- 精华
- 0
- 注册时间
- 2014-11-30
|
本帖最后由 fanvalen 于 2024-7-7 21:55 编辑
先把能量棒做出来添加类复制粘贴编译using System;
using System.Collections.Generic;
using UnityEngine;
public class PowerStickConfig : IEntityConfig
{
public string[] GetDlcIds()
{
return DlcManager.AVAILABLE_ALL_VERSIONS;
}
public GameObject CreatePrefab()
{
return EntityTemplates.CreateLooseEntity("PowerStick", "能量棒", "能量棒中蕴含100千焦的能量可充入电池中使用", 5f, true, Assets.GetAnim("vacillator_charge_kanim"), "object", Grid.SceneLayer.Front, EntityTemplates.CollisionShape.RECTANGLE, 0.8f, 0.6f, true, 0, SimHashes.Creature, new List<Tag>
{
GameTags.IndustrialIngredient
});
}
public void OnPrefabInit(GameObject inst)
{
}
public void OnSpawn(GameObject inst)
{
}
public PowerStickConfig()
{
}
static PowerStickConfig()
{
}
public const string ID = "PowerStick";
public static readonly Tag tag = TagManager.Create("GeneShufflerRecharge");
public const float MASS = 5f;
}
然后我们要修改的是Battery类核心
编辑类添加两个变量
[MyCmpReq
public Storage storage;
public bool IsRechargeable;
public bool IsEmitStick;
添加一个方法
private void OnStorageChange()
{
int num = this.storage.items.Count - 1;
if (num >= 0)
{
GameObject item_go = this.storage.items[num];
if (this.joulesAvailable <= 100000f)
{
this.storage.ConsumeIgnoringDisease(item_go);
this.joulesAvailable += 100000f;
return;
}
}
}
同时修改两个方法
AddEnergy和ConsumeEnergy
由于改动较大直接替换
public void AddEnergy(float joules)
{
this.joulesAvailable = Mathf.Min(this.capacity, this.JoulesAvailable + joules);
this.joulesConsumed += joules;
if (this.IsEmitStick && this.joulesAvailable >= 100002f)
{
GameUtil.KInstantiate(Assets.GetPrefab("PowerStick"), base.transform.position, Grid.SceneLayer.Ore, null, 0).SetActive(true);
this.joulesAvailable -= 100000f;
}
this.ChargeCapacity -= joules;
this.WattsUsed = this.joulesConsumed / this.dt;
}
public void ConsumeEnergy(float joules, bool report = false)
{
if (report)
{
float num = Mathf.Min(this.JoulesAvailable, joules);
ReportManager.Instance.ReportValue(ReportManager.ReportType.EnergyWasted, -num, StringFormatter.Replace(BUILDINGS.PREFABS.BATTERY.CHARGE_LOSS, "{Battery}", this.GetProperName()), null);
}
this.joulesAvailable = Mathf.Max(0f, this.JoulesAvailable - joules);
if (this.IsRechargeable && this.joulesAvailable < 100000f)
{
this.OnStorageChange();
}
}
完成上面操作后保存重新加载一下dll否则另外一个地方无法读取变量
然后就是创建充电电池添加类复制粘贴编译
using System;
using TUNING;
using UnityEngine;
public class BatteryMedium2Config : BaseBatteryConfig
{
public override BuildingDef CreateBuildingDef()
{
string id = "BatteryMedium2";
int width = 1;
int height = 2;
int hitpoints = 30;
string anim = "batterysm_kanim";
float construction_time = 6f;
float[] tier = BUILDINGS.CONSTRUCTION_MASS_KG.TIER4;
string[] all_METALS = MATERIALS.ALL_METALS;
float melting_point = 800f;
float exhaust_temperature_active = 0f;
float self_heat_kilowatts_active = 0f;
EffectorValues tier2 = NOISE_POLLUTION.NOISY.TIER1;
BuildingDef result = base.CreateBuildingDef(id, width, height, hitpoints, anim, construction_time, tier, all_METALS, melting_point, exhaust_temperature_active, self_heat_kilowatts_active, BUILDINGS.DECOR.PENALTY.TIER2, tier2);
SoundEventVolumeCache.instance.AddVolume("batterymed_kanim", "Battery_med_rattle", NOISE_POLLUTION.NOISY.TIER2);
return result;
}
public override void DoPostConfigureComplete(GameObject go)
{
Battery battery = go.AddOrGet<Battery>();
battery.capacity = 200000f;
battery.joulesLostPerSecond = 0f;
battery.IsRechargeable = true;
base.DoPostConfigureComplete(go);
Storage storage = BuildingTemplates.CreateDefaultStorage(go, false);
storage.showInUI = true;
storage.capacityKg = 1f;
storage.SetDefaultStoredItemModifiers(Storage.StandardSealedStorage);
ManualDeliveryKG manualDeliveryKG = go.AddComponent<ManualDeliveryKG>();
manualDeliveryKG.SetStorage(storage);
manualDeliveryKG.RequestedItemTag = new Tag("PowerStick");
manualDeliveryKG.capacity = 2f;
manualDeliveryKG.refillMass = 1f;
manualDeliveryKG.choreTypeIDHash = Db.Get().ChoreTypes.FetchCritical.IdHash;
}
public BatteryMedium2Config()
{
}
public const string ID = "BatteryMedium2";
}
最后一步吧这个充电电池添加到建造菜单
我一般喜欢把它添加到氧气菜单里因为比较少方便找
TUNING.BUILDINGS
new PlanScreen.PlanInfo(new HashedString("Oxygen"), false, new List<string>的末尾添加
"BatteryMedium2"
最后要修改一个电池的容量为150千焦作用是避开其他低端电池,不然每个电池都会产生能量棒导致卡顿这里就把巨型电池作为产生能量棒的工具
BatteryMediumConfig
battery.capacity = 40000f;
改成
battery.capacity = 150000f;
添加一个
battery.IsEmitStick = true;//这句需要保存重新加载才能添加成功
|
|