本文整理汇总了C#中Part.GetResourceMass方法的典型用法代码示例。如果您正苦于以下问题:C# Part.GetResourceMass方法的具体用法?C# Part.GetResourceMass怎么用?C# Part.GetResourceMass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part.GetResourceMass方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: onPartDie
/// <summary>
/// If a part dies, rebuild the sphere
/// </summary>
void onPartDie(Part part)
{
// If there's no part or vessel, abort
if (part == null || part.vessel == null)
return;
// Get the CelestialBody
CelestialBody body = part.vessel.mainBody;
// Get the Vessel
Vessel vessel = part.vessel;
// Create the Deformation
Deformation deformation = new Deformation
{
position = Utility.LLAtoECEF(vessel.latitude, vessel.longitude, vessel.terrainAltitude, body.Radius),
vPos = vessel.vesselTransform.position,
altitude = vessel.terrainAltitude + body.Radius,
body = body,
surfaceSpeed = vessel.srfSpeed,
mass = part.mass + part.GetResourceMass(),
srfAngle = Vector3d.Angle(Vector3d.up, vessel.vesselTransform.forward)
};
deformations.Enqueue(deformation);
}
示例2: KIS_Item
// New part from scene
public KIS_Item(Part part, ModuleKISInventory inventory, float quantity = 1)
{
// Get part node
this.availablePart = PartLoader.getPartInfoByName(part.partInfo.name);
this.partNode = new ConfigNode();
KIS_Shared.PartSnapshot(part).CopyTo(this.partNode);
// init config
this.InitConfig(availablePart, inventory, quantity);
// Get mass
this.resourceMass = part.GetResourceMass();
ModuleKISInventory itemInventory = part.GetComponent<ModuleKISInventory>();
if (itemInventory)
{
this.contentMass = itemInventory.GetContentMass();
this.contentCost = itemInventory.GetContentCost();
if (itemInventory.invName != "") this.inventoryName = itemInventory.invName;
}
}
示例3: FinishDelayedCreation
private static void FinishDelayedCreation(Part part, List<Collider> re_enable)
{
// Dissociate from parent and restore colliders
part.transform.parent = null;
foreach (var collider in re_enable)
{
collider.gameObject.SetActive(true);
}
// Create the rigid body
part.PromoteToPhysicalPart();
part.rb.mass = part.mass + part.GetResourceMass();
}
示例4: SavePartSnapshot
public static ConfigNode SavePartSnapshot(Part part)
{
// Seems fine with a null vessel in 0.23 if some empty lists are allocated below
ProtoPartSnapshot snapshot = new ProtoPartSnapshot(part, null);
ConfigNode node = new ConfigNode("CONTENT_PART");
snapshot.attachNodes = new List<AttachNodeSnapshot>();
snapshot.srfAttachNode = new AttachNodeSnapshot("attach,-1");
snapshot.symLinks = new List<ProtoPartSnapshot>();
snapshot.symLinkIdxs = new List<int>();
snapshot.Save(node);
node.AddValue("kas_total_mass", part.mass+part.GetResourceMass());
// Prune unimportant data
node.RemoveValues("parent");
node.RemoveValues("position");
node.RemoveValues("rotation");
node.RemoveValues("istg");
node.RemoveValues("dstg");
node.RemoveValues("sqor");
node.RemoveValues("sidx");
node.RemoveValues("attm");
node.RemoveValues("srfN");
node.RemoveValues("attN");
node.RemoveValues("connected");
node.RemoveValues("attached");
node.RemoveValues("flag");
node.RemoveNodes("ACTIONS");
// Remove modules that are not in prefab since they won't load anyway
var module_nodes = node.GetNodes("MODULE");
var prefab_modules = part.partInfo.partPrefab.GetComponents<PartModule>();
node.RemoveNodes("MODULE");
for (int i = 0; i < prefab_modules.Length && i < module_nodes.Length; i++)
{
var module = module_nodes[i];
var name = module.GetValue("name") ?? "";
node.AddNode(module);
if (name == "KASModuleContainer")
{
// Containers get to keep their contents
module.RemoveNodes("EVENTS");
}
else if (name.StartsWith("KASModule"))
{
// Prune the state of the KAS modules completely
module.ClearData();
module.AddValue("name", name);
continue;
}
module.RemoveNodes("ACTIONS");
}
return node;
}
示例5: dry_CoM_recurs
public static Vector3 dry_CoM_recurs(Part p, ref float mass_counter, ref float wet_mass)
{
Vector3 res = Vector3.zero;
if (p == null)
return res;
if (p.physicalSignificance == Part.PhysicalSignificance.FULL)
res = p.partTransform.TransformPoint(p.CoMOffset) * p.mass;
else
if (p.parent != null)
res = p.parent.partTransform.TransformPoint(p.parent.CoMOffset) * p.mass;
mass_counter += p.mass;
wet_mass += p.mass + p.GetResourceMass();
for (int i = 0; i < p.children.Count; i++)
{
res += dry_CoM_recurs(p.children[i], ref mass_counter, ref wet_mass);
}
return res;
}
示例6: printMassInfo
void printMassInfo(Part part)
{
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("part", GUILayout.Width (w));
GUILayout.Label (part.partInfo.name);
}
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("mass", GUILayout.Width (w));
GUILayout.Label (part.mass.ToString ("F3"));
}
GUILayout.EndHorizontal ();
var m = part.partInfo.partPrefab.mass;
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("p. mass", GUILayout.Width (w));
GUILayout.Label (m.ToString ("F3"));
}
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("module", GUILayout.Width (w));
GUILayout.Label (part.GetModuleMass (m).ToString ("F3"));
}
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("resource", GUILayout.Width (w));
GUILayout.Label (part.GetResourceMass ().ToString ("F3"));
}
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("childs", GUILayout.Width (w));
GUILayout.Label (part.GetPhysicslessChildMassInEditor ().ToString ("F3"));
}
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
{
GUILayout.Label ("total", GUILayout.Width (w));
GUILayout.Label (part.GetTotalMass ().ToString ("F3"));
}
GUILayout.EndHorizontal ();
}
示例7: PartInfo
protected void PartInfo(Part part)
{
Vector3 com;
part.GetCoM (out com);
GUILayout.Label (string.Format (
"phy: {0} rb: {1} m: {2:F3}t cm: {3:F3}t\n" +
"pm: {4:F3}t rm: {5:F3} mm: {6:F3}t\n" +
"com: {7}\n" +
"max_drag: {8:F3} AreaDrag: {9:F3}\n" +
"dvector: {10}",
part.physicalSignificance,
part.rb != null,
part.GetTotalMass (),
part.GetPhysicslessChildMassInEditor (),
part.mass,
part.GetResourceMass (),
part.GetModuleMass (part.mass),
com,
part.maximum_drag,
part.DragCubes.AreaDrag,
part.DragCubes.DragVector
));
var engines = part.FindModulesImplementing<ModuleEngines> ();
foreach(var engine in engines) {
GUILayout.Label ("<b>ModuleEngine</b> " + engine.engineID);
GUILayout.Label (string.Format (
"min thrust: {0} max thrust: {1}\n" +
"vac isp: {2} asl isp: {3}",
engine.minThrust, engine.maxThrust,
engine.atmosphereCurve.Evaluate (0f),
engine.atmosphereCurve.Evaluate (1f)));
}
var enginesfx = part.FindModulesImplementing<ModuleEnginesFX> ();
foreach(var engine in enginesfx) {
GUILayout.Label ("<b>ModuleEngineFX</b> " + engine.engineID);
GUILayout.Label (string.Format (
"min thrust: {0} max thrust: {1}\n" +
"vac isp: {2} asl isp: {3}",
engine.minThrust, engine.maxThrust,
engine.atmosphereCurve.Evaluate (0f),
engine.atmosphereCurve.Evaluate (1f)));
}
}
示例8: UpdatePartJoint
private void UpdatePartJoint(Part p)
{
if (!KJRJointUtils.JointAdjustmentValid(p) || p.rb == null || p.attachJoint == null)
return;
if (p.attachMethod == AttachNodeMethod.LOCKED_JOINT)
{
if (KJRJointUtils.debug)
{
Debug.Log("KJR: Already processed part before: " + p.partInfo.name + " (" + p.flightID + ") -> " +
p.parent.partInfo.name + " (" + p.parent.flightID + ")");
}
return;
}
List<ConfigurableJoint> jointList;
if (p is StrutConnector)
{
StrutConnector s = p as StrutConnector;
if (s.jointTarget == null || s.jointRoot == null)
return;
jointList = KJRJointUtils.GetJointListFromAttachJoint(s.strutJoint);
if (jointList != null)
{
for (int i = 0; i < jointList.Count; i++)
{
ConfigurableJoint j = jointList[i];
if (j == null)
continue;
JointDrive strutDrive = j.angularXDrive;
strutDrive.positionSpring = KJRJointUtils.decouplerAndClampJointStrength;
strutDrive.maximumForce = KJRJointUtils.decouplerAndClampJointStrength;
j.xDrive = j.yDrive = j.zDrive = j.angularXDrive = j.angularYZDrive = strutDrive;
j.xMotion = j.yMotion = j.zMotion = ConfigurableJointMotion.Locked;
j.angularXMotion = j.angularYMotion = j.angularZMotion = ConfigurableJointMotion.Locked;
//float scalingFactor = (s.jointTarget.mass + s.jointTarget.GetResourceMass() + s.jointRoot.mass + s.jointRoot.GetResourceMass()) * 0.01f;
j.breakForce = KJRJointUtils.decouplerAndClampJointStrength;
j.breakTorque = KJRJointUtils.decouplerAndClampJointStrength;
}
p.attachMethod = AttachNodeMethod.LOCKED_JOINT;
}
}
if (p.Modules.Contains("CModuleStrut"))
{
CModuleStrut s = (CModuleStrut)p.Modules["CModuleStrut"];
if (!(s.jointTarget == null || s.jointRoot == null))
{
jointList = KJRJointUtils.GetJointListFromAttachJoint(s.strutJoint);
if (jointList != null)
{
for (int i = 0; i < jointList.Count; i++)
{
ConfigurableJoint j = jointList[i];
if (j == null)
continue;
JointDrive strutDrive = j.angularXDrive;
strutDrive.positionSpring = KJRJointUtils.decouplerAndClampJointStrength;
strutDrive.maximumForce = KJRJointUtils.decouplerAndClampJointStrength;
j.xDrive = j.yDrive = j.zDrive = j.angularXDrive = j.angularYZDrive = strutDrive;
j.xMotion = j.yMotion = j.zMotion = ConfigurableJointMotion.Locked;
j.angularXMotion = j.angularYMotion = j.angularZMotion = ConfigurableJointMotion.Locked;
//float scalingFactor = (s.jointTarget.mass + s.jointTarget.GetResourceMass() + s.jointRoot.mass + s.jointRoot.GetResourceMass()) * 0.01f;
j.breakForce = KJRJointUtils.decouplerAndClampJointStrength;
j.breakTorque = KJRJointUtils.decouplerAndClampJointStrength;
}
p.attachMethod = AttachNodeMethod.LOCKED_JOINT;
}
}
}
jointList = KJRJointUtils.GetJointListFromAttachJoint(p.attachJoint);
if (jointList == null)
return;
StringBuilder debugString = new StringBuilder();
bool addAdditionalJointToParent = KJRJointUtils.multiPartAttachNodeReinforcement;
//addAdditionalJointToParent &= !(p.Modules.Contains("LaunchClamp") || (p.parent.Modules.Contains("ModuleDecouple") || p.parent.Modules.Contains("ModuleAnchoredDecoupler")));
addAdditionalJointToParent &= !(p is StrutConnector || p.Modules.Contains("CModuleStrut"));
float partMass = p.mass + p.GetResourceMass();
for (int i = 0; i < jointList.Count; i++)
//.........这里部分代码省略.........
示例9: OnMouseGrabEnterPart
void OnMouseGrabEnterPart(Part part)
{
if (!grabActive) return;
grabOk = false;
if (!HighLogic.LoadedSceneIsFlight) return;
if (KISAddonPointer.isRunning) return;
if (hoverInventoryGui()) return;
if (draggedPart == part) return;
ModuleKISPartDrag pDrag = part.GetComponent<ModuleKISPartDrag>();
ModuleKISPartMount parentMount = null;
if (part.parent) parentMount = part.parent.GetComponent<ModuleKISPartMount>();
ModuleKISItem item = part.GetComponent<ModuleKISItem>();
// Drag part over another one if possible (ex : mount)
if (draggedPart && pDrag)
{
KISAddonCursor.CursorEnable(pDrag.dragIconPath, pDrag.dragText, '(' + pDrag.dragText2 + ')');
return;
}
if (draggedPart)
{
KISAddonCursor.CursorDisable();
return;
}
// Do nothing if part is EVA
if (part.vessel.isEVA) return;
// Check part distance
if (!HasActivePickupInRange(part))
{
KISAddonCursor.CursorEnable("KIS/Textures/tooFar", "Too far", "(Move closer to the part)");
return;
}
// Check part mass
float pMass = (part.mass + part.GetResourceMass());
float pickupMaxMass = GetAllPickupMaxMassInRange(part);
if (pMass > pickupMaxMass)
{
KISAddonCursor.CursorEnable("KIS/Textures/tooHeavy", "Too heavy", "(Bring more kerbal [" + pMass + " > " + pickupMaxMass + ")");
return;
}
// Check if part can be detached and grabbed
if (!parentMount)
{
if (part.children.Count > 0 || part.parent)
{
//Part with a child or a parent
if (item)
{
if (item.allowPartAttach == 0)
{
KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't grab", "(This part can't be detached)");
return;
}
else if (item.allowPartAttach == 2)
{
ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
if (!pickupModule)
{
if (FlightGlobals.ActiveVessel.isEVA)
{
KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached without a tool)");
return;
}
else
{
KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
return;
}
}
}
}
else
{
ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
if (!pickupModule)
{
if (FlightGlobals.ActiveVessel.isEVA)
{
KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached without a tool)");
return;
}
else
{
KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
return;
}
}
}
}
else
{
// Part without childs and parent
if (item)
{
if (item.staticAttached && item.allowStaticAttach == 2)
//.........这里部分代码省略.........
示例10: UpdatePartJoint
private void UpdatePartJoint(Part p)
{
if (!JointUtils.JointAdjustmentValid(p) || p.rb == null)
return;
if (p.attachJoint.Joint is ConfigurableJoint &&
p.attachMethod == AttachNodeMethod.LOCKED_JOINT)
{
if (JointUtils.debug)
{
Debug.Log("KJR: Already processed part before: " + p.partInfo.name + " (" + p.uid + ") -> " +
p.parent.partInfo.name + " (" + p.parent.uid + ")");
}
return;
}
if (p is StrutConnector)
{
StrutConnector s = p as StrutConnector;
JointDrive strutDrive = s.strutJoint.Joint.angularXDrive;
strutDrive.positionSpring = JointUtils.decouplerAndClampJointStrength;
strutDrive.maximumForce = JointUtils.decouplerAndClampJointStrength;
s.strutJoint.Joint.xDrive = s.strutJoint.Joint.yDrive = s.strutJoint.Joint.zDrive = s.strutJoint.Joint.angularXDrive = s.strutJoint.Joint.angularYZDrive = strutDrive;
float scalingFactor = (s.jointTarget.mass + s.jointTarget.GetResourceMass() + s.jointRoot.mass + s.jointRoot.GetResourceMass()) * 0.01f;
s.strutJoint.SetBreakingForces(s.strutJoint.Joint.breakForce * scalingFactor, s.strutJoint.Joint.breakTorque * scalingFactor);
p.attachMethod = AttachNodeMethod.LOCKED_JOINT;
return;
}
StringBuilder debugString = new StringBuilder();
String jointType = p.attachJoint.Joint.GetType().Name;
Rigidbody connectedBody = p.attachJoint.Joint.connectedBody;
Part connectedPart = connectedBody.GetComponent<Part>() ?? p.parent;
float partMass = p.mass + p.GetResourceMass();
float parentMass = connectedPart.mass + connectedPart.GetResourceMass();
if (partMass < JointUtils.massForAdjustment || parentMass < JointUtils.massForAdjustment)
{
if (JointUtils.debug)
{
Debug.Log("KJR: Part mass too low, skipping: " + p.partInfo.name + " (" + p.uid + ")");
}
return;
}
// Check attachment nodes for better orientation data
AttachNode attach = p.findAttachNodeByPart(p.parent);
AttachNode p_attach = p.parent.findAttachNodeByPart(p);
AttachNode node = attach ?? p_attach;
if (node == null)
{
// Check if it's a pair of coupled docking ports
var dock1 = p.Modules["ModuleDockingNode"] as ModuleDockingNode;
var dock2 = p.parent.Modules["ModuleDockingNode"] as ModuleDockingNode;
//Debug.Log(dock1 + " " + (dock1 ? ""+dock1.dockedPartUId : "?") + " " + dock2 + " " + (dock2 ? ""+dock2.dockedPartUId : "?"));
if (dock1 && dock2 && (dock1.dockedPartUId == p.parent.flightID || dock2.dockedPartUId == p.flightID))
{
attach = p.findAttachNode(dock1.referenceAttachNode);
p_attach = p.parent.findAttachNode(dock2.referenceAttachNode);
node = attach ?? p_attach;
}
}
// If still no node and apparently surface attached, use the normal one if it's there
if (node == null && p.attachMode == AttachModes.SRF_ATTACH)
node = attach = p.srfAttachNode;
if (JointUtils.debug)
{
debugString.AppendLine("Original joint from " + p.partInfo.title + " to " + p.parent.partInfo.title);
debugString.AppendLine(" " + p.partInfo.name + " (" + p.uid + ") -> " + p.parent.partInfo.name + " (" + p.parent.uid + ")");
debugString.AppendLine("");
debugString.AppendLine(p.partInfo.title + " Inertia Tensor: " + p.rigidbody.inertiaTensor + " " + p.parent.partInfo.name + " Inertia Tensor: " + connectedBody.inertiaTensor);
debugString.AppendLine("");
debugString.AppendLine("Std. Joint Parameters");
debugString.AppendLine("Connected Body: " + p.attachJoint.Joint.connectedBody);
debugString.AppendLine("Attach mode: " + p.attachMode + " (was " + jointType + ")");
if (attach != null)
debugString.AppendLine("Attach node: " + attach.id + " - " + attach.nodeType + " " + attach.size);
if (p_attach != null)
debugString.AppendLine("Parent node: " + p_attach.id + " - " + p_attach.nodeType + " " + p_attach.size);
debugString.AppendLine("Anchor: " + p.attachJoint.Joint.anchor);
debugString.AppendLine("Axis: " + p.attachJoint.Joint.axis);
debugString.AppendLine("Sec Axis: " + p.attachJoint.Joint.secondaryAxis);
debugString.AppendLine("Break Force: " + p.attachJoint.Joint.breakForce);
debugString.AppendLine("Break Torque: " + p.attachJoint.Joint.breakTorque);
debugString.AppendLine("");
//.........这里部分代码省略.........