static List <ConstGenSettings.LayersCTRLR> RetriveValues() { // find controller GUIDs and create LayersCTRLR list string[] controllers = AssetDatabase.FindAssets("t:animatorcontroller"); List <ConstGenSettings.LayersCTRLR> layersControllers = new List <ConstGenSettings.LayersCTRLR>(); foreach (string CTRLR in controllers) { // get controller and it's path string path = AssetDatabase.GUIDToAssetPath(CTRLR); UnityEditor.Animations.AnimatorController animCTRLR = AssetDatabase.LoadAssetAtPath <UnityEditor.Animations.AnimatorController>(path); if (animCTRLR.layers.Length == 0) { continue; } ConstGenSettings.LayersCTRLR layerCTRLR = new ConstGenSettings.LayersCTRLR(); layerCTRLR.name = animCTRLR.name; // loop through controller's layers and cache it foreach (var layer_ in animCTRLR.layers) { layerCTRLR.layers.Add(layer_.name); } layersControllers.Add(layerCTRLR); } return(layersControllers); }
/// <summary> /// checks if there is any changes on the constants /// </summary> private static void UpdateFile() { if (Application.isPlaying) { return; } bool generate = false; instance.newLayers = RetriveValues(); // check if the number of animation controllers in the assets has changed if (instance.oldLayers.Count != instance.newLayers.Count) { generate = true; } else // else check for changes in the layers of the controllers { // loop through animators for (int i = 0; i < instance.oldLayers.Count && generate == false; i++) { ConstGenSettings.LayersCTRLR oldCTRLR = instance.oldLayers[i]; ConstGenSettings.LayersCTRLR newCTRLR = instance.newLayers[i]; // check if the name of the controller has changed or // if any layers is added or removed if (oldCTRLR.name != newCTRLR.name || oldCTRLR.layers.Count != newCTRLR.layers.Count) { generate = true; break; } else // else check if any of the name of layers has changed { // loop through layers for (int i2 = 0; i2 < oldCTRLR.layers.Count; i2++) { string oldName = oldCTRLR.layers[i2]; string newName = newCTRLR.layers[i2]; // compare layer names if (oldName != newName) { generate = true; break; } } } if (generate) // break out animators loop { break; } } } if (generate) { Generate(); } }