Difference between revisions of "API:Part"
m (Added description to isControlSource.) |
|||
Line 575: | Line 575: | ||
|type=bool | |type=bool | ||
|name=isControlSource | |name=isControlSource | ||
− | |desc= | + | |desc=Whether this is capable of being a control source, i.e. whether it has "Control from here" on its right-click menu. |
}} | }} | ||
{{Field | {{Field |
Revision as of 20:39, 16 November 2015
Contents
Part Class
Inherits | Implements |
---|---|
MonoBehaviour | |
A Part is the C# object representing a single part on a vessel. You can subclass Part, creating a new type of part that users can place on their ships. The C# class that controls a part is specified in that part's "part.cfg" file by the line "module = <Part subclass>" where <Part subclass> is the name of your new Part subclass. You can also create PartModules, which add to the behavior of an existing part. From within a PartModule, access the Part you are attached to via the "part" field.
If you build a plugin by subclassing Part, you will want to override some of the Part methods. See API:Part class overrides.
Below are some of the interesting members of the Part class. Note that the list of members is far from complete.
Properties
The following is a list of properties in Part.
Name | Description |
---|---|
BaseActionList Actions { get; } | ? |
int ClassID { get; } | ? |
string ClassName { get; } | ? |
DragCubeList DragCubes { get; } | ? |
EffectList Effects { get; } | ? |
BaseEventList Events { get; } | A list of the events that the Part will respond to. For example, landing legs deploy in response to certain events. |
BaseFieldList Fields { get; } | ? |
bool hasStagingIcon { get; } | ? |
bool isAttached { get; set; } | ? |
bool isConnected { get; set; } | ? Has attribute [Obsolete("for 0.14 support, seriously it's not working anynmore")] |
bool isControllable { get; } | ? |
bool Landed { get; } | ? |
Part localRoot { get; } | ? |
PartModuleList Modules { get; } | ? |
Orbit orbit { get; } | Don't use this!! Use vessel.orbit instead. |
PartValues PartValues { get; } | ? |
PartResourceList Resources { get; } | ? |
Rigidbody Rigidbody { get; } | This object lets you do physics to your part: for example, apply forces to it. Check out the Unity documentation on RigidBody. |
bool ShieldedFromAirstream { get; set; } | ? |
bool Splashed { get; } | ? |
PartStates State { get; } | ? |
Vector3 WCoM { get; } | ? |
Fields
The following is a list of fields in Part.
Signature | Description |
---|---|
bool ActivatesEvenIfDisconnected | ? |
double aerodynamicArea | ? |
Transform airlock | ? |
float angularDrag | ? |
double atmDensity | ? |
bool attached | ? |
PartJoint attachJoint | ? |
AttachNodeMethod attachMethod | ? |
AttachModes attachMode | ? |
List〈AttachNode〉 attachNodes | ? |
AttachRules attachRules | ? |
Vector3 attPos | ? |
Vector3 attPos0 | ? |
Quaternion attRotation | ? |
Quaternion attRotation0 | ? |
Vector3 bodyLiftLocalPosition | ? |
Vector3 bodyLiftLocalVector | ? |
float bodyLiftMultiplier | ? |
float bodyLiftScalar | ? |
float breakingForce | ? |
float breakingTorque | ? |
float buoyancy | ? |
Vector3 CenterOfBuoyancy | ? |
List〈Part〉 children | A list of all the Parts attached to this Part (except this Part's parent, i.e., the part this part was attached to). |
int childStageOffset | ? |
Collider collider | ? |
CollisionEnhancer collisionEnhancer | ? |
Vector3 CoLOffset | ? |
static Color defaultHighlightNone | ? |
static Color defaultHighlightPart | ? |
Vector3 CoMOffset | ? |
bool connected | ? |
Vector3 CoPOffset | ? |
uint craftID | ? |
float crashTolerance | ? |
int CrewCapacity | ? |
List〈Collider〉 currentCollisions | ? |
string customPartData | ? |
int defaultInverseStage | ? |
DragModel dragModel | ? |
Vector3 dragReferenceVector | ? |
float dragScalar | ? |
Vector3 dragVector | ? |
Vector3 dragVectorDir | ? |
Vector3 dragVectorDirLocal | ? |
float dragVectorMag | ? |
float dragVectorSqrMag | ? |
double dynamicPressurekPa | ? |
Part editorCollision | ? |
List〈Part〉 editorLinks | ? |
double emissiveConstant | ? |
float explosionPotential | ? |
double exposedArea | ? |
T FindChildPart〈T〉() where T : Part | ? |
T FindChildPart〈T〉(bool recursive) where T : Part | ? |
T[] FindChildParts〈T〉() where T : Part | ? |
T[] FindChildParts〈T〉(bool recursive) where T : Part | ? |
T FindModelComponent〈T〉() where T : Component | ? |
T FindModelComponent〈T〉(string childName) where T : Component | ? |
T[] FindModelComponents〈T〉() where T : Component | ? |
T[] FindModelComponents〈T〉(string childName) where T : Component | ? |
string flagURL | ? |
uint flightID | ? |
bool frozen | ? |
bool fuelCrossFeed | ? |
List〈Part〉 fuelLookupTargets | ? |
List〈FXGroup〉 fxGroups | ? |
bool GroundContact | ? |
bool hasHeiarchyModel | ? |
bool hasLiftModule | ? |
double heatConductivity | ? |
double heatConvectiveConstant | ? |
Color highlightColor | ? |
global::HighlightingSystem.Highlighter highlighter | ? |
HighlightType highlightType | ? |
string initialVesselName | ? |
int inStageIndex | ? |
InternalModel internalModel | ? |
string InternalModelName | ? |
int inverseStage | The stage in which this Part will activate. |
bool isClone | ? |
bool isControlSource | Whether this is capable of being a control source, i.e. whether it has "Control from here" on its right-click menu. |
bool isMirrored | ? |
bool isPersistent | ? |
uint lastFuelRequestId | ? |
uint launchID | ? |
double machNumber | ? |
int manualStageOffset | ? |
float mass | The mass of this Part. |
float maximum_drag | ? |
double maxTemp | The temperature at which this Part will explode. |
float minimum_drag | ? |
Vector3 mirrorAxis | ? |
Vector3 mirrorRefAxis | ? |
Vector3 mirrorVector | ? |
uint missionID | ? |
string NoCrossFeedNodeKey | ? |
Callback OnEditorAttach | Add your own function to this Callback to have it called when this Part is attached to another part in the VAB. The Part object is created when the user clicks on a part in the VAB part selection menu. When that happens, you can set up this Callback to have something happen when the part gets attached to the ship. |
Callback OnEditorDestroy | Like onEditorAttach, but the Callback gets invoked when the part is deleted in the VAB. |
Callback OnEditorDetach | Like onEditorAttach, but the Callback gets invoked when the part is pulled off the ship in the VAB. |
Callback OnJustAboutToBeDestroyed | ? |
Vector3 orgPos | ? |
Quaternion orgRot | ? |
int originalStage | ? |
bool packed | ? |
Part parent | The Part that this Part is attached to. |
PartBuoyancy partBuoyancy | ? |
AvailablePart partInfo | ? |
string partName | ? |
Transform partTransform | ? |
PhysicalSignificance physicalSignificance | Some parts have no physics: that is, their masses and drags don't actually get added to the ship. For these parts, physicalSignificance == Part.PhysicalSignificance.NONE. For regular parts it's equal to Part.PhysicalSignificance.FULL. |
int PhysicsSignificance | ? |
Part potentialParent | ? |
List〈ProtoCrewMember〉 protoModuleCrew | ? |
ProtoPartSnapshot protoPartSnapshot | ? |
double radiativeArea | ? |
double radiatorHeadroom | ? |
double radiatorMax | ? |
Rigidbody rb | ? |
float rescaleFactor | ? |
List〈Part〉 resourceTargets | ? |
double resourceThermalMass | ? |
PartStates ResumeState | ? |
float scaleFactor | ? |
int separationIndex | ? |
double skinExposedArea | ? |
double skinExposedAreaFrac | ? |
double skinExposedMassMult | ? |
double skinInternalConductionMult | ? |
double skinMassPerArea | ? |
double skinMaxTemp | ? |
double skinSkinConductionMult | ? |
double skinTemperature | ? |
double skinThermalMass | ? |
double skinThermalMassModifier | ? |
double skinThermalMassRecip | ? |
double skinToInternalFlux | ? |
double skinUnexposedExternalTemp | ? |
double skinUnexposedMassMult | ? |
AttachNode srfAttachNode | ? |
VStackIcon stackIcon | ? |
StackIconGrouping stackIconGrouping | ? |
int stackSymmetry | ? |
bool stageAfter | ? |
bool stageBefore | ? |
int stageOffset | ? |
string stagingIcon | ? |
bool started | ? |
PartStates state | Whether the Part is IDLE (not activated yet), ACTIVATED (e.g., an activated engine), DEACTIVATED, or DEAD. |
double staticPressureAtm | ? |
Vector3 surfaceAreas | ? |
SymmetryMethod symMethod | ? |
List〈Part〉 symmetryCounterparts | ? |
static T GetComponentUpwards〈T〉(GameObject obj) where T : Component | ? |
double temperature | The current temperature of the part. |
PQS_PartCollider terrainCollider | ? |
double thermalConductionFlux | ? |
double thermalConvectionFlux | ? |
double thermalInternalFlux | ? |
double thermalInternalFluxPrevious | ? |
double thermalMass | ? |
double thermalMassModifier | ? |
double thermalMassReciprocal | ? |
double thermalRadiationFlux | ? |
AttachNode topNode | ? |
static uint fuelRequestID | ? |
Vector3 vel | ? |
Vessel vessel | The vessel of which this Part is a part. Note that vessel==null in the VAB. |
VesselType vesselType | ? |
bool WaterContact | ? |
Methods
The following are methods included in Part.
Signature | Description |
---|---|
constructor Part() | ? |
bool activate(int currentStage, Vessel activeVessel) | ? |
void AddAttachNode(ConfigNode node) | ? |
void addChild(Part child) | ? |
bool AddCrewmember(ProtoCrewMember crew) | ? |
bool AddCrewmemberAt(ProtoCrewMember crew, int seatIndex) | ? |
InternalModel AddInternalPart(ConfigNode node) | ? |
PartModule AddModule(ConfigNode node) | ? |
PartModule AddModule(string moduleName) | ? |
void AddOnMouseDown(OnActionDelegate method) | ? |
void AddOnMouseEnter(OnActionDelegate method) | ? |
void AddOnMouseExit(OnActionDelegate method) | ? |
PartResource AddResource(ConfigNode node) | ? |
Callback〈IAirstreamShield〉 AddShield(IAirstreamShield shd) | ? |
void AddThermalFlux(double kilowatts) | ? |
bool AlreadyProcessedRequest(int requestID) | ? |
bool CheckCollision(Collision c) | ? |
bool checkLanded() | ? |
bool checkSplashed() | ? |
void cleanReferencesFromOtherParts() | ? |
void Couple(Part tgtPart) | ? |
void CreateInternalModel() | ? |
void deactivate() | Deactivates the part. |
void decouple(float breakForce) | Decouples the part from it's parent part. breakForce is the force it will be pushed away with. |
void DespawnAllCrew() | ? |
void Die() | ? Has attribute [ContextMenu("Die")] |
void disconnect(bool controlledSeparation) | ? |
virtual bool DrainFuel(float amount) | ? Has attribute [Obsolete("Use Part.TransferResource instead.")] |
string drawStats() | ? |
void Effect(string effectName) | ? |
void Effect(string effectName, float effectPower) | ? |
void explode() | Calling this method makes the part explode. |
AttachNode findAttachNode(string nodeId) | ? |
AttachNode findAttachNodeByPart(Part connectedPart) | ? |
AttachNode[] findAttachNodes(string partialNodeId) | ? |
Part FindChildPart(string childName) | ? |
Part FindChildPart(string childName, bool recursive) | ? |
virtual bool FindFuel(Part source, List〈Part〉 fuelSources, uint reqId) | ? Has attribute [Obsolete("Use Part.GetConnectedResources instead.")] |
FXGroup findFxGroup(string groupID) | ? |
Animation FindModelAnimator(string animatorName, string clipName) | ? |
Animation[] FindModelAnimators() | ? |
Animation[] FindModelAnimators(string clipName) | ? |
Transform FindModelTransform(string childName) | ? |
Transform[] FindModelTransforms(string childName) | ? |
T FindModuleImplementing〈T〉() | ? |
List〈T〉 FindModulesImplementing〈T〉() | ? |
void FindNonPhysicslessChildren(List〈Part〉 parts) | ? |
Part FindNonPhysicslessParent() | ? |
AttachNode FindPartThroughNodes(Part tgtPart, Part src) | ? |
void force_activate() | Activates the part. Has attribute [ContextMenu("Activate")] |
void freeze() | ? |
void GetConnectedResources(int resourceID, ResourceFlowMode flowMode, List〈PartResource〉 Resources) | ? |
float GetModuleCosts(float defaultCost) | ? |
float GetModuleMass(float defaultMass) | ? |
Vector3 GetModuleSize(Vector3 defaultSize) | ? |
float GetPhysicslessChildMass() | ? |
Transform GetReferenceTransform() | ? |
float GetResourceMass() | ? |
float GetResourceMass(out double) | ? |
float GetResourceMass(out float) | ? |
Part getSymmetryCounterPart(int index) | ? |
void HandleCollision(Collision c) | ? |
bool hasIndirectChild(Part tgtPart) | ? |
bool hasIndirectParent(Part tgtPart) | ? |
void InitializeEffects() | ? |
void InitializeModules() | ? |
bool isSymmetryCounterPart(Part cPart) | ? |
virtual void LateUpdate() | ? |
void LoadEffects(ConfigNode node) | ? |
PartModule LoadModule(ConfigNode node, ref int) | ? |
virtual void onActiveFixedUpdate() | Still under investigation. Knowledge about Unity indicates probable physics pass. |
virtual void onActiveUpdate() | Still under investigation. Knowledge about Unity indicates probable logic pass. |
void onAttach(Part parent, bool first) | ? |
virtual void onBackup() | Still under investigation. Called once from the Editor(s) and in-flight during saving, loading, adding and removing parts based on this class. |
void OnCollisionEnter(Collision c) | ? |
void OnCollisionExit(Collision c) | ? |
void OnCollisionStay(Collision c) | ? |
void OnCopy(Part original, bool asSymCounterpart) | ? |
virtual void onCopy(Part original, bool asSymCounterpart) | Still under investigation. Called once from the Editor(s) when copying part (CTRL+C to copy, CTRL+V to paste) or using symmetry. Called when part is actually duplicated. |
virtual void onCtrlUpd(FlightCtrlState s) | Still under investigation. Called once every frame in-flight or when on tarmac / launchpad, this is the Autopilot pass. |
virtual void onDecouple(float breakForce) | Still under investigation. Called when decoupling. Not entirely sure about the scope. |
void OnDelete() | ? |
void onDetach(bool first) | ? |
virtual void onDisconnect() | Still under investigation. |
virtual void OnDrawStats() | Has attribute [Obsolete("Functional behaviour should really be happening in PartModules now. In any case, this method's been replaced with OnGetStats, where you just return the string.")] |
virtual void onEditorUpdate() | Still under investigation. Called in the editor while this part is in the scene (one has been added from the parts menu, either by floating around during editing or attached to the vessel). |
virtual void onFlightStart() | Still under investigation. Called when flight begins (vessel is 'launched'), before updates are called (in loading screen). |
virtual void onFlightStartAtLaunchPad() | Still under investigation. Likely when flight begins before updates are called, but only if launched from the VAB/Launch-Pad. |
virtual void onFlightStateLoad(Dictionary〈string, KSPParseable〉 parsedData) | Still under investigation. Probably when the game is loaded mid-flight (quickload). |
virtual void onFlightStateSave(Dictionary〈string, KSPParseable〉 partDataCollection) | Still under investigation. Probably when the game is saved mid-flight (quicksave). |
virtual void onGamePause() | Still under investigation. Called once any time the game is paused by calling the flight log, pressing Escape or other methods. |
virtual void onGameResume() | Still under investigation. Called once any time the game is unpaused by leaving the flight log, pressing Escape or other methods. |
virtual string OnGetStats() | ? |
virtual void onJointDisable() | Still under investigation. Knowledge about Unity indicates probable call when joints are disabled on models with bones and animations. |
virtual void onJointReset() | Still under investigation. Knowledge about Unity indicates probable call when joints are reset on models with bones and animations. |
void OnLiftOff() | ? |
void OnLoad() | ? |
virtual void OnLoad(ConfigNode node) | ? |
virtual void onPack() | Still under investigation. Unknown. Name suggests either an archive part or parachute relation. |
virtual bool onPartActivate() | Still under investigation. Probably when activating the part through the right-mouse-button menu (context-menu) in-flight. |
virtual void onPartAttach(Part parent) | Still under investigation. Called once in the editor for each time part is attached to vessel. |
virtual void onPartAwake() | Still under investigation. Called once during boot (the first loading process) before and after onLoad. Called once in the editor(s) when loading the part to the scene, either by loading a vessel or adding the part from the parts menu. Probably called any and everytime the part is loaded in a scene, either as individual part or part of a vessel. Knowledge about Unity indicates probable gameObject initialization and registration with the proper controllers. |
virtual void onPartDeactivate() | Still under investigation. Probably when deactivating the part through the right-mouse-button menu (context-menu) in-flight. |
virtual void onPartDelete() | Still under investigation. Called once when removed from scene. Probably called on more occasions where a different vessel or scene is about to be loaded and the part is not used there. Often called prior to onPartDestroy, probably to make sure the part is gone. |
virtual void onPartDestroy() | Still under investigation. Called once when removed from scene. Probably called on more occasions where a different vessel or scene is about to be loaded and the part is not used there. |
virtual void onPartDetach() | Still under investigation. Called in the editor(s) when part is detached from vessel. |
virtual void onPartExplode() | Still under investigation. Called once when part is suffering too much stress, either by twisting, turning, temperature, less-than-gracefull-landings, etc. |
virtual void onPartFixedUpdate() | Still under investigation. Called in-flight once every physics frame. The forces acting upon this part are calculated in its base-method and can be supplemented here. |
void OnPartJointBreak(float breakForce) | ? |
virtual void onPartLiftOff() | Still under investigation. Called once when the vessel carrying this part is succesfully fighting gravity. |
virtual void onPartLoad() | Still under investigation. Called once when booting (first loading screen). Have not seen this anywhere else yet, called when loading the assets (CFG, textures, models, etc.) for this part. |
virtual void onPartSplashdown() | Still under investigation. Called once when the part says 'blubblub'; Is touching water. Not sure if it reacts regardless of being attached to the vessel or not. |
virtual void onPartStart() | Still under investigation. Called every time this part requires initialization; Every time the part is loaded into a scene. |
virtual void onPartTouchdown() | Still under investigation. Called once when the part or its vessel has landed. |
virtual void onPartUpdate() | Still under investigation. Called in-flight once every logic frame. This is where functionality can be added to the part. |
virtual void OnSave(ConfigNode node) | ? |
void OnSplashDown() | ? |
virtual void onStartComplete() | ? |
void OnTouchDown() | ? |
virtual void onUnpack() | ? |
void Pack() | ? |
void PromoteToPhysicalPart() | ? |
void propagateControlUpdate(FlightCtrlState st) | This probably lets you give the Part flight input commands (pitch, yaw, roll, etc.) as if they came from the user. See the API:FlightCtrlState class. |
void RegisterCrew() | ? |
void removeChild(Part child) | ? |
void RemoveCrewmember(ProtoCrewMember crew) | ? |
void RemoveModule(PartModule module) | ? |
void RemoveModules() | ? |
void RemoveOnMouseDown(OnActionDelegate method) | ? |
void RemoveOnMouseEnter(OnActionDelegate method) | ? |
void RemoveOnMouseExit(OnActionDelegate method) | ? |
void RemoveShield(IAirstreamShield shd) | ? |
virtual bool RequestFuel(Part source, float amount, uint reqId) | Asks the part for a given amount of fuel. This will drain the requested amount of fuel either from the Part you call this on, or from some other part(s) that this part can draw fuel from. You must pass in a fuel request ID generated by the static funtion Part.getFuelReqId(). This function returns true if it was able to fulfill the fuel request. One way you can use this function is to request 0 fuel, and use the return value to test whether the part has access to fuel (it will return false if it has nowhere to draw fuel from). Has attribute [Obsolete("Use Part.RequestResource instead.")] |
virtual bool RequestRCS(float amount, int earliestStage) | Has attribute [Obsolete("Use Part.RequestResource instead.")] |
virtual float RequestResource(string resourceName, float demand) | Requests a part resource. Returns the provided amount of the resource. |
virtual double RequestResource(string resourceName, double demand) | ? |
virtual double RequestResource(int resourceID, double demand) | ? |
virtual float RequestResource(int resourceID, float demand) | Same as above, but takes the hashcode of the resource name. |
virtual double RequestResource(string resourceName, double demand, ResourceFlowMode flowMode) | ? |
virtual double RequestResource(int resourceID, double demand, ResourceFlowMode flowMode) | ? |
void ResetCollisionIgnores() | ? Has attribute [ContextMenu("Reset Collision Ignores")] |
IEnumerator ResetJoints() | ? Has attribute [DebuggerHidden] |
void ResumeVelocity() | ? |
void SaveEffects(ConfigNode node) | ? |
void ScheduleSetCollisionIgnores() | ? |
void SendEvent(string eventName) | Sends an event to this part. You can find out what events this part responds to by looking at the Events property. Events seem to be propagated throughout the part tree, so to send an event to the whole ship you can probably just send it to the root part of the vessel. |
void SendEvent(string eventName, BaseEventData data) | ? |
void SendEvent(string eventName, BaseEventData data, int maxDepth) | ? |
void SetCollisionIgnores() | ? |
void SetDetectCollisions(bool setState) | ? |
void SetHierarchyRoot(Part root) | ? |
void SetHighlight(bool active, bool recursive) | ? |
void SetHighlightColor() | ? |
void SetHighlightColor(Color color) | ? |
void SetHighlightDefault() | ? |
void SetHighlightType(HighlightType type) | ? |
void SetLayer(GameObject obj, int layer) | ? |
void SetMirror(Vector3 mirrorVector) | ? |
void setOpacity(float opacity) | ? |
void setParent(Part p) | ? |
void SetReferenceTransform(Transform t) | ? |
void SetResource(ConfigNode node) | ? |
void SpawnCrew() | ? |
double TransferResource(int resourceID, double amount) | ? |
void Undock(DockedVesselInfo newVesselInfo) | ? |
void unfreeze() | ? |
void Unpack() | ? |
void UnregisterCrew() | ? |
void UpdateOrgPosAndRot(Part newRoot) | ? |
static Part FromGO(GameObject obj) | ? |
static Component GetComponentUpwards(string type, GameObject obj) | ? |
static uint getFuelReqId() | ? |
static int NewRequestID() | ? |
static Vector3 PartToVesselSpaceDir(Vector3 dir, Part p, Vessel v, PartSpaceMode space) | ? |
static Vector3 PartToVesselSpacePos(Vector3 pos, Part p, Vessel v, PartSpaceMode space) | ? |
static Quaternion PartToVesselSpaceRot(Quaternion rot, Part p, Vessel v, PartSpaceMode space) | ? |
static Vector3 VesselToPartSpaceDir(Vector3 dir, Part p, Vessel v, PartSpaceMode space) | ? |
static Vector3 VesselToPartSpacePos(Vector3 pos, Part p, Vessel v, PartSpaceMode space) | ? |
static Quaternion VesselToPartSpaceRot(Quaternion rot, Part p, Vessel v, PartSpaceMode space) | ? |
Other API
Part also contains the following, not included above.
... public sealed class DragModel : Enum { public const DragModel CONIC = 1; public const DragModel CUBE = 4; public const DragModel CYLINDRICAL = 2; public const DragModel DEFAULT = 0; public const DragModel NONE = 5; public const DragModel SPHERICAL = 3; public int value__; } public sealed class HighlightType : Enum { public const HighlightType AlwaysOn = 2; public const HighlightType Disabled = 0; public const HighlightType OnMouseOver = 1; public int value__; } public sealed class OnActionDelegate : MulticastDelegate { public OnActionDelegate(object @object, IntPtr method); public virtual IAsyncResult BeginInvoke(Part p, AsyncCallback callback, object @object); public virtual void EndInvoke(IAsyncResult result); public virtual void Invoke(Part p); } public sealed class PhysicalSignificance : Enum { public const PhysicalSignificance FULL = 0; public const PhysicalSignificance NONE = 1; public int value__; } ...