当前位置: 首页>>代码示例>>C#>>正文


C# Part.HasModule方法代码示例

本文整理汇总了C#中Part.HasModule方法的典型用法代码示例。如果您正苦于以下问题:C# Part.HasModule方法的具体用法?C# Part.HasModule怎么用?C# Part.HasModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Part的用法示例。


在下文中一共展示了Part.HasModule方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FuelNode

        public FuelNode(Part part)
        {
            bool physicallySignificant = (part.physicalSignificance != Part.PhysicalSignificance.NONE);
            if (part.HasModule<ModuleLandingGear>() || part.HasModule<LaunchClamp>())
            {
                //Landing gear set physicalSignificance = NONE when they enter the flight scene
                //Launch clamp mass should be ignored.
                physicallySignificant = false;
            }
            if (physicallySignificant) dryMass = part.mass;

            inverseStage = part.inverseStage;
            isFuelLine = (part is FuelLine);
            isSepratron = part.IsSepratron();
            partName = part.partInfo.name;

            //note which resources this part has stored
            foreach (PartResource r in part.Resources)
            {
                if (r.info.name != "ElectricCharge") resources[r.info.id] = (float)r.amount;
                resourcesUnobtainableFromParent.Add(r.info.id);
            }

            //record relevant engine stats
            ModuleEngines engine = part.Modules.OfType<ModuleEngines>().FirstOrDefault();
            if (engine != null)
            {
                //Only count engines that either are ignited or will ignite in the future:
                if (HighLogic.LoadedSceneIsEditor || inverseStage < Staging.CurrentStage || engine.getIgnitionState)
                {
                    //if an engine has been activated early, pretend it is in the current stage:
                    if (engine.getIgnitionState && inverseStage < Staging.CurrentStage) inverseStage = Staging.CurrentStage;

                    isEngine = true;

                    maxThrust = engine.maxThrust;
                    ispCurve = engine.atmosphereCurve;

                    propellantSumRatioTimesDensity = engine.propellants.Sum(prop => prop.ratio * MuUtils.ResourceDensity(prop.id));
                    propellantRatios = engine.propellants.Where(prop => prop.name != "ElectricCharge").ToDictionary(prop => prop.id, prop => prop.ratio);
                }
            }

            //figure out when this part gets decoupled. We do this by looking through this part and all this part's ancestors
            //and noting which one gets decoupled earliest (i.e., has the highest inverseStage). Some parts never get decoupled
            //and these are assigned decoupledInStage = -1.
            decoupledInStage = -1;
            Part p = part;
            while (true)
            {
                if (p.IsDecoupler())
                {
                    if (p.inverseStage > decoupledInStage) decoupledInStage = p.inverseStage;
                }
                if (p.parent == null) break;
                else p = p.parent;
            }
        }
开发者ID:Raf04,项目名称:MechJeb2,代码行数:58,代码来源:FuelFlowSimulation.cs

