public void OnDestroy() { if (reflectionScript != null) { reflectionScript.destroy(); } }
public override void OnStart(StartState state) { Reflections reflections = Reflections.instance; Shader reflectiveShader = shader.Length == 0 ? null : Shader.Find(shader); Color reflectionColour = new Color(0.5f, 0.5f, 0.5f); int updateInterval = 1; Util.parse(ReflectionColor, ref reflectionColour); Util.parse(colour, ref reflectionColour); Util.parse(interval, ref updateInterval); updateInterval = Math.Max(updateInterval, 1); List <string> meshNames = Util.splitConfigValue(meshes).ToList(); if (MeshesToChange != "all") { meshNames.AddUniqueRange(Util.splitConfigValue(MeshesToChange)); } if (reflections.reflectionType == Reflections.Type.NONE) { return; } if (reflections.reflectionType == Reflections.Type.REAL) { script = new Reflections.Script(part, updateInterval); } if (reflections.logReflectiveMeshes) { Util.log("Part \"{0}\"", part.name); } bool success = false; foreach (MeshFilter meshFilter in part.FindModelComponents <MeshFilter>()) { if (meshFilter.renderer == null) { continue; } Material material = meshFilter.renderer.material; if (reflections.logReflectiveMeshes) { Util.log("+ {0} [{1}]", meshFilter.name, material.shader.name); } if (meshNames.Count == 0 || meshNames.Contains(meshFilter.name)) { success |= script == null? reflections.applyStatic(material, reflectiveShader, reflectionColour) : script.apply(material, reflectiveShader, reflectionColour); } } if (!success) { if (script != null) { script.destroy(); script = null; } Util.log("Failed to replace any shader on \"{0}\" with its reflective counterpart", part.name); } }