private void UpdateNetworkCones() { var antennas = (ShowPlanet ? RTCore.Instance.Antennas.Where(a => a.Powered && a.CanTarget && RTCore.Instance.Satellites[a.Guid] != null && RTCore.Instance.Network.Planets.ContainsKey(a.Target)) : Enumerable.Empty <IAntenna>()).ToList(); int oldLength = mCones.Count; int newLength = antennas.Count; // Free any unused lines for (int i = newLength; i < oldLength; i++) { GameObject.Destroy(mCones[i]); mCones[i] = null; } mCones.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0)); mCones.AddRange(Enumerable.Repeat((NetworkCone)null, Math.Max(newLength - oldLength, 0))); for (int i = 0; i < newLength; i++) { mCones[i] = mCones[i] ?? NetworkCone.Instantiate(); mCones[i].Material = MapView.fetch.orbitLinesMaterial; mCones[i].LineWidth = 2.0f; mCones[i].Antenna = antennas[i]; mCones[i].Planet = RTCore.Instance.Network.Planets[antennas[i].Target]; mCones[i].Color = Color.gray; mCones[i].Active = ShowPlanet; } }
private void UpdateNetworkCones() { List <IAntenna> antennas = (ShowCone ? RTCore.Instance.Antennas.Where( ant => ant.Powered && ant.CanTarget && RTCore.Instance.Satellites[ant.Guid] != null && ant.Target != Guid.Empty) : Enumerable.Empty <IAntenna>()).ToList(); int oldLength = mCones.Count; int newLength = antennas.Count; // Free any unused lines for (int i = newLength; i < oldLength; i++) { GameObject.Destroy(mCones[i]); mCones[i] = null; } mCones.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0)); mCones.AddRange(Enumerable.Repeat((NetworkCone)null, Math.Max(newLength - oldLength, 0))); for (int i = 0; i < newLength; i++) { var center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target); Debug.Assert(center != null, "center != null", String.Format("GetPositionFromGuid returned a null value for the target {0}", antennas[i].Target) ); if (!center.HasValue) { continue; } mCones[i] = mCones[i] ?? NetworkCone.Instantiate(); mCones[i].Material = MapView.fetch.orbitLinesMaterial; mCones[i].LineWidth = 2.0f; mCones[i].Antenna = antennas[i]; mCones[i].Color = Color.gray; mCones[i].Active = ShowCone; mCones[i].Center = center.Value; } }