示例#1
0
        private void SetRelayVertices(IAntennaRelay relay)
        {
            log.AppendFormat("\n\t\tDrawing line for relay chain starting at {0}.", relay);

            if (relay.vessel == null)
            {
                log.Append("\n\t\tvessel is null, bailing out");
                return;
            }

            LineRenderer renderer = this[relay.vessel.id];
            Vector3      start    = ScaledSpace.LocalToScaledSpace(relay.vessel.GetWorldPos3D());

            float lineWidth;
            float d = Screen.height / 2f + 0.01f;

            if (MapView.Draw3DLines)
            {
                lineWidth = 0.00833333333f * MapView.MapCamera.Distance;
            }
            else
            {
                lineWidth = 3f;

                // TODO: No idea if this substitution is right.
                // start = MapView.MapCamera.camera.WorldToScreenPoint(start);
                start = PlanetariumCamera.Camera.WorldToScreenPoint(start);

                start.z = start.z >= 0f ? d : -d;
            }

            renderer.SetWidth(lineWidth, lineWidth);

            renderer.SetPosition(0, start);

            int idx = 0;

                        #if DEBUG
            relayStart = timer.ElapsedMilliseconds;
                        #endif

            Vector3 nextPoint;

            renderer.enabled = true;

            if (!relay.CanTransmit())
            {
                thisColor = Color.red;
            }
            else
            {
                if (relay.LinkStatus == ConnectionStatus.Optimal)
                {
                    thisColor = Color.green;
                }
                else
                {
                    thisColor = Color.yellow;
                }
            }

            if (relay.KerbinDirect)
            {
                nextPoint = ScaledSpace.LocalToScaledSpace(AntennaRelay.Kerbin.position);
            }
            else
            {
                if (relay.targetRelay == null || relay.targetRelay.vessel == null)
                {
                    this.LogError(
                        "SetRelayVertices: relay {0} has null target relay or vessel when not KerbinDirect, bailing out!",
                        relay
                        );

                    renderer.enabled = false;
                    return;
                }

                switch (relay.targetRelay.vessel.vesselType)
                {
                case VesselType.Debris:
                case VesselType.Flag:
                case VesselType.Unknown:
                    renderer.enabled = false;
                    return;

                default:
                    break;
                }

                nextPoint = ScaledSpace.LocalToScaledSpace(relay.targetRelay.vessel.GetWorldPos3D());
            }

            renderer.SetColors(thisColor, thisColor);

            if (!MapView.Draw3DLines)
            {
                // TODO: No idea if this substitution is right.
                // nextPoint = MapView.MapCamera.camera.WorldToScreenPoint(nextPoint);
                nextPoint   = PlanetariumCamera.Camera.WorldToScreenPoint(nextPoint);
                nextPoint.z = nextPoint.z >= 0f ? d : -d;
            }

            idx++;

            renderer.SetVertexCount(idx + 1);
            renderer.SetPosition(idx, nextPoint);

            log.AppendFormat("\n\t\t\t...finished segment in {0} ms", timer.ElapsedMilliseconds - relayStart);
        }
		private void SetRelayVertices(IAntennaRelay relay)
		{
			log.AppendFormat("\n\t\tDrawing line for relay chain starting at {0}.", relay);

			if (relay.vessel == null)
			{
				log.Append("\n\t\tvessel is null, bailing out");
				return;
			}

			LineRenderer renderer = this[relay.vessel.id];
			Vector3 start = ScaledSpace.LocalToScaledSpace(relay.vessel.GetWorldPos3D());

			float lineWidth;
			float d = Screen.height / 2f + 0.01f;

			if (MapView.Draw3DLines)
			{
				lineWidth = 0.00833333333f * MapView.MapCamera.Distance;
			}
			else
			{
				lineWidth = 3f;

				// TODO: No idea if this substitution is right.
				// start = MapView.MapCamera.camera.WorldToScreenPoint(start);
				start = PlanetariumCamera.Camera.WorldToScreenPoint(start);

				start.z = start.z >= 0f ? d : -d;
			}

			renderer.SetWidth(lineWidth, lineWidth);

			renderer.SetPosition(0, start);

			int idx = 0;

			#if DEBUG
			relayStart = timer.ElapsedMilliseconds;
			#endif

			Vector3 nextPoint;

			renderer.enabled = true;

			if (!relay.CanTransmit())
			{
				thisColor = Color.red;
			}
			else
			{
				if (relay.LinkStatus == ConnectionStatus.Optimal)
				{
					thisColor = Color.green;
				}
				else
				{
					thisColor = Color.yellow;
				}
			}

			if (relay.KerbinDirect)
			{
				nextPoint = ScaledSpace.LocalToScaledSpace(AntennaRelay.Kerbin.position);
			}
			else
			{
				if (relay.targetRelay == null || relay.targetRelay.vessel == null)
				{
					this.LogError(
						"SetRelayVertices: relay {0} has null target relay or vessel when not KerbinDirect, bailing out!",
						relay
					);

					renderer.enabled = false;
					return;
				}

				switch (relay.targetRelay.vessel.vesselType)
				{
					case VesselType.Debris:
					case VesselType.Flag:
					case VesselType.Unknown:
						renderer.enabled = false;
						return;
					default:
						break;
				}

				nextPoint = ScaledSpace.LocalToScaledSpace(relay.targetRelay.vessel.GetWorldPos3D());
			}

			renderer.SetColors(thisColor, thisColor);

			if (!MapView.Draw3DLines)
			{
				// TODO: No idea if this substitution is right.
				// nextPoint = MapView.MapCamera.camera.WorldToScreenPoint(nextPoint);
				nextPoint = PlanetariumCamera.Camera.WorldToScreenPoint(nextPoint);
				nextPoint.z = nextPoint.z >= 0f ? d : -d;
			}

			idx++;

			renderer.SetVertexCount(idx + 1);
			renderer.SetPosition(idx, nextPoint);

			log.AppendFormat("\n\t\t\t...finished segment in {0} ms", timer.ElapsedMilliseconds - relayStart);
		}