What I want to do: list all the individual MotionGroups and animation clips that a character has in an editor script, so that they can be individually tweaked (weights, etc.) in a very simple animation editor.
The problem: I can’t seem to access neither the LocomotionEditorClass’ nor the LegController’s list of motiongroups. In the latter case, this is a natural consequence of the groups being generated at runtime. But for the LocomotionEditorClass, it seems a limitation in the system.
I.e., it’s not possible to use GetComponent on an Editor script, nor can I use FindObject(s)OfType or similar functionality, because the script is not a MonoBehaviour or ScriptableObject.
Does anyone have an idea how I might do this? It’s just to get the names in the editor, so they can be linked for the runtime classes.
I found out one very ugly way to do this, by using static variables. This is NOT how it should work, as it will make every instance of the script modify the same target variable. Makes it impossible to work with several objects using Locomotion, in this case.
So, really, anyone know a way to access editor scripts from other editor scripts without using static variables?
I managed to solve this! Hopefully, this snippet can be useful for someone else as well.
Basically, the LegController contains references to all the analyzers that it uses during runtime. These in turn reference the motion groups they belong to!
Thus, using GetComponent to grab the LegController, you can do something like this:
List<string> tmpMotionGroups = new List<string>();
foreach( MotionAnalyzer Analyzer in m_LegController.sourceAnimations )
{
string tmpMotionGroup = Analyzer.motionGroup;
if ( !tmpMotionGroups.Contains( tmpMotionGroup ) )
tmpMotionGroups.Add( tmpMotionGroup );
}
The tmpMotionGroups list will now contain all the motion groups used by the LegController in the particular animated object you apply the script to.