public static void applyAnchor(GameObject obj, bool force, GameLayout layout = null) { // 先更新自己 obj.GetComponent <ScaleAnchor>()?.updateRect(force); obj.GetComponent <PaddingAnchor>()?.updateRect(force); if (layout != null) { txUIObject uiObj = layout.getUIObject(obj); uiObj?.notifyAnchorApply(); } // 然后更新所有子节点 Transform curTrans = obj.transform; int childCount = curTrans.childCount; for (int i = 0; i < childCount; ++i) { applyAnchor(curTrans.GetChild(i).gameObject, force, layout); } }