Difference between revisions of "API:PartModule"

From Kerbal Space Program Wiki
Jump to: navigation, search
m (Reverted edits by Rocketing Rudolph (talk) to last revision by Martincmartin)
 
(4 intermediate revisions by 3 users not shown)
Line 20: Line 20:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
{{Properties|
+
{{Properties|properties=
 
{{Property
 
{{Property
 
   |type=BaseActionList
 
   |type=BaseActionList
Line 122: Line 122:
 
   |name=OnActive
 
   |name=OnActive
 
   |args=
 
   |args=
   |desc=Called when the part is active.
+
   |desc=Called when the part is active.  Not called in VAB or when on launch pad, but is called when stage is started, assuming that activates the module.
 
}}
 
}}
 
{{Method
 
{{Method
Line 129: Line 129:
 
   |name=OnAwake
 
   |name=OnAwake
 
   |args=
 
   |args=
   |desc=Called when the part is loaded, this can be more than once.
+
   |desc=Called when the part is loaded, this can be more than once.  Called when part is selected in VAB, and also when switching from VAB to launch pad.
 
}}
 
}}
 
{{Method
 
{{Method
Line 150: Line 150:
 
   |name=OnInitialize
 
   |name=OnInitialize
 
   |args=
 
   |args=
   |desc=?
+
   |desc=Called when part is selected in VAB, switching to launch pad or loading from a save.
 
}}
 
}}
 
{{Method
 
{{Method
Line 164: Line 164:
 
   |name=OnSave
 
   |name=OnSave
 
   |args={{arg|ConfigNode|node}}
 
   |args={{arg|ConfigNode|node}}
   |desc=Called when the object is saved.
+
   |desc=Called when the object is saved, which happens with any change in VAB, when switching to launch pad, and during auto saving.
 
}}
 
}}
 
{{Method
 
{{Method
Line 171: Line 171:
 
   |name=OnStart
 
   |name=OnStart
 
   |args={{arg|StartState|state}}
 
   |args={{arg|StartState|state}}
   |desc=Called during the part startup.
+
   |desc=Called when entering VAB (with arg Editor), launch pad (with arg PreLaunch | Landed), or loading from save.
 
}}
 
}}
 
{{Method
 
{{Method
Line 188: Line 188:
 
}}
 
}}
 
}}
 
}}
{{Enums|
+
{{Enums|enums=
 
{{Enum
 
{{Enum
 
   |name=StartState
 
   |name=StartState

Latest revision as of 18:49, 17 March 2017

PartModule Class

Inherits Implements
MonoBehaviour

    The PartModule class allows you to override its functions to intuitively control your parts.

    Example

    Called during the main menu loading stage.

    using System;
    using UnityEngine;
     
    public class RandomPart : PartModule
    {
    	public override void OnAwake()
    	{
    		Debug.Log("Hello World");
    	}
    }

    Properties

    The following is a list of properties in PartModule.

    Name Description
    BaseActionList Actions { get; }  ?
    int ClassID { get; }  ?
    string ClassName { get; }  ?
    BaseEventList Events { get; }  ?
    BaseFieldList Fields { get; }  ?
    string GUIName { get; }  ?
    Part part { get; set; }  ?
    Vessel vessel { get; }  ?

    Fields

    The following is a list of fields in PartModule.

    Signature Description
    bool isEnabled The part state.
    string moduleName The module's name.
    ProtoPartModuleSnapshot snapshot  ?

    Methods

    The following are methods included in PartModule.

    Signature Description
    constructor PartModule()  ?
    virtual string GetInfo() Returns the part information displayed in the part list mouse-over information box.
    void Load(ConfigNode node)  ?
    virtual void OnActive() Called when the part is active. Not called in VAB or when on launch pad, but is called when stage is started, assuming that activates the module.
    virtual void OnAwake() Called when the part is loaded, this can be more than once. Called when part is selected in VAB, and also when switching from VAB to launch pad.
    virtual void OnFixedUpdate() Per-PhysX frame update, Called only when the part is active!
    virtual void OnInactive() Get the part information.
    virtual void OnInitialize() Called when part is selected in VAB, switching to launch pad or loading from a save.
    virtual void OnLoad(ConfigNode node) Called when the object is loaded from a save.
    virtual void OnSave(ConfigNode node) Called when the object is saved, which happens with any change in VAB, when switching to launch pad, and during auto saving.
    virtual void OnStart(StartState state) Called when entering VAB (with arg Editor), launch pad (with arg PreLaunch
    virtual void OnUpdate() Called when OnUpdate is called on the part.
    void Save(ConfigNode node)  ?

    Enumerations

    The following is a list of enumerations in PartModule.

    Name Values
    StartState None
    Editor
    PreLaunch
    Landed = 4
    Docked = 8
    Flying = 16
    Splashed = 32
    SubOrbital = 64
    Orbital = 128