新机械体
This commit is contained in:
@@ -6,6 +6,7 @@ namespace WulaFallenEmpire
|
||||
public class Skyfaller_PrefabSpawner : Skyfaller
|
||||
{
|
||||
public string prefabDefName;
|
||||
private Faction prefabFaction; // 缓存派系信息
|
||||
|
||||
protected override void SpawnThings()
|
||||
{
|
||||
@@ -23,8 +24,30 @@ namespace WulaFallenEmpire
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取派系信息
|
||||
Faction faction = GetPrefabFaction();
|
||||
|
||||
// Correct parameter order based on compiler error: prefabDef, map, position, rotation
|
||||
PrefabUtility.SpawnPrefab(prefabDef, base.Map, base.Position, base.Rotation);
|
||||
PrefabUtility.SpawnPrefab(prefabDef, base.Map, base.Position, base.Rotation, faction);
|
||||
}
|
||||
|
||||
private Faction GetPrefabFaction()
|
||||
{
|
||||
// 如果已经缓存了派系信息,直接返回
|
||||
if (prefabFaction != null)
|
||||
return prefabFaction;
|
||||
|
||||
// 检查是否有 CompSkyfallerFaction 组件
|
||||
var factionComp = this.TryGetComp<CompSkyfallerFaction>();
|
||||
if (factionComp != null)
|
||||
{
|
||||
prefabFaction = factionComp.GetFactionForPrefab();
|
||||
return prefabFaction;
|
||||
}
|
||||
|
||||
// 如果没有组件,默认使用玩家派系
|
||||
prefabFaction = Faction.OfPlayer;
|
||||
return prefabFaction;
|
||||
}
|
||||
|
||||
public override void ExposeData()
|
||||
@@ -33,4 +56,4 @@ namespace WulaFallenEmpire
|
||||
Scribe_Values.Look(ref prefabDefName, "prefabDefName");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompProperties_SkyfallerFaction : CompProperties
|
||||
{
|
||||
public FactionDef factionDef;
|
||||
public bool usePlayerFactionIfNull = true; // 如果 factionDef 为 null 时使用玩家派系
|
||||
|
||||
public CompProperties_SkyfallerFaction()
|
||||
{
|
||||
compClass = typeof(CompSkyfallerFaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompSkyfallerFaction : ThingComp
|
||||
{
|
||||
public CompProperties_SkyfallerFaction Props => (CompProperties_SkyfallerFaction)props;
|
||||
|
||||
public Faction GetFactionForPrefab()
|
||||
{
|
||||
// 如果指定了派系定义,使用该派系
|
||||
if (Props.factionDef != null)
|
||||
{
|
||||
Faction faction = Find.FactionManager.FirstFactionOfDef(Props.factionDef);
|
||||
if (faction != null)
|
||||
return faction;
|
||||
}
|
||||
|
||||
// 如果没有指定派系定义,根据设置决定
|
||||
if (Props.usePlayerFactionIfNull)
|
||||
{
|
||||
return Faction.OfPlayer;
|
||||
}
|
||||
|
||||
// 如果都不满足,返回 null(使用默认行为)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user