ParticlesUnlitShader.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.Rendering.Universal.ShaderGUI
  5. {
  6. internal class ParticlesUnlitShader : BaseShaderGUI
  7. {
  8. // Properties
  9. private BakedLitGUI.BakedLitProperties shadingModelProperties;
  10. private ParticleGUI.ParticleProperties particleProps;
  11. // List of renderers using this material in the scene, used for validating vertex streams
  12. List<ParticleSystemRenderer> m_RenderersUsingThisMaterial = new List<ParticleSystemRenderer>();
  13. public override void FindProperties(MaterialProperty[] properties)
  14. {
  15. base.FindProperties(properties);
  16. shadingModelProperties = new BakedLitGUI.BakedLitProperties(properties);
  17. particleProps = new ParticleGUI.ParticleProperties(properties);
  18. }
  19. public override void MaterialChanged(Material material)
  20. {
  21. if (material == null)
  22. throw new ArgumentNullException("material");
  23. SetMaterialKeywords(material, null, ParticleGUI.SetMaterialKeywords);
  24. }
  25. public override void DrawSurfaceOptions(Material material)
  26. {
  27. // Detect any changes to the material
  28. EditorGUI.BeginChangeCheck();
  29. {
  30. base.DrawSurfaceOptions(material);
  31. DoPopup(ParticleGUI.Styles.colorMode, particleProps.colorMode, Enum.GetNames(typeof(ParticleGUI.ColorMode)));
  32. }
  33. if (EditorGUI.EndChangeCheck())
  34. {
  35. foreach (var obj in blendModeProp.targets)
  36. MaterialChanged((Material)obj);
  37. }
  38. }
  39. public override void DrawSurfaceInputs(Material material)
  40. {
  41. base.DrawSurfaceInputs(material);
  42. BakedLitGUI.Inputs(shadingModelProperties, materialEditor);
  43. DrawEmissionProperties(material, true);
  44. }
  45. public override void DrawAdvancedOptions(Material material)
  46. {
  47. EditorGUI.BeginChangeCheck();
  48. {
  49. materialEditor.ShaderProperty(particleProps.flipbookMode, ParticleGUI.Styles.flipbookMode);
  50. ParticleGUI.FadingOptions(material, materialEditor, particleProps);
  51. ParticleGUI.DoVertexStreamsArea(material, m_RenderersUsingThisMaterial);
  52. }
  53. base.DrawAdvancedOptions(material);
  54. }
  55. public override void OnOpenGUI(Material material, MaterialEditor materialEditor)
  56. {
  57. CacheRenderersUsingThisMaterial(material);
  58. base.OnOpenGUI(material, materialEditor);
  59. }
  60. void CacheRenderersUsingThisMaterial(Material material)
  61. {
  62. m_RenderersUsingThisMaterial.Clear();
  63. ParticleSystemRenderer[] renderers = UnityEngine.Object.FindObjectsOfType(typeof(ParticleSystemRenderer)) as ParticleSystemRenderer[];
  64. foreach (ParticleSystemRenderer renderer in renderers)
  65. {
  66. if (renderer.sharedMaterial == material)
  67. m_RenderersUsingThisMaterial.Add(renderer);
  68. }
  69. }
  70. }
  71. } // namespace UnityEditor