public bool UF_AddToCanvas(string canvas, UIUpdateGroup target, bool normalize = true) { if (target == null) { return(false); } if (m_DicCanvas.ContainsKey(canvas)) { target.rectTransform.SetParent(m_DicCanvas [canvas].transform); target.rectTransform.SetAsLastSibling(); if (normalize) { UF_NormalizeRectTransform(target.rectTransform); } else { target.rectTransform.localPosition = Vector3.zero; target.rectTransform.localEulerAngles = Vector3.zero; target.rectTransform.localScale = Vector3.one; } return(true); } else { Debugger.UF_Error(string.Format("Not Cantains Canvas[{0}],Add To Canvas Failed!", canvas)); return(false); } }
//构建更新列表,用于UIUpdateGroup 自身构建 public static void UF_BuildUpdateList(UIUpdateGroup headGroup, List <UnityEngine.Object> ret) { ret.Clear(); List <UIUpdateGroup> m_TmpGroups = new List <UIUpdateGroup>(); List <UnityEngine.Object> uiupdates = new List <UnityEngine.Object> (); UF_searchSubUIUpdatables(headGroup.gameObject, uiupdates); m_TmpGroups.Clear(); //耗时较长,待优化,1K个物体耗时越为10毫秒 for (int k = 0; k < uiupdates.Count; k++) { if (uiupdates[k] != headGroup) { if (uiupdates [k] is UIUpdateGroup) { UIUpdateGroup tmp = uiupdates [k] as UIUpdateGroup; m_TmpGroups.Add(tmp); UF_BuildUpdateList(tmp, tmp.ListUpdateUI); } UIUpdateGroup targetParentGroup = UF_findParentGroup((uiupdates [k] as MonoBehaviour).transform, m_TmpGroups, headGroup); if (targetParentGroup == headGroup) { ret.Add(uiupdates [k]); } } } m_TmpGroups.Clear(); }
private static UIUpdateGroup UF_findParentGroup(Transform current, List <UIUpdateGroup> uigroups, UIUpdateGroup rootGroup) { current = current.parent; while (current != null && current != rootGroup.transform) { for (int k = uigroups.Count - 1; k >= 0; --k) { if (current == uigroups [k].transform) { return(uigroups [k]); } } current = current.parent; } return(rootGroup); }