ModelXuHua.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using DG.Tweening;
  4. using UnityEngine;
  5. public class ModelXuHua : MonoBehaviour
  6. {
  7. public GameObject teshu;
  8. public GameObject teshuXs;
  9. public bool isXS=false;
  10. public List<Material> mats;
  11. public GameObject TabGo;
  12. public GameObject baimo;
  13. public GameObject texiao;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. }
  18. public void showModel(bool isshow=true)
  19. {
  20. baimo.SetActive(false);
  21. this.gameObject.SetActive(true);
  22. if(this.texiao)
  23. this.texiao.SetActive(true);
  24. Debug.Log("showModel===>"+isshow);
  25. if(teshu)
  26. teshu.SetActive(isshow);
  27. if(teshuXs&&isshow)
  28. {
  29. teshuXs.SetActive(false);
  30. }
  31. }
  32. public void showBaiMo()
  33. {
  34. if(teshuXs)
  35. teshuXs.SetActive(true);
  36. if(teshu)
  37. teshu.SetActive(false);
  38. if(this.texiao)
  39. this.texiao.SetActive(false);
  40. if(isXS)
  41. {
  42. baimo.SetActive(false);
  43. this.gameObject.SetActive(false);
  44. return;
  45. }
  46. baimo.SetActive(true);
  47. this.gameObject.SetActive(false);
  48. for (int i = 0;i<mats.Count;i++)
  49. {
  50. Color c = mats[i].GetColor("_Color");
  51. mats[i].SetColor("_Color",new Color(c.r,c.g,c.b,1f));
  52. mats[i].DOColor(new Color(c.r,c.g,c.b,0.3f),0.5f).OnComplete(()=>{ });
  53. }
  54. }
  55. public void show()
  56. {
  57. this.gameObject.SetActive(true);
  58. }
  59. public void changemode()
  60. {
  61. }
  62. public void hide()
  63. {
  64. if(!baimo.activeSelf)
  65. {
  66. baimo.SetActive(true);
  67. this.gameObject.SetActive(false);
  68. for (int i = 0;i<mats.Count;i++)
  69. {
  70. Color c = mats[i].GetColor("_Color");
  71. mats[i].SetColor("_Color",new Color(c.r,c.g,c.b,1f));
  72. mats[i].DOColor(new Color(c.r,c.g,c.b,0f),0.5f).OnComplete(()=>{ baimo.SetActive(false);});
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 设置材质的 Albedo 颜色
  78. /// </summary>
  79. /// <param name="material">目标材质</param>
  80. /// <param name="color">目标颜色</param>
  81. public static void SetAlbedoColor(Material material, Color color)
  82. {
  83. if (material != null)
  84. {
  85. // 设置 _Color 属性
  86. material.SetColor("_Color", color);
  87. }
  88. else
  89. {
  90. Debug.LogError("Material is null!");
  91. }
  92. }
  93. public enum RenderingMode
  94. {
  95. Opaque,
  96. Cutout,
  97. Fade,
  98. Transparent
  99. }
  100. public static void SetMaterialRenderingMode(Material material, RenderingMode mode)
  101. {
  102. switch (mode)
  103. {
  104. case RenderingMode.Opaque:
  105. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
  106. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
  107. material.SetInt("_ZWrite", 1);
  108. material.DisableKeyword("_ALPHATEST_ON");
  109. material.DisableKeyword("_ALPHABLEND_ON");
  110. material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
  111. material.renderQueue = -1;
  112. break;
  113. case RenderingMode.Cutout:
  114. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
  115. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
  116. material.SetInt("_ZWrite", 1);
  117. material.EnableKeyword("_ALPHATEST_ON");
  118. material.DisableKeyword("_ALPHABLEND_ON");
  119. material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
  120. material.renderQueue = 2450;
  121. break;
  122. case RenderingMode.Fade:
  123. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
  124. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
  125. material.SetInt("_ZWrite", 0);
  126. material.DisableKeyword("_ALPHATEST_ON");
  127. material.EnableKeyword("_ALPHABLEND_ON");
  128. material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
  129. material.renderQueue = 3000;
  130. break;
  131. case RenderingMode.Transparent:
  132. material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
  133. material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
  134. material.SetInt("_ZWrite", 0);
  135. material.DisableKeyword("_ALPHATEST_ON");
  136. material.DisableKeyword("_ALPHABLEND_ON");
  137. material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
  138. material.renderQueue = 3000;
  139. break;
  140. }
  141. }
  142. }