コード例 #1
0
        public void SendVesselMessage(Vessel vessel, bool forceReload = false)
        {
            if (vessel == null || vessel.state == Vessel.State.DEAD || VesselRemoveSystem.Singleton.VesselWillBeKilled(vessel.id))
            {
                return;
            }

            if (!vessel.orbitDriver)
            {
                LunaLog.LogWarning($"Cannot send vessel {vessel.vesselName} - {vessel.id}. It's orbit driver is null!");
                return;
            }

            if (vessel.orbitDriver.Ready())
            {
                vessel.protoVessel = vessel.BackupVessel();
                SendVesselMessage(vessel.protoVessel, forceReload);
            }
            else
            {
                //Orbit driver is not ready so wait max 10 frames until it's ready
                CoroutineUtil.StartConditionRoutine("SendVesselMessage",
                                                    () => SendVesselMessage(vessel),
                                                    () => vessel.orbitDriver.Ready(), 10);
            }
        }
コード例 #2
0
        /// <summary>
        /// Sends a vessel position update
        /// </summary>
        /// <param name="vessel">Vessel to send the position</param>
        /// <param name="doOrbitDriverReadyCheck">Set it to true if you want to check if the driver is ready.
        /// Avoid checking it unless is really needed as it uses reflection that's slow</param>
        public void SendVesselPositionUpdate(Vessel vessel, bool doOrbitDriverReadyCheck = false)
        {
            if (vessel == null)
            {
                return;
            }

            if (doOrbitDriverReadyCheck && !vessel.orbitDriver.Ready())
            {
                //Orbit driver is not ready so wait max 10 frames until it's ready
                CoroutineUtil.StartConditionRoutine("SendVesselPositionUpdate",
                                                    () => SendVesselPositionUpdate(vessel),
                                                    () => vessel.orbitDriver.Ready(), 10);
            }
            else
            {
                var msg = CreateMessageFromVessel(vessel);
                if (msg == null)
                {
                    return;
                }

                SendMessage(msg);
            }
        }