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;
        }
        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;
        }
        public void Start()
        {
            try
            {
                vesselRef = GetComponent <Vessel>();
                if (vesselRef == null || vesselRef.isEVA || !vesselRef.isCommandable)
                {
                    vesselRef = null;
                    Destroy(this);
                    return;
                }
                else
                {
                    vesselAsst     = new PilotAssistant(this);
                    vesselSSAS     = new SurfSAS(this);
                    vesselStockSAS = new Stock_SAS(this);
                    vesselData     = new VesselData(this);
                }


                PilotAssistantFlightCore.Instance.addVessel(this);

                vesselAsst.Start();
                vesselSSAS.Start();
                vesselStockSAS.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 Start()
        {
            try
            {
                vesselRef = GetComponent<Vessel>();
                if (vesselRef == null || vesselRef.isEVA || !vesselRef.isCommandable)
                {
                    vesselRef = null;
                    Destroy(this);
                    return;
                }
                else
                {
                    vesselAsst = new PilotAssistant(this);
                    vesselSSAS = new SurfSAS(this);
                    vesselStockSAS = new Stock_SAS(this);
                    vesselData = new VesselData(this);
                }

                PilotAssistantFlightCore.Instance.addVessel(this);

                vesselAsst.Start();
                vesselSSAS.Start();
                vesselStockSAS.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);
        }