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.

170 lines
3.9 KiB

  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace AmplifyShaderEditor
  6. {
  7. [Serializable]
  8. public class ReordenatorNode : PropertyNode
  9. {
  10. [SerializeField]
  11. private List<PropertyNode> m_propertyList;
  12. [SerializeField]
  13. private string m_headerTitle = string.Empty;
  14. [SerializeField]
  15. private bool m_isInside;
  16. public ReordenatorNode() : base()
  17. {
  18. }
  19. public void Init( string entryName, string entryInspectorName, List<PropertyNode> list, bool register = true )
  20. {
  21. m_propertyName = entryName;
  22. m_propertyInspectorName = entryInspectorName;
  23. m_propertyList = list;
  24. if( register )
  25. UIUtils.RegisterPropertyNode( this );
  26. }
  27. public override void Destroy()
  28. {
  29. base.Destroy();
  30. m_propertyList.Clear();
  31. m_propertyList = null;
  32. UIUtils.UnregisterPropertyNode( this );
  33. }
  34. //public List<ParentNode> PropertyList
  35. //{
  36. // get { return m_propertyList; }
  37. //}
  38. public int PropertyListCount
  39. {
  40. get { if ( m_propertyList != null ) return m_propertyList.Count; else return -1; }
  41. }
  42. public string HeaderTitle { get { return m_headerTitle; } set { m_headerTitle = value; } }
  43. public bool HasTitle { get { return !string.IsNullOrEmpty( m_headerTitle ); } }
  44. public bool IsInside { get { return m_isInside; } set { m_isInside = value; } }
  45. public int RecursiveSetOrderOffset( int offset, bool lockit, int order = -1 )
  46. {
  47. //Debug.Log( Locked + " " + PropertyName );
  48. if ( Locked )
  49. return offset;
  50. if( order > -1 )
  51. OrderIndex = order;
  52. int currentOffset = offset;
  53. if( m_propertyList != null )
  54. m_propertyList.Sort( ( x, y ) => { return ( x as PropertyNode ).OrderIndex.CompareTo( ( y as PropertyNode ).OrderIndex ); } );
  55. OrderIndexOffset = currentOffset - RawOrderIndex;
  56. currentOffset++;
  57. if ( m_propertyList != null )
  58. for ( int i = 0; i < m_propertyList.Count; i++ )
  59. {
  60. ReordenatorNode rnode = m_propertyList[ i ] as ReordenatorNode;
  61. if ( rnode != null )
  62. {
  63. currentOffset = rnode.RecursiveSetOrderOffset( currentOffset, false );
  64. }
  65. else
  66. {
  67. PropertyNode pnode = m_propertyList[ i ] as PropertyNode;
  68. {
  69. pnode.OrderIndexOffset = currentOffset - pnode.RawOrderIndex;// + ( HasTitle ? 1 : 0 );
  70. }
  71. currentOffset++;
  72. }
  73. }
  74. if ( lockit )
  75. Locked = true;
  76. return currentOffset;
  77. }
  78. public int RecursiveCount()
  79. {
  80. int amount = 0;
  81. if ( HasTitle )
  82. amount += 1;
  83. for ( int i = 0; i < m_propertyList.Count; i++ )
  84. {
  85. if ( ( m_propertyList[ i ] is ReordenatorNode ) )
  86. amount += ( m_propertyList[ i ] as ReordenatorNode ).RecursiveCount();
  87. else
  88. amount +=1;
  89. }
  90. return amount;
  91. }
  92. public void RecursiveLog()
  93. {
  94. Debug.LogWarning( OrderIndex+" HEADER "+ PropertyName );
  95. for( int i = 0; i < m_propertyList.Count; i++ )
  96. {
  97. if( ( m_propertyList[ i ] is ReordenatorNode ) )
  98. ( m_propertyList[ i ] as ReordenatorNode ).RecursiveLog();
  99. else
  100. Debug.Log( ( m_propertyList[ i ] as PropertyNode ).OrderIndex+" "+( m_propertyList[ i ] as PropertyNode).PropertyName );
  101. }
  102. }
  103. public bool Locked = false;
  104. public void RecursiveClear()
  105. {
  106. Locked = false;
  107. if( m_propertyList != null)
  108. for ( int i = 0; i < m_propertyList.Count; i++ )
  109. {
  110. ReordenatorNode renode = ( m_propertyList[ i ] as ReordenatorNode );
  111. if ( renode != null )
  112. {
  113. renode.RecursiveClear();
  114. }
  115. }
  116. }
  117. public bool RecursiveConnectedProperties()
  118. {
  119. bool connected = false;
  120. if ( m_propertyList != null )
  121. {
  122. for ( int i = 0; i < m_propertyList.Count; i++ )
  123. {
  124. ReordenatorNode renode = ( m_propertyList[ i ] as ReordenatorNode );
  125. if ( renode != null )
  126. {
  127. bool temp = renode.RecursiveConnectedProperties();
  128. if( temp )
  129. connected = true;
  130. } else
  131. {
  132. if ( ( m_propertyList[ i ] as PropertyNode ).IsConnected )
  133. connected = true;
  134. }
  135. }
  136. }
  137. return connected;
  138. }
  139. }
  140. }