Skip to content

Commit

Permalink
Fix #693 (error "Trying to create a material from string - this is no…
Browse files Browse the repository at this point in the history
… longer supported.")
  • Loading branch information
KSP-TaxiService committed Aug 17, 2018
1 parent e55430c commit 53a3cf2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
23 changes: 19 additions & 4 deletions src/RemoteTech/NetworkRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public MapFilter Filter {
private readonly HashSet<BidirectionalEdge<ISatellite>> mEdges = new HashSet<BidirectionalEdge<ISatellite>>();
private readonly List<NetworkLine> mLines = new List<NetworkLine>();
private readonly List<NetworkCone> mCones = new List<NetworkCone>();
private static float mLineWidth = 1f;

public bool ShowOmni { get { return (Filter & MapFilter.Omni) == MapFilter.Omni; } }
public bool ShowDish { get { return (Filter & MapFilter.Dish) == MapFilter.Dish; } }
Expand All @@ -58,6 +59,22 @@ public MapFilter Filter {
static NetworkRenderer()
{
RTUtil.LoadImage(out mTexMark, "mark");

if(Versioning.version_major == 1)
{
switch(Versioning.version_minor)
{
case 3:
mLineWidth = 3f; //1f is too thin in 1.3
break;
case 4:
mLineWidth = 1f; //1f is matching to CommNet's line width
break;
default:
mLineWidth = 1f;
break;
}
}
}

public static NetworkRenderer CreateAndAttach()
Expand Down Expand Up @@ -237,8 +254,7 @@ private void UpdateNetworkCones()
if (!center.HasValue) continue;

mCones[i] = mCones[i] ?? NetworkCone.Instantiate();
mCones[i].Material = MapView.fetch.orbitLinesMaterial;
mCones[i].LineWidth = 2.0f;
mCones[i].LineWidth = mLineWidth;
mCones[i].Antenna = antennas[i];
mCones[i].Color = Color.gray;
mCones[i].Active = ShowCone;
Expand Down Expand Up @@ -267,8 +283,7 @@ private void UpdateNetworkEdges()
{
it.MoveNext();
mLines[i] = mLines[i] ?? NetworkLine.Instantiate();
mLines[i].Material = MapView.fetch.orbitLinesMaterial;
mLines[i].LineWidth = 3.0f;
mLines[i].LineWidth = mLineWidth;
mLines[i].Edge = it.Current;
mLines[i].Color = CheckColor(it.Current);
mLines[i].Active = true;
Expand Down
6 changes: 5 additions & 1 deletion src/RemoteTech/UI/NetworkCone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace RemoteTech.UI
{
public class NetworkCone : MonoBehaviour
{
private static Material CommNetMaterial = null;

public Vector3d Center
{
set
Expand Down Expand Up @@ -55,11 +57,13 @@ public static NetworkCone Instantiate()

public void Awake()
{
if (CommNetMaterial == null) { CommNetMaterial = Resources.Load<Material>("Telemetry/TelemetryMaterial"); }

SetupMesh();
gameObject.layer = 31;
LineWidth = 1.0f;
Color = Color.white;
Material = new Material("Shader \"Vertex Colors/Alpha\" {Category{Tags {\"Queue\"=\"Transparent\" \"IgnoreProjector\"=\"True\" \"RenderType\"=\"Transparent\"}SubShader {Cull Off ZWrite On Blend SrcAlpha OneMinusSrcAlpha Pass {BindChannels {Bind \"Color\", color Bind \"Vertex\", vertex}}}}}");
Material = CommNetMaterial;
}

private void UpdateMesh(Vector3d center, IAntenna dish)
Expand Down
6 changes: 5 additions & 1 deletion src/RemoteTech/UI/NetworkLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace RemoteTech.UI
{
public class NetworkLine : MonoBehaviour
{
private static Material CommNetMaterial = null;

public BidirectionalEdge<ISatellite> Edge
{
set
Expand Down Expand Up @@ -53,11 +55,13 @@ public static NetworkLine Instantiate()

public void Awake()
{
if (CommNetMaterial == null) { CommNetMaterial = Resources.Load<Material>("Telemetry/TelemetryMaterial"); }

SetupMesh();
gameObject.layer = 31;
LineWidth = 1.0f;
Color = Color.white;
Material = new Material("Shader \"Vertex Colors/Alpha\" {Category{Tags {\"Queue\"=\"Transparent\" \"IgnoreProjector\"=\"True\" \"RenderType\"=\"Transparent\"}SubShader {Cull Off ZWrite On Blend SrcAlpha OneMinusSrcAlpha Pass {BindChannels {Bind \"Color\", color Bind \"Vertex\", vertex}}}}}");
Material = CommNetMaterial;
}

private void UpdateMesh(BidirectionalEdge<ISatellite> edge)
Expand Down

0 comments on commit 53a3cf2

Please sign in to comment.