示例2: New

        public static PartSim New(Part p, int id, double atmosphere, LogMsg log)
        {
            PartSim partSim = pool.Borrow();

            partSim.part = p;
            partSim.centerOfMass = p.transform.TransformPoint(p.CoMOffset);
            partSim.partId = id;
            partSim.name = p.partInfo.name;

            if (log != null) log.buf.AppendLine("Create PartSim for " + partSim.name);

            partSim.parent = null;
            partSim.parentAttach = p.attachMode;
            partSim.fuelCrossFeed = p.fuelCrossFeed;
            partSim.noCrossFeedNodeKey = p.NoCrossFeedNodeKey;
            partSim.decoupledInStage = partSim.DecoupledInStage(p);
            partSim.isFuelLine = p.HasModule<CModuleFuelLine>();
            partSim.isFuelTank = p is FuelTank;
            partSim.isSepratron = partSim.IsSepratron();
            partSim.inverseStage = p.inverseStage;
            //MonoBehaviour.print("inverseStage = " + inverseStage);

            partSim.baseCost = p.GetCostDry();

            if (log != null)
            {
                log.buf.AppendLine("Parent part = " + (p.parent == null ? "null" : p.parent.partInfo.name));
                log.buf.AppendLine("physicalSignificance = " + p.physicalSignificance);
                log.buf.AppendLine("PhysicsSignificance = " + p.PhysicsSignificance);
            }

            // Work out if the part should have no physical significance
            // The root part is never "no physics"
            partSim.isNoPhysics = p.physicalSignificance == Part.PhysicalSignificance.NONE ||
                                    p.PhysicsSignificance == 1;

            if (p.HasModule<LaunchClamp>())
            {
                partSim.realMass = 0d;
                if (log != null) log.buf.AppendLine("Ignoring mass of launch clamp");
            }
            else
            {
                partSim.realMass = p.mass;
                if (log != null) log.buf.AppendLine("Using part.mass of " + p.mass);
            }

            partSim.postStageMassAdjust = 0f;
            if (log != null) log.buf.AppendLine("Calculating postStageMassAdjust, prefabMass = " + p.prefabMass);
            int count = p.Modules.Count;
            for (int i = 0; i < count; i++)
            {
                if (log != null) log.buf.AppendLine("Module: " + p.Modules[i].moduleName);
                IPartMassModifier partMassModifier = p.Modules[i] as IPartMassModifier;
                if (partMassModifier != null)
                {
                    if (log != null) log.buf.AppendLine("ChangeWhen = " + partMassModifier.GetModuleMassChangeWhen());
                    if (partMassModifier.GetModuleMassChangeWhen() == ModifierChangeWhen.STAGED)
                    {
                        float preStage = partMassModifier.GetModuleMass(p.prefabMass, ModifierStagingSituation.UNSTAGED);
                        float postStage = partMassModifier.GetModuleMass(p.prefabMass, ModifierStagingSituation.STAGED);
                        if (log != null) log.buf.AppendLine("preStage = " + preStage + "   postStage = " + postStage);
                        partSim.postStageMassAdjust += (postStage - preStage);
                    }
                }
            }
            if (log != null) log.buf.AppendLine("postStageMassAdjust = " + partSim.postStageMassAdjust);

            for (int i = 0; i < p.Resources.Count; i++)
            {
                PartResource resource = p.Resources[i];

                // Make sure it isn't NaN as this messes up the part mass and hence most of the values
                // This can happen if a resource capacity is 0 and tweakable
                if (!Double.IsNaN(resource.amount))
                {
                    if (log != null)
                        log.buf.AppendLine(resource.resourceName + " = " + resource.amount);

                    partSim.resources.Add(resource.info.id, resource.amount);
                    partSim.resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0);
                }
                else
                {
                    if (log != null) log.buf.AppendLine(resource.resourceName + " is NaN. Skipping.");
                }
            }

            partSim.hasVessel = (p.vessel != null);
            partSim.isLanded = partSim.hasVessel && p.vessel.Landed;
            if (partSim.hasVessel)
            {
                partSim.vesselName = p.vessel.vesselName;
                partSim.vesselType = p.vesselType;
            }
            partSim.initialVesselName = p.initialVesselName;

            partSim.hasMultiModeEngine = p.HasModule<MultiModeEngine>();
            partSim.hasModuleEngines = p.HasModule<ModuleEngines>();

//.........这里部分代码省略.........
开发者ID:FormalRiceFarmer,项目名称:KerbalMods,代码行数:101,代码来源:PartSim.cs

