List<Material> materials = new List<Material>();
//检测模型是否被遮挡
private void UpdateMaterials()
{
RaycastHit rh;
if (Physics.Linecast(Camera.main.transform.position, transform.position, out rh, LayerMask.GetMask("Build")))
{
Material material = rh.transform.GetComponentInChildren<MeshRenderer>().materials[0];
if (!materials.Contains(material))
{
materials.Add(material);
material.shader = Shader.Find("Standard");
material.SetFloat("_Mode", 3);
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = 3000;
material.SetColor("_Color", new Color(1, 1, 1, 0.3f));
}
}
else
{
materials.ForEach((temp) => {
temp.shader = Shader.Find("Mobile/Diffuse");
});
materials.Clear();
}
}
网友评论