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.

116 lines
3.2 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. namespace AmplifyShaderEditor
  7. {
  8. [Serializable]
  9. public sealed class TemplateCullModeModule : TemplateModuleParent
  10. {
  11. private const string CullModeFormatStr = "Cull ";
  12. public TemplateCullModeModule() : base("Cull Mode"){ }
  13. private static readonly string CullModeStr = "Cull Mode";
  14. [SerializeField]
  15. private CullMode m_cullMode = CullMode.Back;
  16. [SerializeField]
  17. private InlineProperty m_inlineCullMode = new InlineProperty();
  18. public void CopyFrom( TemplateCullModeModule other , bool allData )
  19. {
  20. if( allData )
  21. m_independentModule = other.IndependentModule;
  22. m_cullMode = other.CurrentCullMode;
  23. m_inlineCullMode.CopyFrom( other.CullInlineProperty );
  24. }
  25. public void ConfigureFromTemplateData( TemplateCullModeData data )
  26. {
  27. bool newValidData = ( data.DataCheck == TemplateDataCheck.Valid );
  28. if( newValidData && m_validData != newValidData )
  29. {
  30. m_independentModule = data.IndependentModule;
  31. if( string.IsNullOrEmpty( data.InlineData ) )
  32. {
  33. m_cullMode = data.CullModeData;
  34. m_inlineCullMode.IntValue = (int)m_cullMode;
  35. m_inlineCullMode.ResetProperty();
  36. }
  37. else
  38. {
  39. m_inlineCullMode.SetInlineByName( data.InlineData );
  40. }
  41. }
  42. m_validData = newValidData;
  43. }
  44. public override void Draw( UndoParentNode owner, bool style = true )
  45. {
  46. EditorGUI.BeginChangeCheck();
  47. //m_cullMode = (CullMode)owner.EditorGUILayoutEnumPopup( CullModeStr, m_cullMode );
  48. m_inlineCullMode.CustomDrawer( ref owner, ( x ) => { m_cullMode = (CullMode)owner.EditorGUILayoutEnumPopup( CullModeStr, m_cullMode ); }, CullModeStr );
  49. if( EditorGUI.EndChangeCheck() )
  50. {
  51. m_inlineCullMode.IntValue = (int)m_cullMode;
  52. m_isDirty = true;
  53. }
  54. }
  55. public override void ReadFromString( ref uint index, ref string[] nodeParams )
  56. {
  57. bool validDataOnMeta = m_validData;
  58. if( UIUtils.CurrentShaderVersion() > TemplatesManager.MPShaderVersion )
  59. {
  60. validDataOnMeta = Convert.ToBoolean( nodeParams[ index++ ] );
  61. }
  62. if( validDataOnMeta )
  63. {
  64. if( UIUtils.CurrentShaderVersion() < 15304 )
  65. {
  66. m_cullMode = (CullMode)Enum.Parse( typeof( CullMode ), nodeParams[ index++ ] );
  67. m_inlineCullMode.IntValue = (int)m_cullMode;
  68. }
  69. else
  70. {
  71. m_inlineCullMode.ReadFromString( ref index, ref nodeParams );
  72. m_cullMode = (CullMode)m_inlineCullMode.IntValue;
  73. }
  74. }
  75. }
  76. public override void WriteToString( ref string nodeInfo )
  77. {
  78. IOUtils.AddFieldValueToString( ref nodeInfo, m_validData );
  79. if( m_validData )
  80. {
  81. //IOUtils.AddFieldValueToString( ref nodeInfo, m_cullMode );
  82. m_inlineCullMode.WriteToString( ref nodeInfo );
  83. }
  84. }
  85. public override string GenerateShaderData( bool isSubShader )
  86. {
  87. //return CullModeFormatStr + m_cullMode.ToString();
  88. return CullModeFormatStr + m_inlineCullMode.GetValueOrProperty( m_cullMode.ToString());
  89. }
  90. public override void Destroy()
  91. {
  92. base.Destroy();
  93. m_inlineCullMode = null;
  94. }
  95. public CullMode CurrentCullMode { get { return m_cullMode; } }
  96. public InlineProperty CullInlineProperty { get { return m_inlineCullMode; } }
  97. }
  98. }