RiverModeler.Debug.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // River Modeler
  2. // Staggart Creations (http://staggart.xyz)
  3. // Copyright protected under Unity Asset Store EULA
  4. // Copying or referencing source code for the production of new asset store content is strictly prohibited.
  5. using System;
  6. using UnityEngine;
  7. namespace sc.modeling.river.runtime
  8. {
  9. public partial class RiverModeler
  10. {
  11. public enum DebugMode
  12. {
  13. None,
  14. Wireframe,
  15. Bounds,
  16. UV,
  17. Foam,
  18. Transparency,
  19. }
  20. public DebugMode debugMode = DebugMode.None;
  21. [NonSerialized]
  22. private Material debugMaterial;
  23. private static readonly int _VertexColorChannel = Shader.PropertyToID("_VertexColorChannel");
  24. partial void DrawDebugging()
  25. {
  26. if (meshFilter)
  27. {
  28. if (debugMode == DebugMode.Wireframe)
  29. {
  30. Gizmos.matrix = meshFilter.transform.localToWorldMatrix;
  31. Gizmos.color = new Color(0f,0f,0f,0.5f);
  32. Gizmos.DrawWireMesh(meshFilter.sharedMesh);
  33. }
  34. if (debugMode == DebugMode.Bounds)
  35. {
  36. Gizmos.color = Color.yellow;
  37. Gizmos.matrix = meshFilter.transform.localToWorldMatrix;
  38. Gizmos.DrawWireCube(meshFilter.sharedMesh.bounds.center, meshFilter.sharedMesh.bounds.size);
  39. }
  40. bool vertexColor = debugMode == DebugMode.Foam || debugMode == DebugMode.Transparency;
  41. if (debugMode == DebugMode.UV || vertexColor)
  42. {
  43. if (debugMaterial == null) debugMaterial = new Material(Shader.Find("Hidden/Visualize Vertex Attributes"));
  44. int vcChannel = 0;
  45. switch (debugMode)
  46. {
  47. case DebugMode.Foam: vcChannel = (int)settings.foam.vertexColorChannel;
  48. break;
  49. case DebugMode.Transparency: vcChannel = (int)settings.transparency.vertexColorChannel;
  50. break;
  51. }
  52. debugMaterial.SetFloat(_VertexColorChannel, vcChannel);
  53. void SetKeyword(string id, bool state)
  54. {
  55. if(state) debugMaterial.EnableKeyword(id);
  56. else debugMaterial.DisableKeyword(id);
  57. }
  58. SetKeyword("_SHOW_VERTEX_COLOR", vertexColor);
  59. SetKeyword("_SHOW_UV", debugMode == DebugMode.UV);
  60. debugMaterial.SetPass(0);
  61. Graphics.DrawMeshNow(meshFilter.sharedMesh, meshFilter.transform.localToWorldMatrix);
  62. }
  63. }
  64. }
  65. }
  66. }