@@ -77,36 +77,19 @@ private void CreateEnumList()
7777 SetEnumDisplayNames ( enumNamesAndValues ) ;
7878 }
7979
80+ // Sorts the values so that they get displayed consistently, and assigns them for being drawn.
8081 private void SetEnumDisplayNames ( Dictionary < string , int > enumNamesAndValues )
8182 {
8283 m_EnumValues = new int [ enumNamesAndValues . Count ] ;
84+ enumNamesAndValues . Values . CopyTo ( m_EnumValues , 0 ) ;
8385
8486 m_EnumDisplayNames = new string [ enumNamesAndValues . Count ] ;
85- int currentIndex = 0 ;
87+ enumNamesAndValues . Keys . CopyTo ( m_EnumDisplayNames , 0 ) ;
8688
87- int tempInt ;
88- string tempString ;
89-
90- foreach ( KeyValuePair < string , int > kvp in enumNamesAndValues )
91- {
92- int tempIndex = currentIndex ;
93- m_EnumDisplayNames [ currentIndex ] = kvp . Key ;
94- m_EnumValues [ currentIndex ] = kvp . Value ;
95- while ( tempIndex != 0 && m_EnumValues [ currentIndex ] < m_EnumValues [ tempIndex - 1 ] )
96- {
97- tempInt = m_EnumValues [ tempIndex - 1 ] ;
98- m_EnumValues [ tempIndex - 1 ] = m_EnumValues [ currentIndex ] ;
99- m_EnumValues [ currentIndex ] = tempInt ;
100-
101- tempString = m_EnumDisplayNames [ tempIndex - 1 ] ;
102- m_EnumDisplayNames [ tempIndex - 1 ] = m_EnumDisplayNames [ currentIndex ] ;
103- m_EnumDisplayNames [ currentIndex ] = tempString ;
104- tempIndex -- ;
105- }
106- currentIndex ++ ;
107- }
89+ Array . Sort ( m_EnumValues , m_EnumDisplayNames ) ;
10890 }
109-
91+
92+ // Ensures mapping between displayed value and actual value is consistent. Issues arise when there are gaps in the enum values (ie 0, 1, 13).
11093 private int GetEnumIndex ( int enumValue )
11194 {
11295 for ( int i = 0 ; i < m_EnumValues . Length ; i ++ )
0 commit comments