示例3: PartSim

        public PartSim(Part thePart, int id, double atmosphere, LogMsg log)
        {
            part = thePart;
            partId = id;
            name = part.partInfo.name;

            if (log != null)
                log.buf.AppendLine("Create PartSim for " + name);

            parent = null;
            parentAttach = part.attachMode;
            fuelCrossFeed = part.fuelCrossFeed;
            noCrossFeedNodeKey = part.NoCrossFeedNodeKey;
            decoupledInStage = DecoupledInStage(part);
            isFuelLine = part is FuelLine;
            isFuelTank = part is FuelTank;
            isSepratron = IsSepratron();
            inverseStage = part.inverseStage;
            //MonoBehaviour.print("inverseStage = " + inverseStage);

            cost = part.partInfo.cost;
            foreach (PartResource resource in part.Resources)
            {
                cost -= (float)((resource.maxAmount - resource.amount) * resource.info.unitCost);
            }

            // Work out if the part should have no physical significance
            isNoPhysics = part.HasModule<LaunchClamp>() ||
                            part.physicalSignificance == Part.PhysicalSignificance.NONE ||
                            part.PhysicsSignificance == 1;

            if (!isNoPhysics)
                baseMass = part.mass;

            if (SimManager.logOutput)
                MonoBehaviour.print((isNoPhysics ? "Ignoring" : "Using") + " part.mass of " + part.mass);

            foreach (PartResource resource in part.Resources)
            {
                // Make sure it isn't NaN as this messes up the part mass and hence most of the values
                // This can happen if a resource capacity is 0 and tweakable
                if (!Double.IsNaN(resource.amount))
                {
                    if (SimManager.logOutput)
                        MonoBehaviour.print(resource.resourceName + " = " + resource.amount);

                    resources.Add(resource.info.id, resource.amount);
                    resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0);
                }
                else
                {
                    MonoBehaviour.print(resource.resourceName + " is NaN. Skipping.");
                }
            }

            startMass = GetMass();

            hasVessel = (part.vessel != null);
            isLanded = hasVessel && part.vessel.Landed;
            if (hasVessel)
            {
                vesselName = part.vessel.vesselName;
                vesselType = part.vesselType;
            }
            initialVesselName = part.initialVesselName;

            hasMultiModeEngine = part.HasModule<MultiModeEngine>();
            hasModuleEnginesFX = part.HasModule<ModuleEnginesFX>();
            hasModuleEngines = part.HasModule<ModuleEngines>();

            isEngine = hasMultiModeEngine || hasModuleEnginesFX || hasModuleEngines;

            if (SimManager.logOutput)
                MonoBehaviour.print("Created " + name + ". Decoupled in stage " + decoupledInStage);
        }
开发者ID:CYBUTEK,项目名称:Engineer,代码行数:75,代码来源:PartSim.cs

示例4: IsDecoupler

 private bool IsDecoupler(Part thePart)
 {
     return thePart.HasModule<ModuleDecouple>() ||
             thePart.HasModule<ModuleAnchoredDecoupler>();
 }
开发者ID:CYBUTEK,项目名称:Engineer,代码行数:5,代码来源:PartSim.cs

示例5: IsFairing

 private bool IsFairing(Part thePart)
 {
     return thePart.HasModule<ModuleProceduralFairing>();
 }
开发者ID:CliftonMarien,项目名称:MechJeb2,代码行数:4,代码来源:PartSim.cs

