void OnWillRenderObject() { if (r) { var camera = Camera.current; var sssssMain = camera.GetComponent <CP_SSSSS_Main>(); if (sssssMain && sssssMain.isActiveAndEnabled) { if (Application.isPlaying) { for (int i = 0; i < subMeshIndicies.Count; ++i) { sssssMain.AddRenderer(r, subMeshIndicies[i], parameters[i]); } } else { var sharedMaterials = r.sharedMaterials; for (int i = 0; i < sharedMaterials.Length; ++i) { var material = sharedMaterials[i]; if (scatteringColorsPerSubmesh != null && i < scatteringColorsPerSubmesh.Length && scatteringColorsPerSubmesh[i].color != Color.black && material.renderQueue != (int)UnityEngine.Rendering.RenderQueue.Transparent) { subMeshIndicies.Add(i); sssssMain.AddRenderer(r, i, CP_SSSSS_Main.MakeSSSParameterFromTextureAndColor(scatteringColorsPerSubmesh[i])); } else if (CP_SSSSS_Main.HasMaterialSSSParameter(material) && material.renderQueue != (int)UnityEngine.Rendering.RenderQueue.Transparent) { sssssMain.AddRenderer(r, i, CP_SSSSS_Main.MakeSSSParameterFromMaterial(material)); } } } } } }
// Use this for initialization void Start() { r = GetComponent <Renderer>(); parameters.Clear(); subMeshIndicies.Clear(); if (r) { var sharedMaterials = r.sharedMaterials; for (int i = 0; i < sharedMaterials.Length; ++i) { var material = sharedMaterials[i]; if (i < scatteringColorsPerSubmesh.Length && scatteringColorsPerSubmesh[i].color != Color.black && material.renderQueue != (int)UnityEngine.Rendering.RenderQueue.Transparent) { subMeshIndicies.Add(i); parameters.Add(CP_SSSSS_Main.MakeSSSParameterFromTextureAndColor(scatteringColorsPerSubmesh[i])); } else if (CP_SSSSS_Main.HasMaterialSSSParameter(material) && material.renderQueue != (int)UnityEngine.Rendering.RenderQueue.Transparent) { subMeshIndicies.Add(i); parameters.Add(CP_SSSSS_Main.MakeSSSParameterFromMaterial(material)); } } } }