No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Renderer2DDataAuthoring.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using UnityEditor;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. public partial class Renderer2DData
  5. {
  6. #if UNITY_EDITOR
  7. [SerializeField]
  8. Renderer2DDefaultMaterialType m_DefaultMaterialType = Renderer2DDefaultMaterialType.Lit;
  9. internal override Shader GetDefaultShader()
  10. {
  11. if (!GraphicsSettings.TryGetRenderPipelineSettings<Renderer2DResources>(out var resources))
  12. return null;
  13. return resources.defaultLitMaterial.shader;
  14. }
  15. internal override Material GetDefaultMaterial(DefaultMaterialType materialType)
  16. {
  17. if (!GraphicsSettings.TryGetRenderPipelineSettings<Renderer2DResources>(out var resources))
  18. return null;
  19. switch (materialType)
  20. {
  21. case DefaultMaterialType.Sprite:
  22. case DefaultMaterialType.Particle:
  23. {
  24. return m_DefaultMaterialType switch
  25. {
  26. Renderer2DDefaultMaterialType.Lit => resources.defaultLitMaterial,
  27. Renderer2DDefaultMaterialType.Unlit => resources.defaultUnlitMaterial,
  28. _ => resources.defaultCustomMaterial
  29. };
  30. }
  31. case DefaultMaterialType.SpriteMask:
  32. return resources.defaultMaskMaterial;
  33. default:
  34. return null;
  35. }
  36. }
  37. private void InitializeSpriteEditorPrefs()
  38. {
  39. // Provide a list of suggested texture property names to Sprite Editor via EditorPrefs.
  40. const string suggestedNamesKey = "SecondarySpriteTexturePropertyNames";
  41. const string maskTex = "_MaskTex";
  42. const string normalMap = "_NormalMap";
  43. string suggestedNamesPrefs = EditorPrefs.GetString(suggestedNamesKey);
  44. if (string.IsNullOrEmpty(suggestedNamesPrefs))
  45. EditorPrefs.SetString(suggestedNamesKey, maskTex + "," + normalMap);
  46. else
  47. {
  48. if (!suggestedNamesPrefs.Contains(maskTex))
  49. suggestedNamesPrefs += ("," + maskTex);
  50. if (!suggestedNamesPrefs.Contains(normalMap))
  51. suggestedNamesPrefs += ("," + normalMap);
  52. EditorPrefs.SetString(suggestedNamesKey, suggestedNamesPrefs);
  53. }
  54. ReloadAllNullProperties();
  55. }
  56. private void ReloadAllNullProperties()
  57. {
  58. ResourceReloader.TryReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath);
  59. }
  60. void RebuildBlendStyles(bool force = false)
  61. {
  62. // Initialize Light Blend Styles
  63. if (m_LightBlendStyles != null && !force)
  64. {
  65. for (int i = 0; i < m_LightBlendStyles.Length; ++i)
  66. {
  67. ref var blendStyle = ref m_LightBlendStyles[i];
  68. // Custom blend mode (99) now falls back to Multiply.
  69. if ((int) blendStyle.blendMode == 99)
  70. blendStyle.blendMode = Light2DBlendStyle.BlendMode.Multiply;
  71. }
  72. return;
  73. }
  74. m_LightBlendStyles = new Light2DBlendStyle[4];
  75. m_LightBlendStyles[0].name = "Multiply";
  76. m_LightBlendStyles[0].blendMode = Light2DBlendStyle.BlendMode.Multiply;
  77. m_LightBlendStyles[1].name = "Additive";
  78. m_LightBlendStyles[1].blendMode = Light2DBlendStyle.BlendMode.Additive;
  79. m_LightBlendStyles[2].name = "Multiply with Mask";
  80. m_LightBlendStyles[2].blendMode = Light2DBlendStyle.BlendMode.Multiply;
  81. m_LightBlendStyles[2].maskTextureChannel = Light2DBlendStyle.TextureChannel.R;
  82. m_LightBlendStyles[3].name = "Additive with Mask";
  83. m_LightBlendStyles[3].blendMode = Light2DBlendStyle.BlendMode.Additive;
  84. m_LightBlendStyles[3].maskTextureChannel = Light2DBlendStyle.TextureChannel.R;
  85. // Initialize Editor Prefs for Sprite Editor
  86. InitializeSpriteEditorPrefs();
  87. }
  88. private void Awake()
  89. {
  90. RebuildBlendStyles();
  91. }
  92. void Reset()
  93. {
  94. RebuildBlendStyles(true);
  95. }
  96. #endif
  97. }
  98. }