private void Combine(DragAbleParent combined_, DragAbleParent combine_) { foreach (RectTransform combine_logic_rect in combine_.m_child_logic_rect_list) { combined_.m_child_logic_rect_list.Add(combine_logic_rect); combine_logic_rect.SetParent(combined_.transform, true); } foreach (DragAble combine_icon in combine_.m_child_icon_list) { combined_.m_child_icon_list.Add(combine_icon); combine_icon.transform.SetParent(combined_.transform, true); } m_drag_able_parents_list.Remove(combine_); GameObject.DestroyImmediate(combine_.gameObject); }
private void JudgeCombine(DragAbleParent moved_dp_) { List <RectTransform> move_end_logic_rects = moved_dp_.m_child_logic_rect_list; List <DragAble> move_end_icons = moved_dp_.m_child_icon_list; Vector2 offset = Vector2.zero; foreach (RectTransform move_end_logic_rect in move_end_logic_rects) { Dictionary <string, ENUM_RECT_DIR> neighbours = this.GetNeighbours(move_end_logic_rect.gameObject.name); if (0 == neighbours.Count) { Debug.LogError(string.Format("拼图 {0} 没有邻居", move_end_logic_rect.gameObject.name)); continue; } foreach (DragAbleParent judge_dp in m_drag_able_parents_list) { if (judge_dp == moved_dp_) { continue; } foreach (RectTransform cur_logic_rect in judge_dp.m_child_logic_rect_list) { string cur_name = cur_logic_rect.gameObject.name; if (neighbours.ContainsKey(cur_name)) { if (this.IsNear(move_end_logic_rect, cur_logic_rect, neighbours[cur_name], out offset)) { this.MoveAndCombine(moved_dp_, judge_dp, offset); return; } } } } } }
private void MoveAndCombine(DragAbleParent move_end_dp_, DragAbleParent neighbour_, Vector2 offset) { move_end_dp_.m_self_rtf.anchoredPosition += offset; this.Combine(move_end_dp_, neighbour_); }