private static void SearchMotion(RuntimeAnimatorController animator, UnityEditor.Animations.AnimatorStateMachine stateMachine, AssetData assetData) { var stateCount = 0; if (isUnity41) { stateCount = (int)stateMachine.GetType().GetMethod("GetStateCount").Invoke(stateMachine, new object[0]); } else { stateCount = (int)stateMachine.GetType().GetProperty("stateCount").GetValue(stateMachine, new object[0]); } for (var k = 0; k < stateCount; k++) { var state = stateMachine.states[k]; var parameters = new object[0]; var types = new Type[0]; if (isUnity41) { ArrayUtility.Add(ref parameters, 0); ArrayUtility.Add(ref types, typeof(int)); } var motion = state.GetType().GetMethod("GetMotion", types).Invoke(state, parameters) as Motion; if (motion) { SearchBlendTreeMotion(animator, motion, assetData); } } }
public static void Build(string[] assetPaths, Action <AssetData[]> callback = null) { var result = new AssetData[0]; for (var i = 0; i < assetPaths.Length; i++) { var assetPath = assetPaths[i]; var assetData = new AssetData { path = assetPath, guid = AssetDatabase.AssetPathToGUID(assetPath) }; var progress = (float)i / assetPaths.Length; switch (Path.GetExtension(assetPath)) { case ".prefab": { DisplayProgressBar(assetData.path, progress); var prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject; var go = (GameObject)PrefabUtility.InstantiatePrefab(prefab); go.hideFlags = HideFlags.HideAndDontSave; SearchGameObject(go, assetData); Object.DestroyImmediate(go); } break; case ".unity": DisplayProgressBar(assetData.path, progress); if (EditorApplication.OpenScene(assetPath)) { foreach (GameObject go in Object.FindObjectsOfType(typeof(GameObject))) { SearchGameObject(go, assetData, true); } } break; case ".controller": var animator = (RuntimeAnimatorController) AssetDatabase.LoadAssetAtPath(assetPath, typeof(RuntimeAnimatorController)); var layerCount = 0; if (isUnity41) { layerCount = (int)animator.GetType().GetMethod("GetLayerCount").Invoke(animator, new object[0]); } else { PropertyInfo info = animator.GetType().GetProperty("layerCount"); if (info != null) { layerCount = (int)info.GetValue(animator, new object[0]); } } for (var j = 0; j < layerCount; j++) { UnityEditor.Animations.AnimatorStateMachine stateMachine = null; if (isUnity41) { stateMachine = (UnityEditor.Animations.AnimatorStateMachine) animator.GetType() .GetMethod("GetLayerStateMachine") .Invoke(animator, new object[] { j }); } else { var layer = animator.GetType().GetMethod("GetLayer").Invoke(animator, new object[] { j }); stateMachine = (UnityEditor.Animations.AnimatorStateMachine)layer.GetType().GetProperty("stateMachine").GetValue(layer, new object[0]); } SearchMotion(animator, stateMachine, assetData); var stateMachineCount = 0; if (isUnity41) { stateMachineCount = (int)stateMachine.GetType().GetMethod("GetStateMachineCount").Invoke(stateMachine, new object[0]); } else { stateMachineCount = (int)stateMachine.GetType().GetProperty("stateMachineCount").GetValue(stateMachine, new object[0]); } for (var s = 0; s < stateMachineCount; s++) { SearchMotion(animator, stateMachine.stateMachines[s].stateMachine, assetData); } } break; case ".mat": var material = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Material)) as Material; AddAttachedAsset(material, material.shader, assetData, false); var propertyCount = ShaderUtil.GetPropertyCount(material.shader); for (var j = 0; j < propertyCount; j++) { if (ShaderUtil.GetPropertyType(material.shader, j) != ShaderUtil.ShaderPropertyType.TexEnv) { continue; } var propertyName = ShaderUtil.GetPropertyName(material.shader, j); AddAttachedAsset(material, material.GetTexture(propertyName), assetData, false); } break; default: SearchFieldAndProperty(AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)), assetData); break; } ArrayUtility.Add(ref result, assetData); } callback(result); depths.Clear(); EditorUtility.ClearProgressBar(); }