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.

692 lines
21 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. using UnityEditor;
  7. namespace AmplifyShaderEditor
  8. {
  9. public enum eResizeAxis
  10. {
  11. X_AXIS,
  12. Y_AXIS,
  13. ALL
  14. }
  15. [Serializable]
  16. public sealed class CommentaryNode : ParentNode, ISerializationCallbackReceiver
  17. {
  18. private const string InfoText = "Press Alt + Left Mouse Click/Drag to make all Comment node area interactable.\nDouble click on the Comment at the node body to modify it directly from there.";
  19. private const string CommentaryTitle = "Comment";
  20. private const float BORDER_SIZE_X = 50;
  21. private const float BORDER_SIZE_Y = 50;
  22. private const float MIN_SIZE_X = 100;
  23. private const float MIN_SIZE_Y = 100;
  24. private const float COMMENTARY_BOX_HEIGHT = 30;
  25. private readonly Vector2 ResizeButtonPos = new Vector2( 1, 1 );
  26. [SerializeField]
  27. private string m_commentText = "Comment";
  28. [SerializeField]
  29. private string m_titleText = string.Empty;
  30. [SerializeField]
  31. private eResizeAxis m_resizeAxis = eResizeAxis.ALL;
  32. [SerializeField]
  33. private List<ParentNode> m_nodesOnCommentary = new List<ParentNode>();
  34. private Dictionary<int, ParentNode> m_nodesOnCommentaryDict = new Dictionary<int, ParentNode>();
  35. private bool m_reRegisterNodes = false;
  36. [SerializeField]
  37. private Rect m_resizeLeftIconCoords;
  38. [SerializeField]
  39. private Rect m_resizeRightIconCoords;
  40. [SerializeField]
  41. private Rect m_auxHeaderPos;
  42. [SerializeField]
  43. private Rect m_commentArea;
  44. private Texture2D m_resizeIconTex;
  45. private bool m_isResizingRight = false;
  46. private bool m_isResizingLeft = false;
  47. private Vector2 m_resizeStartPoint = Vector2.zero;
  48. private string m_focusName = "CommentaryNode";
  49. private bool m_focusOnTitle = false;
  50. private bool m_graphDepthAnalized = false;
  51. private bool m_checkCommentText = true;
  52. private bool m_checkTitleText = true;
  53. public Color m_frameColor = Color.white;
  54. private List<int> m_nodesIds = new List<int>();
  55. private bool m_checkContents = false;
  56. private bool m_isEditing;
  57. private bool m_stopEditing;
  58. private bool m_startEditing;
  59. private double m_clickTime;
  60. private double m_doubleClickTime = 0.3;
  61. protected override void CommonInit( int uniqueId )
  62. {
  63. base.CommonInit( uniqueId );
  64. m_reorderLocked = true;
  65. m_rmbIgnore = true;
  66. m_defaultInteractionMode = InteractionMode.Both;
  67. m_headerColor = UIUtils.GetColorFromCategory( "Commentary" );
  68. m_connStatus = NodeConnectionStatus.Island;
  69. m_textLabelWidth = 90;
  70. }
  71. protected override void OnUniqueIDAssigned()
  72. {
  73. base.OnUniqueIDAssigned();
  74. m_focusName = CommentaryTitle + OutputId;
  75. }
  76. public void CreateFromSelectedNodes( Vector2 mousePosOnCanvasCoords, ParentNode[] selectedNodes )
  77. {
  78. if ( selectedNodes.Length == 0 )
  79. {
  80. m_position = new Rect( mousePosOnCanvasCoords, new Vector2( 100, 100 ) );
  81. return;
  82. }
  83. Vector2 minPos = new Vector2( float.MaxValue, float.MaxValue );
  84. Vector2 maxPos = new Vector2( float.MinValue, float.MinValue );
  85. for ( int i = 0; i < selectedNodes.Length; i++ )
  86. {
  87. //Check min
  88. if ( selectedNodes[ i ].Position.x < minPos.x )
  89. minPos.x = selectedNodes[ i ].Position.x;
  90. if ( selectedNodes[ i ].Position.y < minPos.y )
  91. minPos.y = selectedNodes[ i ].Position.y;
  92. //check max
  93. float nodeXMax = selectedNodes[ i ].Position.x + selectedNodes[ i ].Position.width;
  94. if ( nodeXMax > maxPos.x )
  95. {
  96. maxPos.x = nodeXMax;
  97. }
  98. float nodeYMax = selectedNodes[ i ].Position.y + selectedNodes[ i ].Position.height;
  99. if ( nodeYMax > maxPos.y )
  100. {
  101. maxPos.y = nodeYMax;
  102. }
  103. //_nodesOnCommentary.Add( selectedNodes[ i ] );
  104. //selectedNodes[ i ].OnNodeStoppedMovingEvent += NodeStoppedMoving;
  105. AddNodeToCommentary( selectedNodes[ i ] );
  106. }
  107. Vector2 dims = maxPos - minPos + new Vector2( 2 * BORDER_SIZE_X, 2 * BORDER_SIZE_Y );
  108. m_position = new Rect( minPos.x - BORDER_SIZE_X, minPos.y - BORDER_SIZE_Y, dims.x, dims.y );
  109. }
  110. public override void Move( Vector2 delta, bool snap )
  111. {
  112. if ( m_isResizingRight || m_isResizingLeft )
  113. return;
  114. base.Move( delta, snap );
  115. for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
  116. {
  117. if ( !m_nodesOnCommentary[ i ].Selected )
  118. {
  119. m_nodesOnCommentary[ i ].RecordObject( Constants.UndoMoveNodesId );
  120. m_nodesOnCommentary[ i ].Move( delta, snap );
  121. }
  122. }
  123. }
  124. public void NodeStoppedMoving( ParentNode node, bool testOnlySelected, InteractionMode useTargetInteraction )
  125. {
  126. if ( !m_position.Contains( node.Vec2Position ) && !m_position.Contains( node.Corner ) )
  127. {
  128. RemoveNode( node );
  129. }
  130. }
  131. public void NodeDestroyed( ParentNode node )
  132. {
  133. RemoveNode( node );
  134. }
  135. public void RemoveNode( ParentNode node )
  136. {
  137. if ( m_nodesOnCommentaryDict.ContainsKey( node.UniqueId ) )
  138. {
  139. UIUtils.MarkUndoAction();
  140. RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
  141. node.RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
  142. m_nodesOnCommentary.Remove( node );
  143. m_nodesOnCommentaryDict.Remove( node.UniqueId );
  144. node.OnNodeStoppedMovingEvent -= NodeStoppedMoving;
  145. node.OnNodeDestroyedEvent -= NodeDestroyed;
  146. node.CommentaryParent = -1;
  147. }
  148. }
  149. public void RemoveAllNodes()
  150. {
  151. UIUtils.MarkUndoAction();
  152. for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
  153. {
  154. RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
  155. m_nodesOnCommentary[ i ].RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
  156. m_nodesOnCommentary[ i ].OnNodeStoppedMovingEvent -= NodeStoppedMoving;
  157. m_nodesOnCommentary[ i ].OnNodeDestroyedEvent -= NodeDestroyed;
  158. m_nodesOnCommentary[ i ].CommentaryParent = -1;
  159. }
  160. m_nodesOnCommentary.Clear();
  161. m_nodesOnCommentaryDict.Clear();
  162. }
  163. public override void Destroy()
  164. {
  165. base.Destroy();
  166. RemoveAllNodes();
  167. }
  168. public void AddNodeToCommentary( ParentNode node )
  169. {
  170. if( node.UniqueId == UniqueId )
  171. return;
  172. if ( !m_nodesOnCommentaryDict.ContainsKey( node.UniqueId ) )
  173. {
  174. bool addToNode = false;
  175. if ( node.CommentaryParent < 0 )
  176. {
  177. addToNode = true;
  178. if ( node.Depth <= m_depth )
  179. {
  180. ActivateNodeReordering( node.Depth );
  181. }
  182. }
  183. else
  184. {
  185. CommentaryNode other = UIUtils.GetNode( node.CommentaryParent ) as CommentaryNode;
  186. if ( other != null )
  187. {
  188. if ( other.Depth < Depth )
  189. {
  190. other.RemoveNode( node );
  191. addToNode = true;
  192. }
  193. }
  194. }
  195. if ( addToNode )
  196. {
  197. UIUtils.MarkUndoAction();
  198. RecordObject( Constants.UndoAddNodeToCommentaryId );
  199. node.RecordObject( Constants.UndoAddNodeToCommentaryId );
  200. m_nodesOnCommentary.Add( node );
  201. m_nodesOnCommentaryDict.Add( node.UniqueId, node );
  202. node.OnNodeStoppedMovingEvent += NodeStoppedMoving;
  203. node.OnNodeDestroyedEvent += NodeDestroyed;
  204. node.CommentaryParent = UniqueId;
  205. }
  206. }
  207. }
  208. public override void DrawProperties()
  209. {
  210. base.DrawProperties();
  211. NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr,()=>
  212. {
  213. EditorGUI.BeginChangeCheck();
  214. m_titleText = EditorGUILayoutTextField( "Frame Title", m_titleText );
  215. if ( EditorGUI.EndChangeCheck() )
  216. {
  217. m_checkTitleText = true;
  218. }
  219. EditorGUI.BeginChangeCheck();
  220. m_commentText = EditorGUILayoutTextField( CommentaryTitle, m_commentText );
  221. if ( EditorGUI.EndChangeCheck() )
  222. {
  223. m_checkCommentText = true;
  224. }
  225. m_frameColor = EditorGUILayoutColorField( "Frame Color", m_frameColor );
  226. } );
  227. EditorGUILayout.HelpBox( InfoText, MessageType.Info );
  228. }
  229. public override void OnNodeLayout( DrawInfo drawInfo )
  230. {
  231. if ( m_nodesIds.Count > 0 )
  232. {
  233. for ( int i = 0; i < m_nodesIds.Count; i++ )
  234. {
  235. ParentNode node = ContainerGraph.GetNode( m_nodesIds[ i ] );
  236. if ( node )
  237. {
  238. AddNodeToCommentary( node );
  239. }
  240. }
  241. m_nodesIds.Clear();
  242. }
  243. if ( m_reRegisterNodes )
  244. {
  245. m_reRegisterNodes = false;
  246. m_nodesOnCommentaryDict.Clear();
  247. for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
  248. {
  249. if ( m_nodesOnCommentary[ i ] != null )
  250. {
  251. m_nodesOnCommentary[ i ].OnNodeStoppedMovingEvent += NodeStoppedMoving;
  252. m_nodesOnCommentary[ i ].OnNodeDestroyedEvent += NodeDestroyed;
  253. m_nodesOnCommentaryDict.Add( m_nodesOnCommentary[ i ].UniqueId, m_nodesOnCommentary[ i ] );
  254. }
  255. }
  256. }
  257. //base.OnLayout( drawInfo );
  258. CalculatePositionAndVisibility( drawInfo );
  259. m_headerPosition = m_globalPosition;
  260. m_headerPosition.height = UIUtils.CurrentHeaderHeight;
  261. m_auxHeaderPos = m_position;
  262. m_auxHeaderPos.height = UIUtils.HeaderMaxHeight;
  263. m_commentArea = m_globalPosition;
  264. m_commentArea.height = COMMENTARY_BOX_HEIGHT * drawInfo.InvertedZoom;
  265. m_commentArea.xMin += 10 * drawInfo.InvertedZoom;
  266. m_commentArea.xMax -= 10 * drawInfo.InvertedZoom;
  267. if ( m_resizeIconTex == null )
  268. {
  269. m_resizeIconTex = UIUtils.GetCustomStyle( CustomStyle.CommentaryResizeButton ).normal.background;
  270. }
  271. // LEFT RESIZE BUTTON
  272. m_resizeLeftIconCoords = m_globalPosition;
  273. m_resizeLeftIconCoords.x = m_globalPosition.x + 2;
  274. m_resizeLeftIconCoords.y = m_globalPosition.y + m_globalPosition.height - 2 - ( m_resizeIconTex.height + ResizeButtonPos.y ) * drawInfo.InvertedZoom;
  275. m_resizeLeftIconCoords.width = m_resizeIconTex.width * drawInfo.InvertedZoom;
  276. m_resizeLeftIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;
  277. // RIGHT RESIZE BUTTON
  278. m_resizeRightIconCoords = m_globalPosition;
  279. m_resizeRightIconCoords.x = m_globalPosition.x + m_globalPosition.width - 1 - ( m_resizeIconTex.width + ResizeButtonPos.x ) * drawInfo.InvertedZoom;
  280. m_resizeRightIconCoords.y = m_globalPosition.y + m_globalPosition.height - 2 - ( m_resizeIconTex.height + ResizeButtonPos.y ) * drawInfo.InvertedZoom;
  281. m_resizeRightIconCoords.width = m_resizeIconTex.width * drawInfo.InvertedZoom;
  282. m_resizeRightIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;
  283. }
  284. public override void OnNodeRepaint( DrawInfo drawInfo )
  285. {
  286. if ( !m_isVisible )
  287. return;
  288. m_colorBuffer = GUI.color;
  289. // Background
  290. GUI.color = Constants.NodeBodyColor * m_frameColor;
  291. GUI.Label( m_globalPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.CommentaryBackground ) );
  292. // Header
  293. GUI.color = m_headerColor * m_headerColorModifier * m_frameColor;
  294. GUI.Label( m_headerPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.NodeHeader ) );
  295. GUI.color = m_colorBuffer;
  296. // Fixed Title ( only renders when not editing )
  297. if ( !m_isEditing && !m_startEditing && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
  298. {
  299. GUI.Label( m_commentArea, m_commentText, UIUtils.CommentaryTitle );
  300. }
  301. // Buttons
  302. GUI.Label( m_resizeLeftIconCoords, string.Empty, UIUtils.GetCustomStyle( CustomStyle.CommentaryResizeButtonInv ) );
  303. GUI.Label( m_resizeRightIconCoords, string.Empty, UIUtils.GetCustomStyle( CustomStyle.CommentaryResizeButton ) );
  304. // Selection Box
  305. if ( m_selected )
  306. {
  307. GUI.color = Constants.NodeSelectedColor;
  308. RectOffset cache = UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ).border;
  309. UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ).border = UIUtils.RectOffsetSix;
  310. GUI.Label( m_globalPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ) );
  311. UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ).border = cache;
  312. GUI.color = m_colorBuffer;
  313. }
  314. if ( !string.IsNullOrEmpty( m_titleText ) )
  315. {
  316. Rect titleRect = m_globalPosition;
  317. titleRect.y -= 24;
  318. titleRect.height = 24;
  319. GUI.Label( titleRect, m_titleText, UIUtils.GetCustomStyle( CustomStyle.CommentarySuperTitle ) );
  320. }
  321. }
  322. public override void Draw( DrawInfo drawInfo )
  323. {
  324. base.Draw( drawInfo );
  325. // Custom Editable Title
  326. if ( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
  327. {
  328. if ( !m_isEditing && ( ( !ContainerGraph.ParentWindow.MouseInteracted && drawInfo.CurrentEventType == EventType.MouseDown && m_commentArea.Contains( drawInfo.MousePosition ) ) ) )
  329. {
  330. if ( ( EditorApplication.timeSinceStartup - m_clickTime ) < m_doubleClickTime )
  331. m_startEditing = true;
  332. else
  333. GUI.FocusControl( null );
  334. m_clickTime = EditorApplication.timeSinceStartup;
  335. }
  336. else if ( m_isEditing && ( ( drawInfo.CurrentEventType == EventType.MouseDown && !m_commentArea.Contains( drawInfo.MousePosition ) ) || !EditorGUIUtility.editingTextField ) )
  337. {
  338. m_stopEditing = true;
  339. }
  340. if ( m_isEditing || m_startEditing )
  341. {
  342. EditorGUI.BeginChangeCheck();
  343. GUI.SetNextControlName( m_focusName );
  344. m_commentText = EditorGUITextField( m_commentArea, string.Empty, m_commentText, UIUtils.CommentaryTitle );
  345. if ( EditorGUI.EndChangeCheck() )
  346. {
  347. m_checkCommentText = true;
  348. }
  349. if ( m_startEditing )
  350. EditorGUI.FocusTextInControl( m_focusName );
  351. }
  352. if ( drawInfo.CurrentEventType == EventType.Repaint )
  353. {
  354. if ( m_startEditing )
  355. {
  356. m_startEditing = false;
  357. m_isEditing = true;
  358. }
  359. if ( m_stopEditing )
  360. {
  361. m_stopEditing = false;
  362. m_isEditing = false;
  363. GUI.FocusControl( null );
  364. }
  365. }
  366. }
  367. if ( drawInfo.CurrentEventType == EventType.MouseDown && drawInfo.LeftMouseButtonPressed )
  368. {
  369. // Left Button
  370. if( m_resizeLeftIconCoords.Contains( drawInfo.MousePosition ) && ContainerGraph.ParentWindow.CurrentEvent.modifiers != EventModifiers.Shift )
  371. {
  372. if ( !m_isResizingLeft )
  373. {
  374. m_isResizingLeft = true;
  375. ContainerGraph.ParentWindow.ForceAutoPanDir = true;
  376. m_resizeStartPoint = drawInfo.TransformedMousePos;
  377. }
  378. }
  379. // Right Button
  380. if ( m_resizeRightIconCoords.Contains( drawInfo.MousePosition ) && ContainerGraph.ParentWindow.CurrentEvent.modifiers != EventModifiers.Shift )
  381. {
  382. if ( !m_isResizingRight )
  383. {
  384. m_isResizingRight = true;
  385. ContainerGraph.ParentWindow.ForceAutoPanDir = true;
  386. m_resizeStartPoint = drawInfo.TransformedMousePos;
  387. }
  388. }
  389. }
  390. if ( drawInfo.CurrentEventType == EventType.Repaint || drawInfo.CurrentEventType == EventType.MouseUp )
  391. {
  392. // Left Button
  393. EditorGUIUtility.AddCursorRect( m_resizeLeftIconCoords, MouseCursor.ResizeUpRight );
  394. if ( m_isResizingLeft )
  395. {
  396. if ( drawInfo.CurrentEventType == EventType.MouseUp )
  397. {
  398. m_isResizingLeft = false;
  399. ContainerGraph.ParentWindow.ForceAutoPanDir = false;
  400. RemoveAllNodes();
  401. FireStoppedMovingEvent( false, InteractionMode.Target );
  402. }
  403. else
  404. {
  405. Vector2 currSize = ( drawInfo.TransformedMousePos - m_resizeStartPoint ) /*/ drawInfo.InvertedZoom*/;
  406. m_resizeStartPoint = drawInfo.TransformedMousePos;
  407. if ( m_resizeAxis != eResizeAxis.Y_AXIS )
  408. {
  409. m_position.x += currSize.x;
  410. m_position.width -= currSize.x;
  411. if ( m_position.width < MIN_SIZE_X )
  412. {
  413. m_position.x -= ( MIN_SIZE_X - m_position.width );
  414. m_position.width = MIN_SIZE_X;
  415. }
  416. }
  417. if ( m_resizeAxis != eResizeAxis.X_AXIS )
  418. {
  419. m_position.height += currSize.y;
  420. if ( m_position.height < MIN_SIZE_Y )
  421. {
  422. m_position.height = MIN_SIZE_Y;
  423. }
  424. }
  425. }
  426. }
  427. // Right Button
  428. EditorGUIUtility.AddCursorRect( m_resizeRightIconCoords, MouseCursor.ResizeUpLeft );
  429. if ( m_isResizingRight )
  430. {
  431. if ( drawInfo.CurrentEventType == EventType.MouseUp )
  432. {
  433. m_isResizingRight = false;
  434. ContainerGraph.ParentWindow.ForceAutoPanDir = false;
  435. RemoveAllNodes();
  436. FireStoppedMovingEvent( false, InteractionMode.Target );
  437. }
  438. else
  439. {
  440. Vector2 currSize = ( drawInfo.TransformedMousePos - m_resizeStartPoint ) /*/ drawInfo.InvertedZoom*/;
  441. m_resizeStartPoint = drawInfo.TransformedMousePos;
  442. if ( m_resizeAxis != eResizeAxis.Y_AXIS )
  443. {
  444. m_position.width += currSize.x;
  445. if ( m_position.width < MIN_SIZE_X )
  446. {
  447. m_position.width = MIN_SIZE_X;
  448. }
  449. }
  450. if ( m_resizeAxis != eResizeAxis.X_AXIS )
  451. {
  452. m_position.height += currSize.y;
  453. if ( m_position.height < MIN_SIZE_Y )
  454. {
  455. m_position.height = MIN_SIZE_Y;
  456. }
  457. }
  458. }
  459. }
  460. }
  461. if ( m_checkCommentText )
  462. {
  463. m_checkCommentText = false;
  464. m_commentText = m_commentText.Replace( IOUtils.FIELD_SEPARATOR, ' ' );
  465. }
  466. if ( m_checkTitleText )
  467. {
  468. m_checkTitleText = false;
  469. m_titleText = m_titleText.Replace( IOUtils.FIELD_SEPARATOR, ' ' );
  470. }
  471. if ( m_focusOnTitle && drawInfo.CurrentEventType == EventType.KeyUp )
  472. {
  473. m_focusOnTitle = false;
  474. m_startEditing = true;
  475. }
  476. }
  477. public void Focus()
  478. {
  479. m_focusOnTitle = true;
  480. }
  481. public override void OnAfterDeserialize()
  482. {
  483. base.OnAfterDeserialize();
  484. m_reRegisterNodes = true;
  485. }
  486. public override bool OnNodeInteraction( ParentNode node )
  487. {
  488. if ( node == null || UniqueId == node.UniqueId )
  489. return false;
  490. for( int i = 0; i < m_nodesOnCommentary.Count; i++ )
  491. {
  492. if( m_nodesOnCommentary[ i ] && m_nodesOnCommentary[ i ] != this && m_nodesOnCommentary[ i ].OnNodeInteraction( node ) )
  493. {
  494. return false;
  495. }
  496. }
  497. if( m_position.Contains( node.Vec2Position ) && m_position.Contains( node.Corner ) )
  498. {
  499. AddNodeToCommentary( node );
  500. return true;
  501. }
  502. return false;
  503. }
  504. public override void OnSelfStoppedMovingEvent()
  505. {
  506. FireStoppedMovingEvent( false, InteractionMode.Both );
  507. }
  508. public override void ReadFromString( ref string[] nodeParams )
  509. {
  510. base.ReadFromString( ref nodeParams );
  511. m_position.width = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
  512. m_position.height = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
  513. m_commentText = GetCurrentParam( ref nodeParams );
  514. int count = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  515. for ( int i = 0; i < count; i++ )
  516. {
  517. m_nodesIds.Add( Convert.ToInt32( GetCurrentParam( ref nodeParams ) ) );
  518. }
  519. if ( UIUtils.CurrentShaderVersion() > 5004 )
  520. m_titleText = GetCurrentParam( ref nodeParams );
  521. if ( UIUtils.CurrentShaderVersion() > 12002 )
  522. {
  523. string[] colorChannels = GetCurrentParam( ref nodeParams ).Split( IOUtils.VECTOR_SEPARATOR );
  524. if ( colorChannels.Length == 4 )
  525. {
  526. m_frameColor.r = Convert.ToSingle( colorChannels[ 0 ] );
  527. m_frameColor.g = Convert.ToSingle( colorChannels[ 1 ] );
  528. m_frameColor.b = Convert.ToSingle( colorChannels[ 2 ] );
  529. m_frameColor.a = Convert.ToSingle( colorChannels[ 3 ] );
  530. }
  531. else
  532. {
  533. UIUtils.ShowMessage( "Incorrect number of color values", MessageSeverity.Error );
  534. }
  535. }
  536. }
  537. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  538. {
  539. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  540. IOUtils.AddFieldValueToString( ref nodeInfo, m_position.width );
  541. IOUtils.AddFieldValueToString( ref nodeInfo, m_position.height );
  542. IOUtils.AddFieldValueToString( ref nodeInfo, m_commentText );
  543. IOUtils.AddFieldValueToString( ref nodeInfo, m_nodesOnCommentary.Count );
  544. for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
  545. {
  546. IOUtils.AddFieldValueToString( ref nodeInfo, m_nodesOnCommentary[ i ].UniqueId );
  547. }
  548. IOUtils.AddFieldValueToString( ref nodeInfo, m_titleText );
  549. IOUtils.AddFieldValueToString( ref nodeInfo, m_frameColor.r.ToString() + IOUtils.VECTOR_SEPARATOR + m_frameColor.g.ToString() + IOUtils.VECTOR_SEPARATOR + m_frameColor.b.ToString() + IOUtils.VECTOR_SEPARATOR + m_frameColor.a.ToString() );
  550. }
  551. public override void ResetNodeData()
  552. {
  553. base.ResetNodeData();
  554. m_graphDepthAnalized = false;
  555. }
  556. public override void ReadAdditionalClipboardData( ref string[] nodeParams )
  557. {
  558. base.ReadAdditionalClipboardData( ref nodeParams );
  559. m_nodesIds.Clear();
  560. m_checkContents = true;
  561. }
  562. public override void RefreshExternalReferences()
  563. {
  564. base.RefreshExternalReferences();
  565. if( m_checkContents )
  566. {
  567. m_checkContents = false;
  568. OnSelfStoppedMovingEvent();
  569. }
  570. }
  571. public override void CalculateCustomGraphDepth()
  572. {
  573. if ( m_graphDepthAnalized )
  574. return;
  575. m_graphDepth = int.MinValue;
  576. int count = m_nodesOnCommentary.Count;
  577. for ( int i = 0; i < count; i++ )
  578. {
  579. if ( m_nodesOnCommentary[ i ].ConnStatus == NodeConnectionStatus.Island )
  580. {
  581. m_nodesOnCommentary[ i ].CalculateCustomGraphDepth();
  582. }
  583. if ( m_nodesOnCommentary[ i ].GraphDepth >= m_graphDepth )
  584. {
  585. m_graphDepth = m_nodesOnCommentary[ i ].GraphDepth + 1;
  586. }
  587. }
  588. m_graphDepthAnalized = true;
  589. }
  590. public override Rect Position { get { return Event.current.alt ? m_position : m_auxHeaderPos; } }
  591. public override bool Contains( Vector3 pos )
  592. {
  593. return Event.current.alt ? m_globalPosition.Contains( pos ) : ( m_headerPosition.Contains( pos ) || m_resizeRightIconCoords.Contains( pos ) || m_resizeLeftIconCoords.Contains( pos ) );
  594. }
  595. }
  596. }