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.

120 lines
2.9 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEditor;
  7. namespace AmplifyShaderEditor
  8. {
  9. // UI STRUCTURES
  10. [Serializable]
  11. public class TemplateOptionUIItem
  12. {
  13. public delegate void OnActionPerformed( TemplateOptionUIItem uiItem, params TemplateActionItem[] validActions );
  14. public event OnActionPerformed OnActionPerformedEvt;
  15. [SerializeField]
  16. private bool m_isVisible = true;
  17. [SerializeField]
  18. private int m_currentOption = 0;
  19. [SerializeField]
  20. private TemplateOptionsItem m_options;
  21. [SerializeField]
  22. private bool m_checkOnExecute = false;
  23. public TemplateOptionUIItem( TemplateOptionsItem options )
  24. {
  25. m_options = options;
  26. m_currentOption = m_options.DefaultOptionIndex;
  27. }
  28. public void Draw( UndoParentNode owner )
  29. {
  30. if( m_isVisible )
  31. {
  32. EditorGUI.BeginChangeCheck();
  33. switch( m_options.UIWidget )
  34. {
  35. case AseOptionsUIWidget.Dropdown:
  36. {
  37. m_currentOption = owner.EditorGUILayoutPopup( m_options.Name, m_currentOption, m_options.Options );
  38. }
  39. break;
  40. case AseOptionsUIWidget.Toggle:
  41. {
  42. m_currentOption = owner.EditorGUILayoutToggle( m_options.Name, m_currentOption == 1 ) ? 1 : 0;
  43. }
  44. break;
  45. }
  46. if( EditorGUI.EndChangeCheck() )
  47. {
  48. if( OnActionPerformedEvt != null )
  49. {
  50. OnActionPerformedEvt( this, m_options.ActionsPerOption[ m_currentOption ] );
  51. }
  52. }
  53. }
  54. }
  55. public void FillDataCollector( ref MasterNodeDataCollector dataCollector )
  56. {
  57. if( m_isVisible && m_checkOnExecute )
  58. {
  59. for( int i = 0; i < m_options.ActionsPerOption[ m_currentOption ].Length; i++ )
  60. {
  61. switch( m_options.ActionsPerOption[ m_currentOption ][i].ActionType )
  62. {
  63. case AseOptionsActionType.SetDefine:
  64. {
  65. dataCollector.AddToDefines( -1, m_options.ActionsPerOption[ m_currentOption ][ i ].ActionData );
  66. }
  67. break;
  68. case AseOptionsActionType.UnsetDefine:
  69. {
  70. dataCollector.AddToDefines( -1, m_options.ActionsPerOption[ m_currentOption ][ i ].ActionData, false );
  71. }
  72. break;
  73. }
  74. }
  75. }
  76. }
  77. public TemplateOptionsItem Options { get { return m_options; } }
  78. public void Destroy()
  79. {
  80. OnActionPerformedEvt = null;
  81. }
  82. public bool IsVisible
  83. {
  84. get { return m_isVisible; }
  85. set { m_isVisible = value; }
  86. }
  87. public bool CheckOnExecute
  88. {
  89. get { return m_checkOnExecute; }
  90. set { m_checkOnExecute = value; }
  91. }
  92. public int CurrentOption
  93. {
  94. get { return m_currentOption; }
  95. set
  96. {
  97. m_currentOption = Mathf.Clamp( value, 0, m_options.Options.Length -1 );
  98. if( OnActionPerformedEvt != null )
  99. {
  100. OnActionPerformedEvt( this, m_options.ActionsPerOption[ m_currentOption ] );
  101. }
  102. }
  103. }
  104. public bool EmptyEvent { get { return OnActionPerformedEvt == null;} }
  105. }
  106. }