示例6: FuelNode

        public float moduleMass; // for debugging

        public FuelNode(Part part, bool dVLinearThrust)
        {
            if (!part.IsLaunchClamp())
            {
                //print(part.partInfo.name.PadRight(25) + " " + part.mass.ToString("F4") + " " + part.GetPhysicslessChildMass().ToString("F4") + " " + part.GetModuleMass(part.partInfo.partPrefab.mass).ToString("F4"));
                dryMass = part.mass; // Intentionally ignore the physic flag.

                moduleMass = part.GetModuleMass(part.partInfo.partPrefab != null ? part.partInfo.partPrefab.mass : dryMass);
                if (part.HasModule<ModuleProceduralFairing>())
                {
                    fairingMass = moduleMass;
                }
            }

            inverseStage = part.inverseStage;
            partName = part.partInfo.name;

            //note which resources this part has stored
            for (int i = 0; i < part.Resources.Count; i++)
            {
                PartResource r = part.Resources[i];
                if (r.info.density > 0 && r.info.name != "IntakeAir")
                {
                    if (r.flowState)
                    {
                        resources[r.info.id] = (float) r.amount;
                    }
                    else
                    {
                        dryMass += (float) (r.amount*r.info.density); // disabled resources are just dead weight
                    }
                }
            }

            // TODO : handle the multiple active ModuleEngine case ( SXT engines with integrated vernier )

            //record relevant engine stats
            ModuleEngines engine = part.Modules.OfType<ModuleEngines>().FirstOrDefault(e => e.isEnabled);
            if (engine != null)
            {
                //Only count engines that either are ignited or will ignite in the future:
                if ((HighLogic.LoadedSceneIsEditor || inverseStage < Staging.CurrentStage || engine.getIgnitionState) && (engine.thrustPercentage > 0 || engine.minThrust > 0))
                {
                    //if an engine has been activated early, pretend it is in the current stage:
                    if (engine.getIgnitionState && inverseStage < Staging.CurrentStage)
                        inverseStage = Staging.CurrentStage;

                    isEngine = true;

                    g = engine.g;

                    // If we take into account the engine rotation
                    if (dVLinearThrust)
                    {
                        Vector3 thrust = Vector3d.zero;
                        for (int i = 0; i < engine.thrustTransforms.Count; i++)
                        {
                            thrust -= engine.thrustTransforms[i].forward/engine.thrustTransforms.Count;
                        }

                        Vector3d fwd = HighLogic.LoadedScene == GameScenes.EDITOR ? EditorLogic.VesselRotation * Vector3d.up : engine.part.vessel.GetTransform().up;
                        fwdThrustRatio = Vector3.Dot(fwd, thrust);
                    }

                    thrustPercentage = engine.thrustPercentage;

                    minFuelFlow = engine.minFuelFlow;
                    maxFuelFlow = engine.maxFuelFlow;

                    atmosphereCurve = new FloatCurve(engine.atmosphereCurve.Curve.keys);
                    atmChangeFlow = engine.atmChangeFlow;
                    useAtmCurve = engine.useAtmCurve;
                    if (useAtmCurve)
                        atmCurve = new FloatCurve(engine.atmCurve.Curve.keys);
                    useVelCurve = engine.useVelCurve;
                    if (useAtmCurve)
                        velCurve = new FloatCurve(engine.velCurve.Curve.keys);

                    propellantSumRatioTimesDensity = engine.propellants.Where(prop => !prop.ignoreForIsp).Sum(prop => prop.ratio * MuUtils.ResourceDensity(prop.id));
                    propellantRatios = engine.propellants.Where(prop => MuUtils.ResourceDensity(prop.id) > 0 && !prop.ignoreForIsp ).ToDictionary(prop => prop.id, prop => prop.ratio);
                }
            }
        }
开发者ID:CliftonMarien,项目名称:MechJeb2,代码行数:85,代码来源:FuelFlowSimulation.cs

