private int ComparisonFunc(UIElement ui_element_1, UIElement ui_element_2) { if (ui_element_1 == ui_element_2) { return(0); } if (ui_element_1.HierarchyPos != ui_element_2.HierarchyPos) { return(ui_element_2.HierarchyPos.CompareTo(ui_element_1.HierarchyPos)); } UIWidget w1 = ui_element_1.GetComponent <UIWidget>(); UIWidget w2 = ui_element_2.GetComponent <UIWidget>(); if (w1 != null && w2 != null) { if (w2.depth != w1.depth) { return(w2.depth.CompareTo(w1.depth)); } return(MathTool.CompareRect(w1.worldCorners, w2.worldCorners)); } return(0); }