public void autopilotModeCallback(byte ID, object Data) { byte[] payload = (byte[])Data; VesselAutopilot autopilot = FlightGlobals.ActiveVessel.Autopilot; if (autopilot == null) { Debug.Log("KerbalSimpit : Ignoring a SAS MODE Message since I could not find the autopilot"); return; } mySASMode = (VesselAutopilot.AutopilotMode)(payload[0]); if (autopilot.CanSetMode(mySASMode)) { autopilot.SetMode(mySASMode); if (KSPit.Config.Verbose) { Debug.Log(String.Format("KerbalSimpit: payload is {0}", mySASMode)); Debug.Log(String.Format("KerbalSimpit: SAS mode is {0}", FlightGlobals.ActiveVessel.Autopilot.Mode.ToString())); } } else { Debug.Log(String.Format("KerbalSimpit: Unable to set SAS mode to {0}", mySASMode.ToString())); } }
public static bool SetActualMode(this VesselAutopilot autopilot, VesselAutopilot.AutopilotMode mode) { mode = ConvertMode(mode); if (autopilot.CanSetMode(mode)) { var result = autopilot.SetMode(mode); var autopilotUI = GameObject.FindObjectOfType <VesselAutopilotUI>(); if (autopilotUI != null && mode >= 0 && (int)mode < autopilotUI.modeButtons.Length) { autopilotUI.modeButtons[(int)mode].SetState(true); } return(result); } return(false); }
public void SASInfoProvider() { if (FlightGlobals.ActiveVessel == null) { // This can happen when docking/undocking/changing scene, etc. return; } VesselAutopilot autopilot = FlightGlobals.ActiveVessel.Autopilot; if (autopilot == null) { return; } if (autopilot.Enabled) { newSASInfo.currentSASMode = (byte)autopilot.Mode; } else { newSASInfo.currentSASMode = 255; //special value to indicate a disabled SAS } newSASInfo.SASModeAvailability = 0; foreach (VesselAutopilot.AutopilotMode i in Enum.GetValues(typeof(VesselAutopilot.AutopilotMode))) { if (autopilot.CanSetMode(i)) { newSASInfo.SASModeAvailability = (ushort)(newSASInfo.SASModeAvailability | (1 << (byte)i)); } } if (mySASInfo.currentSASMode != newSASInfo.currentSASMode || mySASInfo.SASModeAvailability != newSASInfo.SASModeAvailability) { if (SASInfoChannel != null) { mySASInfo = newSASInfo; SASInfoChannel.Fire(OutboundPackets.SASInfo, mySASInfo); } } }
public static bool CanSetActualMode(this VesselAutopilot autopilot, VesselAutopilot.AutopilotMode mode) { return(autopilot.CanSetMode(ConvertMode(mode))); }