public void Start()
        {
            try
            {
                vesselRef = GetComponent<Vessel>();

                if (vesselRef == null || vesselRef.isEVA || !vesselRef.isCommandable || vesselRef.parts[0].Modules.Contains<FlagSite>())
                {
                    vesselRef = null;
                    Destroy(this);
                    return;
                }
                else
                {
                    vesselAsst = new PilotAssistant(this);
                    vesselData = new VesselData(this);
                }
                PilotAssistantFlightCore.Instance.addVessel(this);

                vesselAsst.Start();
            }
            catch (Exception ex)
            {
                Debug.LogError("Pilot Assistant: Startup error");
                Debug.LogError(ex.InnerException);
            }
            vesselRef.OnPreAutopilotUpdate += new FlightInputCallback(preAutoPilotUpdate);
            vesselRef.OnPostAutopilotUpdate += new FlightInputCallback(postAutoPilotUpdate);

            GameEvents.onPartCouple.Add(docking);
            GameEvents.onVesselChange.Add(vesselSwitch);
            GameEvents.onTimeWarpRateChanged.Add(warpHandler);
        }
        public void OnDestroy()
        {
            if (Vessel != null)
            {
                GameEvents.onVesselChange.Remove(vesselSwitch);
                GameEvents.onTimeWarpRateChanged.Remove(warpHandler);

                Vessel.OnPreAutopilotUpdate -= preAutoPilotUpdate;
                Vessel.OnPostAutopilotUpdate -= postAutoPilotUpdate;
                if (!ReferenceEquals(vesselAsst, null))
                {
                    vesselAsst.OnDestroy();
                    if (!ReferenceEquals(PilotAssistantFlightCore.Instance, null))
                        PilotAssistantFlightCore.Instance.removeVessel(this);
                }
                vesselAsst = null;
                vesselData = null;
            }
        }
        public void OnDestroy()
        {
            GameEvents.onVesselChange.Remove(vesselSwitch);
            GameEvents.onTimeWarpRateChanged.Remove(warpHandler);
            GameEvents.onPartCouple.Remove(docking);

            if (vesselRef != null)
            {
                vesselRef.OnPreAutopilotUpdate -= preAutoPilotUpdate;
                vesselRef.OnPostAutopilotUpdate -= postAutoPilotUpdate;
            }
            if (!ReferenceEquals(vesselAsst, null))
                vesselAsst.OnDestroy();
            if (!ReferenceEquals(vesselData, null) && !ReferenceEquals(PilotAssistantFlightCore.Instance, null))
                PilotAssistantFlightCore.Instance.removeVessel(this);

            vesselRef = null;
            vesselSSAS = null;
            vesselStockSAS = null;
            vesselAsst = null;
            vesselData = null;
        }
        protected override void OnStart()
        {
            base.OnStart();
            try
            {
                vesselAsst = new PilotAssistant(this);
                vesselData = new VesselData(this);
                PilotAssistantFlightCore.Instance.addVessel(this);

                vesselAsst.Start();

                Vessel.OnPreAutopilotUpdate += new FlightInputCallback(preAutoPilotUpdate);
                Vessel.OnPostAutopilotUpdate += new FlightInputCallback(postAutoPilotUpdate);

                GameEvents.onVesselChange.Add(vesselSwitch);
                GameEvents.onTimeWarpRateChanged.Add(warpHandler);
            }
            catch (Exception ex)
            {
                Utils.LogError("Startup error");
                Utils.LogError(ex.Message);
                Utils.LogError(ex.InnerException);
                Utils.LogError(ex.StackTrace);
            }
        }