BaseShaderData.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace Funly.SkyStudio
  6. {
  7. [Serializable]
  8. public abstract class BaseShaderDefinition : IProfileDefinition
  9. {
  10. public string shaderName { get; protected set; }
  11. // Definition of shader parameters.
  12. private ProfileGroupSection[] m_ProfileDefinitions;
  13. public ProfileGroupSection[] groups
  14. {
  15. get { return m_ProfileDefinitions ?? (m_ProfileDefinitions = ProfileDefinitionTable()); }
  16. }
  17. // Shader features.
  18. [SerializeField]
  19. private ProfileFeatureSection[] m_ProfileFeatures;
  20. //private Dictionary<string, ProfileFeatureSection>
  21. public ProfileFeatureSection[] features
  22. {
  23. get { return m_ProfileFeatures ?? (m_ProfileFeatures = ProfileFeatureSection()); }
  24. }
  25. private Dictionary<string, ProfileFeatureDefinition> m_KeyToFeature;
  26. public ProfileFeatureDefinition GetFeatureDefinition(string featureKey)
  27. {
  28. // Build a table mapping on first access.
  29. if (m_KeyToFeature == null) {
  30. m_KeyToFeature = new Dictionary<string, ProfileFeatureDefinition>();
  31. foreach (ProfileFeatureSection section in features) {
  32. foreach (ProfileFeatureDefinition feature in section.featureDefinitions) {
  33. if (feature.featureType == ProfileFeatureDefinition.FeatureType.BooleanValue ||
  34. feature.featureType == ProfileFeatureDefinition.FeatureType.ShaderKeyword) {
  35. m_KeyToFeature[feature.featureKey] = feature;
  36. } else if (feature.featureType == ProfileFeatureDefinition.FeatureType.ShaderKeywordDropdown) {
  37. // For dropdowns we map all the feature types back to the parent definition.
  38. foreach (string dropdownFeatureKey in feature.featureKeys) {
  39. m_KeyToFeature[dropdownFeatureKey] = feature;
  40. }
  41. }
  42. }
  43. }
  44. }
  45. if (featureKey == null) {
  46. return null;
  47. }
  48. if (m_KeyToFeature.ContainsKey(featureKey) == false) {
  49. return null;
  50. }
  51. return m_KeyToFeature[featureKey];
  52. }
  53. // Override and return shader keyword info.
  54. protected abstract ProfileFeatureSection[] ProfileFeatureSection();
  55. // Override and return shader property info.
  56. protected abstract ProfileGroupSection[] ProfileDefinitionTable();
  57. }
  58. }