/// <summary> /// Fix the instantiated object (in some cases object have wrong position, rotation and scale). /// </summary> /// <param name="source">Source.</param> /// <param name="instance">Instance.</param> static public void FixInstantiated(ResNode source, GameObject instance) { var rectTransform = instance.transform as RectTransform; rectTransform.localPosition = source.GetResPosition(); rectTransform.localRotation = source.GetResRotation(); rectTransform.localScale = source.GetResScale(); rectTransform.anchoredPosition = source.GetResAnchoredPosition(); rectTransform.sizeDelta = source.GetResSizeDelta(); }
/// <summary> /// 添加显示对象 /// </summary> protected TComponent AddItemComponent(TItem newItem) { if (DefaultItemComponentRes == null) { return(null); } TComponent component; if (m_ItemComponentsCache.Count > 0) { component = m_ItemComponentsCache[m_ItemComponentsCache.Count - 1]; m_ItemComponentsCache.RemoveAt(m_ItemComponentsCache.Count - 1); } else { component = DefaultItemComponentRes.InstanceMainRes <TComponent>(); component.transform.SetParent(Container, false); Utilites.FixInstantiated(component.gameObject, DefaultItemComponentRes.GetResPosition(), DefaultItemComponentRes.GetResRotation(), DefaultItemComponentRes.GetResScale(), DefaultItemComponentRes.GetResAnchoredPosition(), DefaultItemComponentRes.GetResSizeDelta()); } component.transform.SetAsLastSibling(); component.gameObject.SetActive(true); m_ItemComponent.Add(component); newItem.ClearPopupMenuAction = OnClickAction; component.onEnter.AddListener(OnEnterAction); component.onExit.AddListener(OnExitAction); SetData(component, newItem); return(component); }