public List <FindResult> FindComponents(string searchPath, string filter, ClassInfo classInfo, BatchExpressionGroup root) { List <FindResult> results = new List <FindResult>(); List <string> assets = FindAsset.FindAllAssets(searchPath, filter); FixExpressionsValue(classInfo, root); for (int i = 0; i < assets.Count; ++i) { GameObject gameObj = AssetDatabase.LoadAssetAtPath <GameObject>(assets[i]); if (gameObj != null) { Component[] insts = gameObj.GetComponentsInChildren(classInfo.type); if (insts != null && insts.Length > 0) { for (int j = 0; j < insts.Length; ++j) { if (CheckConditions(classInfo, insts[i], root)) { results.Add(new FindResult(assets[i] + ":" + HierarchyUtil.FullPath(insts[j].transform), insts[j])); } } } } } return(results); }
void DoAutoFix() { if (m_Clip) { GameObject root = GetRoot(); if (root) { EditorCurveBinding[] bindings = GetAllCurveBindings(m_Clip); for (int i = 0; i < bindings.Length; ++i) { EditorCurveBinding binding = bindings[i]; Debug.Log("binding path=" + binding.path + ",propName=" + binding.propertyName + ",PPtrCurve=" + binding.isPPtrCurve + ",type=" + binding.type); GameObject animatedObject = AnimationUtility.GetAnimatedObject(root, binding) as GameObject; if (!animatedObject && !root.transform.Find(binding.path)) { //不存在则修正 //Debug.Log("can't find:" + binding.path); //二种修正,一种是上移,从子节点移到父结点。一种是下移,从父节点移到子结点。 string path = binding.path; //查找存在的父结点。存在的就是没有被移动的。 string[] result = LookForExists(root, path); //自动修正,只能修正不会有重名的元素。 //比如根结点有个Name,Panel有个Name,把Name移到,PanelTT下,则可能无法正确找到PanelTT下的Name //获取被移动GameObject animatedObject = HierarchyUtil.SearchGameObject(result[1], root); if (!animatedObject) { Debug.LogWarning("can't find:" + result[1]); continue; } string newPath = AnimationUtility.CalculateTransformPath(animatedObject.transform, root.transform); Debug.Log("fix path:" + path + ",to:" + newPath); FixCurveBinding(m_Clip, binding, newPath); } } } else { Debug.LogWarning("root is null"); } } else { Debug.LogWarning("AnimationClip is null"); } }
void TestFind(string path) { Debug.Log("look for " + path); GameObject root = Selection.activeGameObject; GameObject obj = HierarchyUtil.SearchGameObject(path, root); Debug.Log("searched:" + obj); if (obj) { EditorCurveBinding[] bindings = AnimationUtility.GetAnimatableBindings(obj, root); for (int i = 0; i < bindings.Length; ++i) { EditorCurveBinding binding = bindings[i]; Debug.Log("binding path=" + binding.path + ",propName=" + binding.propertyName + ",PPtrCurve=" + binding.isPPtrCurve + ",type=" + binding.type); } } }