Assignment for RMIT Mixed Reality in 2020
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.

661 lines
20 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. public enum ShaderPropertyScope
  10. {
  11. Shader,
  12. SubShader,
  13. Pass
  14. }
  15. [Serializable]
  16. [NodeAttributes( "Template Parameter", "Constants And Properties", "Select and use one of the pre-existing properties given by the template" )]
  17. public sealed class TemplateShaderPropertyNode : TemplateNodeParent
  18. {
  19. private const string CurrentScopeStr = "Scope";
  20. private const string WarningStr = "Preview doesn't work with global variables";
  21. private const string PropertyLabelStr = "Parameter";
  22. private const string TypeLabelStr = "Type: ";
  23. private const string PropertyNameStr = "Property Name: ";
  24. private int IntPropertyId;
  25. private int FloatPropertyId;
  26. private int VectorPropertyId;
  27. private int Sampler2DPropertyId;
  28. private int Sampler3DPropertyId;
  29. private int SamplerCubePropertyId;
  30. [SerializeField]
  31. private int m_currentPropertyIdx = -1;
  32. [SerializeField]
  33. private string m_propertyName = string.Empty;
  34. [SerializeField]
  35. private int m_propertyNameId = 0;
  36. [SerializeField]
  37. private string m_typeName = string.Empty;
  38. [SerializeField]
  39. private string m_propertyNameLabel = string.Empty;
  40. private bool m_fetchPropertyId = false;
  41. private bool m_fetchScopeFromProperty = false;
  42. private List<TemplateShaderPropertyData> m_shaderProperties = null;
  43. private string[] m_propertyLabels = null;
  44. private UpperLeftWidgetHelper m_upperLeftWidgetHelper = new UpperLeftWidgetHelper();
  45. //Multi-Pass only properties
  46. [SerializeField]
  47. private ShaderPropertyScope m_currentScope = ShaderPropertyScope.Shader;
  48. protected override void CommonInit( int uniqueId )
  49. {
  50. base.CommonInit( uniqueId );
  51. m_previewShaderGUID = "4feb2016be0ece148b8bf234508f6aa4";
  52. }
  53. void FetchScope()
  54. {
  55. int shaderScopeCount = m_templateMPData.AvailableShaderProperties.Count;
  56. for( int i = 0; i < shaderScopeCount; i++ )
  57. {
  58. if( m_templateMPData.AvailableShaderProperties[ i ].PropertyName.Equals( m_propertyName ) )
  59. {
  60. m_currentScope = ShaderPropertyScope.Shader;
  61. }
  62. }
  63. int subShaderScopeCount = m_templateMPData.SubShaders[ SubShaderIdx ].AvailableShaderGlobals.Count;
  64. for( int i = 0; i < subShaderScopeCount; i++ )
  65. {
  66. if( m_templateMPData.SubShaders[ SubShaderIdx ].AvailableShaderGlobals[ i ].PropertyName.Equals( m_propertyName ) )
  67. {
  68. m_currentScope = ShaderPropertyScope.SubShader;
  69. }
  70. }
  71. int passScopeCount = m_templateMPData.SubShaders[ SubShaderIdx ].Passes[ PassIdx ].AvailableShaderGlobals.Count;
  72. for( int i = 0; i < passScopeCount; i++ )
  73. {
  74. if( m_templateMPData.SubShaders[ SubShaderIdx ].Passes[ PassIdx ].AvailableShaderGlobals[ i ].PropertyName.Equals( m_propertyName ) )
  75. {
  76. m_currentScope = ShaderPropertyScope.Pass;
  77. }
  78. }
  79. }
  80. void FetchShaderProperties()
  81. {
  82. if( m_templateMPData == null )
  83. m_templateMPData = ( m_containerGraph.CurrentMasterNode as TemplateMultiPassMasterNode ).CurrentTemplate;
  84. if( m_templateMPData != null )
  85. {
  86. switch( m_currentScope )
  87. {
  88. case ShaderPropertyScope.Shader:
  89. m_shaderProperties = m_templateMPData.AvailableShaderProperties;
  90. break;
  91. case ShaderPropertyScope.SubShader:
  92. m_shaderProperties = m_templateMPData.SubShaders[ SubShaderIdx ].AvailableShaderGlobals;
  93. break;
  94. case ShaderPropertyScope.Pass:
  95. m_shaderProperties = m_templateMPData.SubShaders[ SubShaderIdx ].Passes[ PassIdx ].AvailableShaderGlobals;
  96. break;
  97. }
  98. }
  99. }
  100. public override void OnEnable()
  101. {
  102. base.OnEnable();
  103. IntPropertyId = Shader.PropertyToID( "_IntData" );
  104. FloatPropertyId = Shader.PropertyToID( "_FloatData" );
  105. VectorPropertyId = Shader.PropertyToID( "_VectorData" );
  106. Sampler2DPropertyId = Shader.PropertyToID( "_Sampler2DData" );
  107. Sampler3DPropertyId = Shader.PropertyToID( "_Sampler3DData" );
  108. SamplerCubePropertyId = Shader.PropertyToID( "_SamplerCubeData" );
  109. }
  110. public override void DrawProperties()
  111. {
  112. base.DrawProperties();
  113. if( m_multiPassMode )
  114. {
  115. DrawMultipassProperties();
  116. }
  117. if( m_currentPropertyIdx > -1 )
  118. {
  119. bool hasProperties = ( m_shaderProperties != null && m_shaderProperties.Count > 0 );
  120. if( hasProperties )
  121. {
  122. EditorGUI.BeginChangeCheck();
  123. m_currentPropertyIdx = EditorGUILayoutPopup( PropertyLabelStr, m_currentPropertyIdx, m_propertyLabels );
  124. if( EditorGUI.EndChangeCheck() )
  125. {
  126. UpdateFromId();
  127. }
  128. EditorGUILayout.LabelField( m_typeName );
  129. if( m_shaderProperties[ m_currentPropertyIdx ].PropertyType != PropertyType.Global )
  130. {
  131. EditorGUILayout.LabelField( m_propertyNameLabel );
  132. }
  133. }
  134. }
  135. }
  136. void DrawMultipassProperties()
  137. {
  138. EditorGUI.BeginChangeCheck();
  139. m_currentScope = (ShaderPropertyScope)EditorGUILayoutEnumPopup( CurrentScopeStr, m_currentScope );
  140. if( EditorGUI.EndChangeCheck() )
  141. {
  142. FetchShaderProperties();
  143. FetchPropertyId();
  144. }
  145. bool showSubShader = false;
  146. bool showPass = false;
  147. switch( m_currentScope )
  148. {
  149. case ShaderPropertyScope.SubShader:
  150. {
  151. showSubShader = true;
  152. }
  153. break;
  154. case ShaderPropertyScope.Pass:
  155. {
  156. showSubShader = true;
  157. showPass = true;
  158. }
  159. break;
  160. }
  161. if( showSubShader )
  162. {
  163. DrawSubShaderUI();
  164. }
  165. if( showPass )
  166. {
  167. DrawPassUI();
  168. }
  169. }
  170. protected override void OnSubShaderChange()
  171. {
  172. FetchShaderProperties();
  173. FetchPropertyId();
  174. }
  175. protected override void OnPassChange()
  176. {
  177. FetchShaderProperties();
  178. FetchPropertyId();
  179. }
  180. override protected void CheckWarningState()
  181. {
  182. if( m_containerGraph.CurrentCanvasMode != NodeAvailability.TemplateShader )
  183. {
  184. ShowTab( NodeMessageType.Error, ErrorMessageStr );
  185. }
  186. else
  187. {
  188. if( m_shaderProperties != null &&
  189. m_shaderProperties.Count > 0 &&
  190. m_shaderProperties.Count > m_currentPropertyIdx &&
  191. m_shaderProperties[ m_currentPropertyIdx ].PropertyType == PropertyType.Global &&
  192. m_showPreview )
  193. {
  194. ShowTab( NodeMessageType.Info, WarningStr );
  195. }
  196. else
  197. {
  198. m_showErrorMessage = false;
  199. }
  200. }
  201. }
  202. public override void SetPreviewInputs()
  203. {
  204. if( m_containerGraph.CurrentCanvasMode != NodeAvailability.TemplateShader )
  205. return;
  206. if( m_shaderProperties == null || m_currentPropertyIdx >= m_shaderProperties.Count )
  207. return;
  208. if( m_shaderProperties[ m_currentPropertyIdx ].PropertyType == PropertyType.Global )
  209. {
  210. m_additionalContent.text = string.Empty;
  211. PreviewMaterial.SetInt( IntPropertyId, 0 );
  212. return;
  213. }
  214. Material currMat = m_containerGraph.CurrentMaterial;
  215. if( currMat != null && currMat.HasProperty( m_propertyNameId ) )
  216. {
  217. switch( m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType )
  218. {
  219. case WirePortDataType.INT:
  220. {
  221. int value = currMat.GetInt( m_propertyNameId );
  222. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, GenerateTitle( value ) ) );
  223. PreviewMaterial.SetInt( IntPropertyId, value );
  224. }
  225. break;
  226. case WirePortDataType.FLOAT:
  227. {
  228. float value = currMat.GetFloat( m_propertyNameId );
  229. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, GenerateTitle( value ) ) );
  230. PreviewMaterial.SetFloat( FloatPropertyId, value );
  231. }
  232. break;
  233. case WirePortDataType.FLOAT4:
  234. {
  235. Vector4 value = currMat.GetVector( m_propertyNameId );
  236. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, GenerateTitle( value.x, value.y, value.z, value.w ) ) );
  237. PreviewMaterial.SetVector( VectorPropertyId, value );
  238. }
  239. break;
  240. case WirePortDataType.COLOR:
  241. {
  242. Color value = currMat.GetColor( m_propertyNameId );
  243. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, GenerateTitle( value.r, value.g, value.b, value.a ) ) );
  244. PreviewMaterial.SetColor( VectorPropertyId, value );
  245. }
  246. break;
  247. case WirePortDataType.SAMPLER2D:
  248. {
  249. Texture value = currMat.GetTexture( m_propertyNameId );
  250. if( value )
  251. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, value.name ) );
  252. else
  253. SetAdditonalTitleText( string.Empty );
  254. PreviewMaterial.SetTexture( Sampler2DPropertyId, value );
  255. }
  256. break;
  257. case WirePortDataType.SAMPLER3D:
  258. {
  259. Texture value = currMat.GetTexture( m_propertyNameId );
  260. if( value )
  261. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, value.name ) );
  262. else
  263. SetAdditonalTitleText( string.Empty );
  264. PreviewMaterial.SetTexture( Sampler3DPropertyId, value );
  265. }
  266. break;
  267. case WirePortDataType.SAMPLERCUBE:
  268. {
  269. Texture value = currMat.GetTexture( m_propertyNameId );
  270. if( value )
  271. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, value.name ) );
  272. else
  273. SetAdditonalTitleText( string.Empty );
  274. PreviewMaterial.SetTexture( SamplerCubePropertyId, value );
  275. }
  276. break;
  277. case WirePortDataType.SAMPLER2DARRAY:
  278. {
  279. Texture value = currMat.GetTexture( m_propertyNameId );
  280. if( value )
  281. SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, value.name ) );
  282. else
  283. SetAdditonalTitleText( string.Empty );
  284. PreviewMaterial.SetTexture( SamplerCubePropertyId, value );
  285. }
  286. break;
  287. }
  288. }
  289. else
  290. {
  291. SetAdditonalTitleText( string.Empty );
  292. }
  293. }
  294. public override void Draw( DrawInfo drawInfo )
  295. {
  296. if( m_containerGraph.CurrentCanvasMode != NodeAvailability.TemplateShader )
  297. {
  298. if( !m_showErrorMessage || m_errorMessageTypeIsError == NodeMessageType.Info )
  299. {
  300. ShowTab( NodeMessageType.Error, ErrorMessageStr );
  301. }
  302. }
  303. else if( m_showErrorMessage )
  304. {
  305. if( m_errorMessageTypeIsError == NodeMessageType.Error )
  306. HideTab();
  307. }
  308. base.Draw( drawInfo );
  309. if( m_containerGraph.CurrentCanvasMode != NodeAvailability.TemplateShader )
  310. return;
  311. if( m_shaderProperties == null )
  312. {
  313. MasterNode masterNode = m_containerGraph.CurrentMasterNode;
  314. if( masterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template )
  315. {
  316. if( SetTemplate( masterNode ) )
  317. {
  318. m_fetchPropertyId = true;
  319. }
  320. }
  321. }
  322. if( m_fetchScopeFromProperty )
  323. {
  324. m_fetchScopeFromProperty = false;
  325. FetchScope();
  326. FetchShaderProperties();
  327. }
  328. if( m_fetchPropertyId )
  329. {
  330. m_fetchPropertyId = false;
  331. FetchPropertyId();
  332. }
  333. if( m_currentPropertyIdx > -1 )
  334. {
  335. EditorGUI.BeginChangeCheck();
  336. m_currentPropertyIdx = m_upperLeftWidgetHelper.DrawWidget( this, m_currentPropertyIdx, m_propertyLabels );
  337. if( EditorGUI.EndChangeCheck() )
  338. {
  339. UpdateFromId();
  340. }
  341. }
  342. }
  343. void FetchPropertyId()
  344. {
  345. if( m_shaderProperties != null )
  346. {
  347. m_currentPropertyIdx = 0;
  348. m_propertyLabels = new string[ m_shaderProperties.Count ];
  349. for( int i = 0; i < m_shaderProperties.Count; i++ )
  350. {
  351. if( m_shaderProperties[ i ].PropertyName.Equals( m_propertyName ) )
  352. {
  353. m_currentPropertyIdx = i;
  354. }
  355. m_propertyLabels[ i ] = m_shaderProperties[ i ].PropertyInspectorName;
  356. }
  357. UpdateFromId();
  358. }
  359. else
  360. {
  361. m_currentPropertyIdx = -1;
  362. }
  363. }
  364. void UpdateFromId()
  365. {
  366. if( m_shaderProperties != null )
  367. {
  368. if( m_shaderProperties.Count == 0 )
  369. {
  370. for( int i = 0; i < 4; i++ )
  371. m_containerGraph.DeleteConnection( false, UniqueId, i, false, true );
  372. m_headerColor = UIUtils.GetColorFromCategory( "Default" );
  373. m_content.text = "None";
  374. m_additionalContent.text = string.Empty;
  375. m_previewMaterialPassId = 1;
  376. PreviewMaterial.SetFloat( FloatPropertyId, 0 );
  377. m_showPreview = false;
  378. m_drawPreviewExpander = false;
  379. m_outputPorts[ 0 ].ChangeProperties( "None", WirePortDataType.FLOAT, false );
  380. ConfigurePorts();
  381. return;
  382. }
  383. m_drawPreviewExpander = true;
  384. bool areCompatible = TemplateHelperFunctions.CheckIfCompatibles( m_outputPorts[ 0 ].DataType, m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType );
  385. switch( m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType )
  386. {
  387. case WirePortDataType.SAMPLER1D:
  388. case WirePortDataType.SAMPLER2D:
  389. case WirePortDataType.SAMPLER3D:
  390. case WirePortDataType.SAMPLERCUBE:
  391. case WirePortDataType.SAMPLER2DARRAY:
  392. m_outputPorts[ 0 ].ChangeProperties( "Tex", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false );
  393. m_headerColor = UIUtils.GetColorFromCategory( "Textures" );
  394. break;
  395. case WirePortDataType.INT:
  396. case WirePortDataType.FLOAT:
  397. m_outputPorts[ 0 ].ChangeProperties( Constants.EmptyPortValue, m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false );
  398. m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" );
  399. break;
  400. case WirePortDataType.FLOAT4:
  401. m_outputPorts[ 0 ].ChangeProperties( "XYZW", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false );
  402. m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" );
  403. break;
  404. case WirePortDataType.COLOR:
  405. m_outputPorts[ 0 ].ChangeProperties( "RGBA", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false );
  406. m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" );
  407. break;
  408. default:
  409. case WirePortDataType.OBJECT:
  410. case WirePortDataType.FLOAT3x3:
  411. case WirePortDataType.FLOAT4x4:
  412. m_outputPorts[ 0 ].ChangeProperties( "Out", m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType, false );
  413. m_headerColor = UIUtils.GetColorFromCategory( "Constants And Properties" );
  414. break;
  415. }
  416. if( !areCompatible )
  417. {
  418. for( int i = 0; i < 4; i++ )
  419. m_containerGraph.DeleteConnection( false, UniqueId, i, false, true );
  420. }
  421. ConfigurePorts();
  422. m_propertyName = m_shaderProperties[ m_currentPropertyIdx ].PropertyName;
  423. m_content.text = m_shaderProperties[ m_currentPropertyIdx ].PropertyInspectorName;
  424. m_propertyNameId = Shader.PropertyToID( m_propertyName );
  425. m_typeName = TypeLabelStr + m_shaderProperties[ m_currentPropertyIdx ].PropertyType.ToString();
  426. if( m_shaderProperties[ m_currentPropertyIdx ].PropertyType != PropertyType.Global )
  427. {
  428. m_propertyNameLabel = PropertyNameStr + m_shaderProperties[ m_currentPropertyIdx ].PropertyName;
  429. }
  430. m_sizeIsDirty = true;
  431. Material currMat = m_containerGraph.CurrentMaterial;
  432. if( currMat != null )
  433. {
  434. if( m_shaderProperties[ m_currentPropertyIdx ].PropertyType == PropertyType.Global )
  435. {
  436. m_previewMaterialPassId = 0;
  437. if( !m_showErrorMessage && m_showPreview )
  438. {
  439. ShowTab( NodeMessageType.Info, WarningStr );
  440. }
  441. }
  442. else
  443. {
  444. if( m_showErrorMessage && m_errorMessageTypeIsError != NodeMessageType.Error )
  445. {
  446. HideTab();
  447. }
  448. switch( m_shaderProperties[ m_currentPropertyIdx ].PropertyDataType )
  449. {
  450. case WirePortDataType.INT: m_previewMaterialPassId = 0; break;
  451. case WirePortDataType.FLOAT: m_previewMaterialPassId = 1; break;
  452. case WirePortDataType.FLOAT4:
  453. case WirePortDataType.COLOR: m_previewMaterialPassId = 2; break;
  454. case WirePortDataType.SAMPLER2D: m_previewMaterialPassId = 3; break;
  455. case WirePortDataType.SAMPLER3D: m_previewMaterialPassId = 4; break;
  456. case WirePortDataType.SAMPLERCUBE: m_previewMaterialPassId = 5; break;
  457. default: PreviewMaterial.SetPass( 0 ); break;
  458. }
  459. }
  460. }
  461. CheckWarningState();
  462. }
  463. }
  464. string GenerateTitle( params float[] values )
  465. {
  466. //string finalResult = "( ";
  467. string finalResult = string.Empty;
  468. if( values.Length == 1 )
  469. {
  470. finalResult += values[ 0 ].ToString( Mathf.Abs( values[ 0 ] ) > 1000 ? Constants.PropertyBigFloatFormatLabel : Constants.PropertyFloatFormatLabel );
  471. }
  472. else
  473. {
  474. for( int i = 0; i < values.Length; i++ )
  475. {
  476. finalResult += values[ i ].ToString( Mathf.Abs( values[ i ] ) > 1000 ? Constants.PropertyBigVectorFormatLabel : Constants.PropertyVectorFormatLabel );
  477. if( i < ( values.Length - 1 ) )
  478. finalResult += ",";
  479. }
  480. }
  481. //finalResult += " )";
  482. return finalResult;
  483. }
  484. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  485. {
  486. if( dataCollector.MasterNodeCategory != AvailableShaderTypes.Template )
  487. {
  488. UIUtils.ShowMessage( UniqueId, "Template Parameter node is only intended for templates use only" );
  489. return m_outputPorts[ outputId ].ErrorValue;
  490. }
  491. if( m_shaderProperties == null || m_shaderProperties.Count ==0 )
  492. {
  493. UIUtils.ShowMessage( UniqueId, "Attempting to fetch inexistant parameter on " + m_nodeAttribs.Name +" node");
  494. return m_outputPorts[ outputId ].ErrorValue;
  495. }
  496. if( m_multiPassMode )
  497. {
  498. switch( m_currentScope )
  499. {
  500. case ShaderPropertyScope.SubShader:
  501. {
  502. if( dataCollector.TemplateDataCollectorInstance.MultipassSubshaderIdx != SubShaderIdx )
  503. {
  504. UIUtils.ShowMessage( UniqueId, string.Format( "{0} is only intended for subshader {1}", m_propertyLabels[ m_currentPropertyIdx ], SubShaderIdx ) );
  505. return m_outputPorts[ outputId ].ErrorValue;
  506. }
  507. }
  508. break;
  509. case ShaderPropertyScope.Pass:
  510. {
  511. if( dataCollector.TemplateDataCollectorInstance.MultipassSubshaderIdx != SubShaderIdx ||
  512. dataCollector.TemplateDataCollectorInstance.MultipassPassIdx != PassIdx
  513. )
  514. {
  515. UIUtils.ShowMessage( UniqueId, string.Format( "{0} is only intended for subshader {1} and pass {2}", m_propertyLabels[ m_currentPropertyIdx ], SubShaderIdx, PassIdx ) );
  516. return m_outputPorts[ outputId ].ErrorValue;
  517. }
  518. }
  519. break;
  520. }
  521. }
  522. return GetOutputVectorItem( 0, outputId, m_propertyName );
  523. }
  524. public override void ReadFromString( ref string[] nodeParams )
  525. {
  526. base.ReadFromString( ref nodeParams );
  527. m_propertyName = GetCurrentParam( ref nodeParams );
  528. m_propertyNameId = Shader.PropertyToID( m_propertyName );
  529. if( UIUtils.CurrentShaderVersion() > TemplatesManager.MPShaderVersion )
  530. {
  531. m_currentScope = (ShaderPropertyScope)Enum.Parse( typeof( ShaderPropertyScope ), GetCurrentParam( ref nodeParams ) );
  532. }
  533. else
  534. {
  535. m_fetchScopeFromProperty = true;
  536. }
  537. m_fetchPropertyId = true;
  538. }
  539. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  540. {
  541. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  542. IOUtils.AddFieldValueToString( ref nodeInfo, m_propertyName );
  543. IOUtils.AddFieldValueToString( ref nodeInfo, m_currentScope );
  544. }
  545. public override void OnMasterNodeReplaced( MasterNode newMasterNode )
  546. {
  547. base.OnMasterNodeReplaced( newMasterNode );
  548. if( newMasterNode.CurrentMasterNodeCategory == AvailableShaderTypes.Template )
  549. {
  550. SetTemplate( newMasterNode );
  551. if( m_fetchScopeFromProperty )
  552. {
  553. m_fetchScopeFromProperty = false;
  554. FetchScope();
  555. }
  556. FetchShaderProperties();
  557. FetchPropertyId();
  558. //m_containerGraph.DeleteConnection( false, UniqueId, 0, false, true );
  559. }
  560. }
  561. bool SetTemplate( MasterNode newMasterNode )
  562. {
  563. if( m_containerGraph.MultiPassMasterNodes.NodesList.Count > 0 )
  564. {
  565. m_multiPassMode = true;
  566. TemplateMultiPassMasterNode templateMasterNode = ( newMasterNode as TemplateMultiPassMasterNode );
  567. if( templateMasterNode != null )
  568. {
  569. m_templateMPData = templateMasterNode.CurrentTemplate;
  570. UpdateSubShaderAmount();
  571. FetchShaderProperties();
  572. return true;
  573. }
  574. }
  575. else
  576. {
  577. m_multiPassMode = false;
  578. TemplateMasterNode templateMasterNode = ( newMasterNode as TemplateMasterNode );
  579. if( templateMasterNode != null )
  580. {
  581. m_shaderProperties = templateMasterNode.CurrentTemplate.AvailableShaderProperties;
  582. return true;
  583. }
  584. }
  585. return false;
  586. }
  587. public override void RefreshExternalReferences()
  588. {
  589. base.RefreshExternalReferences();
  590. CheckWarningState();
  591. }
  592. public override void Destroy()
  593. {
  594. base.Destroy();
  595. m_propertyLabels = null;
  596. m_shaderProperties = null;
  597. m_upperLeftWidgetHelper = null;
  598. }
  599. }
  600. }