ParticlesSimpleLitShader.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.Rendering.Universal.ShaderGUI
  5. {
  6. internal class ParticlesSimpleLitShader : BaseShaderGUI
  7. {
  8. // Properties
  9. private SimpleLitGUI.SimpleLitProperties 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 SimpleLitGUI.SimpleLitProperties(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, SimpleLitGUI.SetMaterialKeywords, 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. SimpleLitGUI.Inputs(shadingModelProperties, materialEditor, material);
  43. DrawEmissionProperties(material, true);
  44. }
  45. public override void DrawAdvancedOptions(Material material)
  46. {
  47. SimpleLitGUI.Advanced(shadingModelProperties);
  48. EditorGUI.BeginChangeCheck();
  49. {
  50. materialEditor.ShaderProperty(particleProps.flipbookMode, ParticleGUI.Styles.flipbookMode);
  51. ParticleGUI.FadingOptions(material, materialEditor, particleProps);
  52. ParticleGUI.DoVertexStreamsArea(material, m_RenderersUsingThisMaterial, true);
  53. }
  54. base.DrawAdvancedOptions(material);
  55. }
  56. public override void OnOpenGUI(Material material, MaterialEditor materialEditor)
  57. {
  58. CacheRenderersUsingThisMaterial(material);
  59. base.OnOpenGUI(material, materialEditor);
  60. }
  61. void CacheRenderersUsingThisMaterial(Material material)
  62. {
  63. m_RenderersUsingThisMaterial.Clear();
  64. ParticleSystemRenderer[] renderers = UnityEngine.Object.FindObjectsOfType(typeof(ParticleSystemRenderer)) as ParticleSystemRenderer[];
  65. foreach (ParticleSystemRenderer renderer in renderers)
  66. {
  67. if (renderer.sharedMaterial == material)
  68. m_RenderersUsingThisMaterial.Add(renderer);
  69. }
  70. }
  71. }
  72. } // namespace UnityEditor