Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SimpleLitShader.cs 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.Rendering.Universal.ShaderGUI
  4. {
  5. internal class SimpleLitShader : BaseShaderGUI
  6. {
  7. // Properties
  8. private SimpleLitGUI.SimpleLitProperties shadingModelProperties;
  9. // collect properties from the material properties
  10. public override void FindProperties(MaterialProperty[] properties)
  11. {
  12. base.FindProperties(properties);
  13. shadingModelProperties = new SimpleLitGUI.SimpleLitProperties(properties);
  14. }
  15. // material changed check
  16. public override void ValidateMaterial(Material material)
  17. {
  18. SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords);
  19. }
  20. // material main surface options
  21. public override void DrawSurfaceOptions(Material material)
  22. {
  23. if (material == null)
  24. throw new ArgumentNullException("material");
  25. // Use default labelWidth
  26. EditorGUIUtility.labelWidth = 0f;
  27. base.DrawSurfaceOptions(material);
  28. }
  29. // material main surface inputs
  30. public override void DrawSurfaceInputs(Material material)
  31. {
  32. base.DrawSurfaceInputs(material);
  33. SimpleLitGUI.Inputs(shadingModelProperties, materialEditor, material);
  34. DrawEmissionProperties(material, true);
  35. DrawTileOffset(materialEditor, baseMapProp);
  36. }
  37. public override void DrawAdvancedOptions(Material material)
  38. {
  39. SimpleLitGUI.Advanced(shadingModelProperties);
  40. base.DrawAdvancedOptions(material);
  41. }
  42. public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
  43. {
  44. if (material == null)
  45. throw new ArgumentNullException("material");
  46. // _Emission property is lost after assigning Standard shader to the material
  47. // thus transfer it before assigning the new shader
  48. if (material.HasProperty("_Emission"))
  49. {
  50. material.SetColor("_EmissionColor", material.GetColor("_Emission"));
  51. }
  52. base.AssignNewShaderToMaterial(material, oldShader, newShader);
  53. if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
  54. {
  55. SetupMaterialBlendMode(material);
  56. return;
  57. }
  58. SurfaceType surfaceType = SurfaceType.Opaque;
  59. BlendMode blendMode = BlendMode.Alpha;
  60. if (oldShader.name.Contains("/Transparent/Cutout/"))
  61. {
  62. surfaceType = SurfaceType.Opaque;
  63. material.SetFloat("_AlphaClip", 1);
  64. }
  65. else if (oldShader.name.Contains("/Transparent/"))
  66. {
  67. // NOTE: legacy shaders did not provide physically based transparency
  68. // therefore Fade mode
  69. surfaceType = SurfaceType.Transparent;
  70. blendMode = BlendMode.Alpha;
  71. }
  72. material.SetFloat("_Surface", (float)surfaceType);
  73. material.SetFloat("_Blend", (float)blendMode);
  74. }
  75. }
  76. }