示例7: Init

        private void Init(Part part, bool dVLinearThrust)
        {
            resources.Clear();
            resourceConsumptions.Clear();
            resourceDrains.Clear();
            freeResources.Clear();

            propellantRatios.Clear();
            propellantFlows.Clear();

            fuelLineSources.Clear();
            stackNodeSources.Clear();
            surfaceMountSources.Clear();

            surfaceMountParent = null;
            isEngine = false;

            dryMass = 0;
            fairingMass = 0;

            moduleMass = 0;
            if (!part.IsLaunchClamp())
            {
                //print(part.partInfo.name.PadRight(25) + " " + part.mass.ToString("F4") + " " + part.GetPhysicslessChildMass().ToString("F4") + " " + part.GetModuleMass(part.partInfo.partPrefab.mass).ToString("F4"));
                dryMass = part.mass; // Intentionally ignore the physic flag.

                moduleMass = part.GetModuleMassNoAlloc(part.partInfo.partPrefab != null ? part.partInfo.partPrefab.mass : dryMass);
                if (part.HasModule<ModuleProceduralFairing>())
                {
                    fairingMass = moduleMass;
                }
            }

            inverseStage = part.inverseStage;
            partName = part.partInfo.name;

            //note which resources this part has stored
            for (int i = 0; i < part.Resources.Count; i++)
            {
                PartResource r = part.Resources[i];
                if (r.info.density > 0)
                {
                    if (r.flowState)
                    {
                        resources[r.info.id] = (float)r.amount;
                    }
                    else
                    {
                        dryMass += (float)(r.amount * r.info.density); // disabled resources are just dead weight
                    }
                }
                if (r.info.name == "IntakeAir")
                    freeResources[PartResourceLibrary.Instance.GetDefinition("IntakeAir").id] = true;
                // Those two are in the CRP.
                if (r.info.name == "IntakeLqd")
                    freeResources[PartResourceLibrary.Instance.GetDefinition("IntakeLqd").id] = true;
                if (r.info.name == "IntakeAtm")
                    freeResources[PartResourceLibrary.Instance.GetDefinition("IntakeAtm").id] = true;
            }

            // TODO : handle the multiple active ModuleEngine case ( SXT engines with integrated vernier )

            //record relevant engine stats
            //ModuleEngines engine = part.Modules.OfType<ModuleEngines>().FirstOrDefault(e => e.isEnabled);
            ModuleEngines engine = null;
            for (int i = 0; i < part.Modules.Count; i++)
            {
                PartModule pm = part.Modules[i];
                ModuleEngines e = pm as ModuleEngines;
                if (e != null && e.isEnabled)
                {
                    engine = e;
                    break;
                }
            }

            if (engine != null)
            {
                //Only count engines that either are ignited or will ignite in the future:
                if ((HighLogic.LoadedSceneIsEditor || inverseStage < StageManager.CurrentStage || engine.getIgnitionState) && (engine.thrustPercentage > 0 || engine.minThrust > 0))
                {
                    //if an engine has been activated early, pretend it is in the current stage:
                    if (engine.getIgnitionState && inverseStage < StageManager.CurrentStage)
                        inverseStage = StageManager.CurrentStage;

                    isEngine = true;

                    g = engine.g;

                    // If we take into account the engine rotation
                    if (dVLinearThrust)
                    {
                        Vector3 thrust = Vector3d.zero;
                        for (int i = 0; i < engine.thrustTransforms.Count; i++)
                        {
                            thrust -= engine.thrustTransforms[i].forward * engine.thrustTransformMultipliers[i];
                        }

                        Vector3d fwd = HighLogic.LoadedScene == GameScenes.EDITOR ? EditorLogic.VesselRotation * Vector3d.up : engine.part.vessel.GetTransform().up;
                        fwdThrustRatio = Vector3.Dot(fwd, thrust);
//.........这里部分代码省略.........
开发者ID:BloodyRain2k,项目名称:MechJeb2,代码行数:101,代码来源:FuelFlowSimulation.cs

示例8: IsARadialDecoupler

 private static bool IsARadialDecoupler(Part part)
 {
     return part.HasModule<ModuleAnchoredDecoupler>() ||
         part.FindModuleImplementing<ModuleDecouple>()?.explosiveNodeID == "srf";
 }
开发者ID:jkoritzinsky,项目名称:Extensive-Engineer-Report,代码行数:5,代码来源:RadialStagesStrutted.cs

示例9: FuelNode

        public FuelNode(Part part, bool dVLinearThrust)
        {
            bool physicallySignificant = (part.physicalSignificance != Part.PhysicalSignificance.NONE);
            if (part.HasModule<ModuleLandingGear>() || part.HasModule<LaunchClamp>())
            {
                //Landing gear set physicalSignificance = NONE when they enter the flight scene
                //Launch clamp mass should be ignored.
                physicallySignificant = false;
            }
            if (physicallySignificant) dryMass = part.mass;

            inverseStage = part.inverseStage;
            isFuelLine = (part is FuelLine);
            isSepratron = part.IsSepratron();
            partName = part.partInfo.name;

            //note which resources this part has stored
            foreach (PartResource r in part.Resources)
            {
                if (r.info.density > 0 && r.name != "IntakeAir") resources[r.info.id] = (float)r.amount;
                resourcesUnobtainableFromParent.Add(r.info.id);
            }

            //record relevant engine stats
            ModuleEngines engine = part.Modules.OfType<ModuleEngines>().FirstOrDefault();
            if (engine != null)
            {
                //Only count engines that either are ignited or will ignite in the future:
                if (HighLogic.LoadedSceneIsEditor || inverseStage < Staging.CurrentStage || engine.getIgnitionState)
                {
                    //if an engine has been activated early, pretend it is in the current stage:
                    if (engine.getIgnitionState && inverseStage < Staging.CurrentStage) inverseStage = Staging.CurrentStage;

                    isEngine = true;

                    // If we take into account the engine rotation
                    if (dVLinearThrust)
                    {
                        Vector3 thrust = Vector3d.zero;
                        foreach (var t in engine.thrustTransforms)
                            thrust -= t.forward / engine.thrustTransforms.Count;

                        Vector3 fwd = HighLogic.LoadedScene == GameScenes.EDITOR ? Vector3d.up : (HighLogic.LoadedScene == GameScenes.SPH ? Vector3d.forward : (Vector3d)engine.part.vessel.GetTransform().up);
                        fwdThrustRatio = Vector3.Dot(fwd, thrust);
                    }

                    maxThrust = engine.thrustPercentage / 100f * engine.maxThrust;

                    if (part.Modules.Contains("ModuleEngineConfigs") || part.Modules.Contains("ModuleHybridEngine") || part.Modules.Contains("ModuleHybridEngines"))
                    {
                        correctThrust = true;
                        if (HighLogic.LoadedSceneIsFlight && engine.realIsp > 0.0f)
                            maxThrust = maxThrust * engine.atmosphereCurve.Evaluate(0) / engine.realIsp; //engine.atmosphereCurve.Evaluate((float)FlightGlobals.ActiveVessel.atmDensity);
                    }
                    else
                        correctThrust = false;
                    ispCurve = engine.atmosphereCurve;

                    propellantSumRatioTimesDensity = engine.propellants.Sum(prop => prop.ratio * MuUtils.ResourceDensity(prop.id));
                    propellantRatios = engine.propellants.Where(prop => PartResourceLibrary.Instance.GetDefinition(prop.id).density > 0 && prop.name != "IntakeAir" ).ToDictionary(prop => prop.id, prop => prop.ratio);
                }
            }

            // And do the same for ModuleEnginesFX :(
            ModuleEnginesFX enginefx = part.Modules.OfType<ModuleEnginesFX>().Where(e => e.isEnabled).FirstOrDefault();
            if (enginefx != null)
            {
                //Only count engines that either are ignited or will ignite in the future:
                if (HighLogic.LoadedSceneIsEditor || inverseStage < Staging.CurrentStage || enginefx.getIgnitionState)
                {
                    //if an engine has been activated early, pretend it is in the current stage:
                    if (enginefx.getIgnitionState && inverseStage < Staging.CurrentStage) inverseStage = Staging.CurrentStage;

                    isEngine = true;

                    // If we take into account the engine rotation
                    if (dVLinearThrust)
                    {
                        Vector3 thrust = Vector3d.zero;
                        foreach (var t in enginefx.thrustTransforms)
                            thrust -= t.forward / enginefx.thrustTransforms.Count;

                        Vector3 fwd = HighLogic.LoadedScene == GameScenes.EDITOR ? Vector3d.up : (HighLogic.LoadedScene == GameScenes.SPH ? Vector3d.forward : (Vector3d)enginefx.part.vessel.GetTransform().up);
                        fwdThrustRatio = Vector3.Dot(fwd, thrust);
                    }

                    maxThrust = enginefx.thrustPercentage / 100f * enginefx.maxThrust;

                    if (part.Modules.Contains("ModuleEngineConfigs") || part.Modules.Contains("ModuleHybridEngine") || part.Modules.Contains("ModuleHybridEngines"))
                    {
                        correctThrust = true;
                        if (HighLogic.LoadedSceneIsFlight && enginefx.realIsp > 0.0f)
                            maxThrust = maxThrust * enginefx.atmosphereCurve.Evaluate(0) / enginefx.realIsp; //engine.atmosphereCurve.Evaluate((float)FlightGlobals.ActiveVessel.atmDensity);
                    }
                    else
                        correctThrust = false;
                    ispCurve = enginefx.atmosphereCurve;

                    propellantSumRatioTimesDensity = enginefx.propellants.Sum(prop => prop.ratio * MuUtils.ResourceDensity(prop.id));
                    propellantRatios = enginefx.propellants.Where(prop => PartResourceLibrary.Instance.GetDefinition(prop.id).density > 0 && prop.name != "IntakeAir").ToDictionary(prop => prop.id, prop => prop.ratio);
//.........这里部分代码省略.........
开发者ID:KaiSforza,项目名称:MechJeb2,代码行数:101,代码来源:FuelFlowSimulation.cs


注:本文中的Part.HasModule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。