AnimCurvePathNode FindOrCreateChildPath( string relativePath, AnimCurvePathNode parent ) { // First see if the path object already exists foreach( AnimCurvePathNode child in parent.children ) { if ( child.relativePath.CompareTo(relativePath) == 0 ) return child; } // Create the path since it didn't exist var newPath = new AnimCurvePathNode(); newPath.relativePath = relativePath; parent.children.Add( newPath ); return newPath; }
/** * Draw the tree (populated from the animation curves) rooted at the passed-in 'root' variable */ void DrawPathTree( AnimCurvePathNode root ) { ++EditorGUI.indentLevel; // Do we allow folding out to display the curves? GUI.enabled = (root.animClipCurves.Count > 0); root.foldOut = EditorGUILayout.Foldout( GUI.enabled && root.foldOut, root.relativePath ); GUI.enabled = true; // If we folded out to display all the curves... if ( root.foldOut ) { // Display all the curves contained in this node foreach( AnimationClipCurveData curve in root.animClipCurves ) { GUIContent pathContent = EditorGUIUtility.ObjectContent( null, curve.type ); pathContent.tooltip = pathContent.text; pathContent.text = ""; // Begin a row Rect area = EditorGUILayout.BeginHorizontal( GUILayout.ExpandWidth(true) ); // Stop indenting, since we're drawing horizontally int oldIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; // Draw the little icon infront of the row float indentPixels = 10.0f * oldIndentLevel; GUILayout.Space( indentPixels + pathContent.image.width ); GUI.DrawTexture( new Rect(area.x + indentPixels, area.y, pathContent.image.width, pathContent.image.height), pathContent.image ); // Draw path, property name, then the curve preview curve.path = EditorGUILayout.TextField( curve.path ); curve.propertyName = EditorGUILayout.TextField( curve.propertyName, GUILayout.MaxWidth(200.0f) ); curve.curve = EditorGUILayout.CurveField( curve.curve, Color.red, GetCurveRect(curve.curve), GUILayout.Width(200.0f) ); // Stop drawing horizontally EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel = oldIndentLevel; } } // Now display all of the children of this path node foreach( AnimCurvePathNode node in root.children ) { DrawPathTree( node ); } --EditorGUI.indentLevel; }