public static void CheckMaterial(BridgeEdge bridgeEdge) { if (!bridgeEdge.m_MeshRenderer.material.HasProperty(stressId)) { Material originalMaterial = null; Material originalSharedMaterial = null; try { int hashCode = bridgeEdge.GetHashCode(); List <Material> originalMaterialList = originMaterials[hashCode]; if (originalMaterialList != null) { originalMaterial = originalMaterialList[0]; originalSharedMaterial = originalMaterialList[1]; } originMaterials.Remove(hashCode); } catch (KeyNotFoundException) { staticLogger.LogMessage("Edge has no original material, assuming it's fine"); } if (originalMaterial != null) { bridgeEdge.m_MeshRenderer.material = originalMaterial; } if (originalSharedMaterial != null) { bridgeEdge.m_MeshRenderer.sharedMaterial = originalSharedMaterial; } } }
private static void SetShaderColor(BridgeEdge bridgeEdge, float stressNormalized, float stressNormalizedSigned) { Color minColor; Color maxColor; if (stressNormalizedSigned <= 0.0f) { minColor = minTensileColor; maxColor = maxTensileColor; } else { minColor = minCompressiveColor; maxColor = maxCompressiveColor; } if (minColor == null || maxColor == null) { return; } Color desiredColor = Color.Lerp(minColor, maxColor, stressNormalized); if (bridgeEdge.m_MeshRenderer.material.HasProperty(stressId)) { originMaterials[bridgeEdge.GetHashCode()] = new List <Material> { bridgeEdge.m_MeshRenderer.material, bridgeEdge.m_MeshRenderer.sharedMaterial }; bridgeEdge.m_MeshRenderer.material = new Material(Shader.Find("Standard")); bridgeEdge.m_MeshRenderer.sharedMaterial = new Material(Shader.Find("Standard")); } bridgeEdge.m_MeshRenderer.material.color = desiredColor; bridgeEdge.m_MeshRenderer.sharedMaterial.color = desiredColor; }