/// <summary> /// 查找角色,武器,配件的关节请使用缓存版本的函数BoneMount.FindChildBoneFromCache /// </summary> /// <param name="obj"></param> /// <param name="target"></param> /// <param name="ignoreMissing"></param> /// <returns></returns> /// <seealso cref="BoneMount.FindChildBoneFromCache"/> public static Transform FindChildBone(GameObject obj, string target, bool ignoreMissing = false) { if (obj != null && target != null) { var r = BoneTool.FindTransformFromCache(obj, target); if (r == null) { _logger.InfoFormat("target:{0} is not cached!!!!", target); r = obj.transform.FindTransformRecursive(target); } if (r == null && !ignoreMissing) { _logger.DebugFormat("missing {0} in {1}", target, obj.name); } return(r); } else { _logger.DebugFormat("null object or null target in FindChildBone"); } return(null); }
private static void FindTarget(GameObject obj, string target, ref Transform r, bool containsUnActive = false) { CacheResults.Clear(); obj.GetComponentsInChildren <TransformCache>(CacheResults); if (CacheResults.Count == 0) { _logger.DebugFormat("obj:{0} has no cache", obj); } foreach (TransformCache transformCache in CacheResults) { r = BoneTool.FindTransformFromCache(transformCache, target, containsUnActive); if (r != null) { break; } } }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <param name="target"></param> /// <param name="containsAttach">是否包含子节点缓存</param> /// <param name="containsUnActive">是否包含UnActive的节点</param> /// <returns></returns> public static Transform FindChildBoneFromCache(GameObject obj, string target, bool containsAttach = true, bool containsUnActive = false) { Transform r = null; if (obj != null && target != null) { if (containsAttach) { FindTarget(obj, target, ref r, containsUnActive); } else if (obj.GetComponent <TransformCache>() == null) { FindTarget(obj, target, ref r, containsUnActive); } else { r = BoneTool.FindTransformFromCache(obj, target, containsUnActive); } return(r); } _logger.DebugFormat("null object or null target in FindChildBone"); return(null); }