1111
1212namespace UnityEditorInternal
1313{
14- internal class AnimationWindowCurve : IComparable < AnimationWindowCurve >
14+ internal class AnimationWindowCurve : IComparable < AnimationWindowCurve > , IEquatable < AnimationWindowCurve >
1515 {
1616 public const float timeEpsilon = 0.00001f ;
1717
@@ -101,47 +101,13 @@ public int GetBindingHashCode()
101101
102102 public int CompareTo ( AnimationWindowCurve obj )
103103 {
104- bool pathEquals = path . Equals ( obj . path ) ;
105- bool typeEquals = obj . type == type ;
106-
107- if ( ! pathEquals && depth != obj . depth )
104+ if ( ! path . Equals ( obj . path ) )
108105 {
109- int minLength = Math . Min ( path . Length , obj . path . Length ) ;
110- int commonLength = 0 ;
111- int index = 0 ;
112- for ( ; index < minLength ; ++ index )
113- {
114- if ( path [ index ] != obj . path [ index ] )
115- break ;
116-
117- if ( path [ index ] == '/' )
118- commonLength = index + 1 ;
119- }
120-
121- if ( index == minLength )
122- commonLength = minLength ;
123-
124- string subPath1 = path . Substring ( commonLength ) ;
125- string subPath2 = obj . path . Substring ( commonLength ) ;
126-
127- if ( String . IsNullOrEmpty ( subPath1 ) )
128- return - 1 ;
129- else if ( String . IsNullOrEmpty ( subPath2 ) )
130- return 1 ;
131-
132- Regex r = new Regex ( @"^[^\/]*\/" ) ;
133-
134- Match match1 = r . Match ( subPath1 ) ;
135- string next1 = match1 . Success ? match1 . Value . Substring ( 0 , match1 . Value . Length - 1 ) : subPath1 ;
136-
137- Match match2 = r . Match ( subPath2 ) ;
138- string next2 = match2 . Success ? match2 . Value . Substring ( 0 , match2 . Value . Length - 1 ) : subPath2 ;
139-
140- return next1 . CompareTo ( next2 ) ;
106+ return ComparePaths ( obj . path ) ;
141107 }
142108
143- bool sameTransformComponent = type == typeof ( Transform ) && obj . type == typeof ( Transform ) && pathEquals ;
144- bool oneIsTransformComponent = ( type == typeof ( Transform ) || obj . type == typeof ( Transform ) ) && pathEquals ;
109+ bool sameTransformComponent = type == typeof ( Transform ) && obj . type == typeof ( Transform ) ;
110+ bool oneIsTransformComponent = ( type == typeof ( Transform ) || obj . type == typeof ( Transform ) ) ;
145111
146112 // We want to sort position before rotation
147113 if ( sameTransformComponent )
@@ -164,15 +130,45 @@ public int CompareTo(AnimationWindowCurve obj)
164130 }
165131
166132 // Sort (.r, .g, .b, .a) and (.x, .y, .z, .w)
167- if ( pathEquals && typeEquals )
133+ if ( obj . type == type )
168134 {
169135 int lhsIndex = AnimationWindowUtility . GetComponentIndex ( obj . propertyName ) ;
170136 int rhsIndex = AnimationWindowUtility . GetComponentIndex ( propertyName ) ;
171137 if ( lhsIndex != - 1 && rhsIndex != - 1 && propertyName . Substring ( 0 , propertyName . Length - 2 ) == obj . propertyName . Substring ( 0 , obj . propertyName . Length - 2 ) )
172138 return rhsIndex - lhsIndex ;
173139 }
174140
175- return ( path + type + propertyName ) . CompareTo ( obj . path + obj . type + obj . propertyName ) ;
141+ return string . Compare ( ( path + type + propertyName ) , obj . path + obj . type + obj . propertyName , StringComparison . Ordinal ) ;
142+ }
143+
144+ public bool Equals ( AnimationWindowCurve other )
145+ {
146+ return CompareTo ( other ) == 0 ;
147+ }
148+
149+ int ComparePaths ( string otherPath )
150+ {
151+ var thisPath = path . Split ( '/' ) ;
152+ var objPath = otherPath . Split ( '/' ) ;
153+
154+ int smallerLength = Math . Min ( thisPath . Length , objPath . Length ) ;
155+ for ( int i = 0 ; i < smallerLength ; ++ i )
156+ {
157+ int compare = string . Compare ( thisPath [ i ] , objPath [ i ] , StringComparison . Ordinal ) ;
158+ if ( compare == 0 )
159+ {
160+ continue ;
161+ }
162+
163+ return compare ;
164+ }
165+
166+ if ( thisPath . Length < objPath . Length )
167+ {
168+ return - 1 ;
169+ }
170+
171+ return 1 ;
176172 }
177173
178174 public AnimationCurve ToAnimationCurve ( )
0 commit comments