本文整理汇总了C#中Part.AddModule方法的典型用法代码示例。如果您正苦于以下问题:C# Part.AddModule方法的具体用法?C# Part.AddModule怎么用?C# Part.AddModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part.AddModule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addRootPart
void addRootPart(Part root)
{
//Debug.Log (String.Format ("[EL GUI] root: {0}", root));
buildCost = new BuildCost ();
buildCost.addPart (root);
ExShipInfoEventCatcher ec = (ExShipInfoEventCatcher)root.AddModule ("ExShipInfoEventCatcher");
ec.shipinfo = this;
}
示例2: addPart
void addPart(Part part)
{
Debug.Log (String.Format ("[EL GUI] attach: {0}", part));
buildCost.addPart (part);
var ship = EditorLogic.fetch.ship;
parts_count = ship.parts.Count;
ExShipInfoEventCatcher ec = (ExShipInfoEventCatcher)part.AddModule ("ExShipInfoEventCatcher");
ec.shipinfo = this;
}
示例3: AttachCollector
void AttachCollector(Part toPart) {
toPart.AddModule("ModuleExhaustCapture");
ModuleExhaustCapture newModule = toPart.FindModuleImplementing<ModuleExhaustCapture>();
ModuleResource outPutRes = new ModuleResource();
if (primaryResourceName != null && primaryResourceRate != 0 && PartResourceLibrary.Instance.resourceDefinitions.Contains(primaryResourceName))
{
outPutRes.name = primaryResourceName;
outPutRes.id = PartResourceLibrary.Instance.GetDefinition(primaryResourceName).id; //Do I need this
outPutRes.rate = primaryResourceRate*thrustMultiplier;
newModule.outputResources.Add(outPutRes);
print("PZER: Capture " + outPutRes.name + " " + outPutRes.id + " added with a real rate of " + outPutRes.rate * thrustMultiplier);
}
else
{
print("PZER: " + part.partName + " has bad primary resource/rate: " + primaryResourceName +" rate: " + primaryResourceRate);
}
if (secondaryResourceName != null && secondaryResourceRate != 0 && PartResourceLibrary.Instance.resourceDefinitions.Contains(secondaryResourceName)) {
outPutRes.name = secondaryResourceName;
outPutRes.id = PartResourceLibrary.Instance.GetDefinition(secondaryResourceName).id; //see above
outPutRes.rate = secondaryResourceRate * thrustMultiplier;
newModule.outputResources.Add(outPutRes);
print("PZER: Secondary capture " + outPutRes.name + " " + outPutRes.id + " added with a real rate of " + outPutRes.rate * thrustMultiplier);
}
else
{
print("PZER: " + part.partName + " has bad secondary resource/rate: " + secondaryResourceName + " rate: " + secondaryResourceRate);
}
newModule.heatIncrease = (float)additionalHeatRate;
}
示例4: PartUnpacked
public void PartUnpacked(Part part)
{
if (HighLogic.LoadedSceneIsFlight == false)
return;
WBIExtractionMonitor extractionMonitor = null;
if (part.FindModuleImplementing<ModuleResourceHarvester>() == null)
return;
//Add an extraction monitor if needed.
extractionMonitor = part.FindModuleImplementing<WBIExtractionMonitor>();
if (extractionMonitor == null)
{
extractionMonitor = (WBIExtractionMonitor)part.AddModule("WBIExtractionMonitor");
extractionMonitor.OnActive();
extractionMonitor.OnStart(PartModule.StartState.Landed);
extractionMonitor = null;
}
}
示例5: AddPartModule
private void AddPartModule(Part part)
{
try
{
if (!part.Modules.Contains("LifeSupportModule"))
{
Debug.Log("TAC missing!");
ConfigNode node = new ConfigNode("MODULE");
node.AddValue("name", "LifeSupportModule");
part.AddModule(node);
}
else
{
Debug.Log("TAC already there!");
}
}
catch (Exception ex)
{
Debug.LogError("TAC Life Support (AddLifeSupport) [" + this.GetInstanceID().ToString("X") + "][" + Time.time
+ "]: Failed to add the part module: " + ex.Message + "\n" + ex.StackTrace);
}
}
示例6: AddLaunchClampReinforcementModule
public static void AddLaunchClampReinforcementModule(Part p)
{
p.AddModule("KJRLaunchClampReinforcementModule");
(p.Modules["KJRLaunchClampReinforcementModule"] as KJRLaunchClampReinforcementModule).OnPartUnpack();
if (debug)
Debug.Log("Added KJRLaunchClampReinforcementModule to part " + p.partInfo.title);
}
示例7: AddDecouplerJointReinforcementModule
public static void AddDecouplerJointReinforcementModule(Part p)
{
p.AddModule("KJRDecouplerReinforcementModule");
(p.Modules["KJRDecouplerReinforcementModule"] as KJRDecouplerReinforcementModule).OnPartUnpack();
if (debug)
Debug.Log("Added KJRDecouplerReinforcementModule to part " + p.partInfo.title);
}
示例8: EvaAddPartModule
private void EvaAddPartModule(Part part)
{
try
{
ConfigNode node = new ConfigNode("MODULE");
node.AddValue("name", "LifeSupportModule");
part.AddModule(node);
}
catch (Exception ex)
{
this.LogError("Error adding the part module to EVA (expected?): " + ex.Message + "\n" + ex.StackTrace);
}
}
示例9: AddPartModule
private void AddPartModule(Part part)
{
try
{
if (!part.Modules.Contains("LifeSupportModule"))
{
this.Log("The LifeSupportModule is missing!");
ConfigNode node = new ConfigNode("MODULE");
node.AddValue("name", "LifeSupportModule");
part.AddModule(node);
}
else
{
this.Log("The LifeSupportModule is already there.");
}
}
catch (Exception ex)
{
this.LogError("Error adding the Part Module (expected?): " + ex.Message + "\n" + ex.StackTrace);
}
}
示例10: InstantiateHandler
private static bool InstantiateHandler(ConfigNode node, Part ourPart, out Func<string, object> handlerFunction)
{
handlerFunction = null;
var handlerConfiguration = new ConfigNode("MODULE");
node.CopyTo(handlerConfiguration);
string moduleName = node.GetValue("name");
string methodName = node.GetValue("method");
// Since we're working with part modules here, and starting in a pod config,
// we'll keep one instance per pod, which will let them instantiate with their own config if needed.
MonoBehaviour thatModule = null;
foreach (PartModule potentialModule in ourPart.Modules)
{
if (potentialModule.ClassName == moduleName)
{
thatModule = potentialModule;
break;
}
}
if (thatModule == null)
{
try
{
thatModule = ourPart.AddModule(handlerConfiguration);
}
catch
{
JUtil.LogErrorMessage(null, "Caught exception when trying to instantiate module '{0}'. Something's fishy here", moduleName);
}
}
if (thatModule == null)
{
JUtil.LogMessage(null, "Warning, variable handler module \"{0}\" could not be loaded. This could be perfectly normal.", moduleName);
return false;
}
foreach (MethodInfo m in thatModule.GetType().GetMethods())
{
if (m.Name == node.GetValue("method"))
{
try
{
handlerFunction = (Func<string, object>)Delegate.CreateDelegate(typeof(Func<string, object>), thatModule, m);
}
catch
{
JUtil.LogErrorMessage(null, "Error, incorrect variable handler configuration for module {0}", moduleName);
return false;
}
break;
}
}
return true;
}
示例11: addUsageModulesToPart
public static void addUsageModulesToPart(Part part)
{
// list of modules to add as a string
string addModules = "";
// check part resources
foreach (PartResource resource in part.Resources)
{
// electric batteries (ignore empty batts, probably alternator)
if (resource.resourceName == "ElectricCharge" &&
resource.maxAmount > 0.0 && resource.hideFlow == false)
{
addModules += "usageBatteries;";
}
}
// check part modules
bool addUsagePods = (part.CrewCapacity > 0);
foreach (PartModule module in part.Modules)
{
// add engine usage
if (module is ModuleEngines)
{
addModules += "usageEngines;";
}
// add gimbal usage
else if (module is ModuleGimbal)
{
addModules += "usageGimbal;";
}
// add crewed command pod usage
else if (module is ModuleCommand)
{
addModules += "usagePods;";
addUsagePods = false;
}
// add crewed command pod usage
else if (module is ModuleReactionWheel)
{
addModules += "usageReactionWheels;";
}
}
// add other modules based on part parameters
if (addUsagePods)
{
addModules += "usagePods;";
}
// add generic time usage (aging) for unknown part if no other modules were added
if (addModules.Length == 0)
{
KerbalGUIManager.print("Adding usageGeneric to " + part.partInfo.name);
part.AddModule("usageGeneric");
}
// add known modules
else
{
string[] modulesIds = addModules.Split(new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries);
foreach (string moduleId in modulesIds)
{
KerbalGUIManager.print("Adding " + moduleId + " to " + part.partInfo.name);
part.AddModule(moduleId);
}
}
}
示例12: Attach
private bool Attach(Part part)
{
bool attached = false;
List<string> toAttach = new List<string>();
// print("scanning " + part.name + " for needed attachments");
foreach (PartModule pm in part.Modules)
{
foreach (Attachment attach in attachments.FindAll(a => a.attachTo == pm.moduleName && !part.Modules.Contains(a.moduleName)))
{
if (attach.RestrictionsMet(part))
{
toAttach.Add(attach.moduleName);
}
}
}
foreach (string a in toAttach)
{
print("Attaching " + a + " to " + part.name);
var pm = part.AddModule(a);
attached = true;
}
return attached;
}
示例13: canDamage
private bool canDamage(Part p)
{
if(hasModule(p, "ModuleGimbal")) {
// engine gimbal damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleEngines")) {
// engine damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleParachute")) {
// parachute damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleDecouple") || hasModule(p, "ModuleAnchoredDecoupler")) {
// decoupler damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleDockingNode")) {
// docking port damage
p.AddModule("DamageTestModule");
return true;
}
if(p.Resources.Count > 0) {
// fuel tank damage
Debug.Log("Found a fuel tank");
addPartModule(p, "DamageTestModule");
return true;
}
if(hasModule(p, "ModuleResourceIntake")) {
// intake damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleWheel")) {
// wheel damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleEnviroSensor")) {
// sensor damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleDeployableSolarPanel")) {
// solar panel damage
p.AddModule("DamageTestModule");
return true;
}
if(hasModule(p, "ModuleGenerator")) {
// generator damage
p.AddModule("DamageTestModule");
return true;
}
return false;
}
示例14: addPartModule
private void addPartModule(Part p, string module)
{
try {
ConfigNode node = new ConfigNode("MODULE");
node.AddValue("name", module);
p.AddModule(node);
} catch(Exception e) {
Debug.Log("PartDamage: Failed to add PartModule" + module + "--> " + e.Message + "\n" + e.StackTrace);
}
}
示例15: EvaAddPartModule
private void EvaAddPartModule(Part part)
{
try
{
ConfigNode node = new ConfigNode("MODULE");
node.AddValue("name", "LifeSupportModule");
part.AddModule(node);
this.LogWarning("The expected exception did not happen when adding the Life Support part module to the EVA!");
}
catch (Exception ex)
{
if (ex.Message.Contains("Object reference not set"))
{
this.Log("Adding life support to the EVA part succeeded as expected.");
}
else
{
this.LogError("Unexpected error while adding the Life Support part module to the EVA: " + ex.Message + "\n" + ex.StackTrace);
}
}
}