public static List <txUIButton> raycast(Ray ray, SortedDictionary <int, List <txUIButton> > buttonList, int maxCount = 0) { bool cast = true; List <txUIButton> retList = new List <txUIButton>(); RaycastHit hit = new RaycastHit(); foreach (var box in buttonList) { int count = box.Value.Count; for (int i = 0; i < count; ++i) { txUIButton button = box.Value[i]; if (button.getHandleInput() && button.Raycast(ray, out hit, 10000.0f)) { retList.Add(button); // 如果射线不能穿透当前按钮,或者已经达到最大数量,则不再继续 if (!button.getPassRay() || maxCount > 0 && retList.Count >= maxCount) { cast = false; break; } } } if (!cast) { break; } } return(retList); }