Skip to content

Commit

Permalink
Merge pull request #134 from Algoryx/fix/constraint-controllers
Browse files Browse the repository at this point in the history
Fixed constraint controllers not handling multiple controllers of same type
  • Loading branch information
FilipAlg authored Nov 15, 2023
2 parents a07856b + da25927 commit 893d38c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions Editor/AGXUnityEditor/Tools/ConstraintTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,31 @@ in constraintsParser
GUI.MakeLabel( "Controllers", true ) ) ) {
using ( InspectorGUI.IndentScope.Single ) {
foreach ( var refController in ecControllers ) {
// Skip Cone Limit friction controllers
if ( refController.NativeName.StartsWith( "CL" ) )
continue;

var controllerType = refController.GetControllerType();
var controllerTypeTag = controllerType.ToString()[ 0 ].ToString();
var controllerName = ConstraintUtils.FindName( refController );
if ( controllerName.EndsWith( " Controller" ) )
controllerName = controllerName.Remove( controllerName.LastIndexOf( " Controller" ) );
string nativeTag = GetNativeNameTag(refController.NativeName);
var controllerLabel = GUI.MakeLabel( ( controllerType == Constraint.ControllerType.Rotational ?
GUI.Symbols.CircleArrowAcw.ToString() + " " :
GUI.Symbols.ArrowRight.ToString() + " " ) + controllerName, true );
if ( !InspectorGUI.Foldout( selected( controllerTypeTag + controllerName ),
GUI.Symbols.ArrowRight.ToString() + " " ) +
controllerName +
nativeTag,
true );
if ( !InspectorGUI.Foldout( selected( controllerTypeTag + controllerName + refController.NativeName ),
controllerLabel ) ) {
continue;
}

var controllers = ( from constraint
in constraints
from controller
in constraint.GetElementaryConstraintControllers()
where controller.GetType() == refController.GetType() &&
controller.GetControllerType() == refController.GetControllerType()
where controller.NativeName == refController.NativeName
select controller ).ToArray();
using ( InspectorGUI.IndentScope.Single ) {
InspectorEditor.DrawMembersGUI( controllers );
Expand All @@ -222,6 +228,17 @@ where controller.GetType() == refController.GetType() &&
}
}

private static string GetNativeNameTag( string nativeName )
{
if ( nativeName[ 0 ] == 'F' ) {
string dimLabel = nativeName[1].ToString();
if ( RowLabels.Contains( dimLabel ) )
return " " + GUI.AddColorTag( dimLabel, RowColors[ Array.IndexOf( RowLabels, dimLabel ) ] );
}

return "";
}

private bool ConstraintTypeGUI( Constraint[] constraints, bool differentTypes )
{
var anyUnknownType = constraints.Any( c => c.Type == ConstraintType.Unknown );
Expand Down

0 comments on commit 893d38c

Please sign in to comment.