public void SetupVariants(Variant[] vars) { if (!m_instance) { return; } int count = vars.Length; while (m_variants.Count < count) { Transform newPlace = Instantiate(m_gridInstance, m_gridParent); m_gridElements.Add(newPlace); DragNDropHandle newVariant = Instantiate(m_instance, transform); newVariant.SetModule(m_module); m_variants.Add(newVariant); } for (int i = count; i < m_variants.Count; ++i) { m_variants[i].gameObject.SetActive(false); } m_vars = ShuffleList(vars); StartCoroutine(InitValues()); }
public ArrangeCell TryAddToCell(DragNDropHandle handle) { foreach (var cell in m_cells) { if (cell.CheckFalling(handle)) { cell.SwapHandles(handle); return(cell); } } return(null); }
public DragNDropHandle SwapHandles(DragNDropHandle newHandle) { DragNDropHandle oldHandle = m_item; if (oldHandle) { oldHandle.ResetCell(); oldHandle.SetPos(newHandle.GetStartPos()); } m_item = newHandle; RectTransform rect = transform as RectTransform; m_item.transform.position = transform.position;// + new Vector3(rect.rect.center.x, rect.rect.center.y); return(oldHandle); }
public bool CheckFalling(DragNDropHandle handle) { RectTransform rect = transform as RectTransform; return(RectTransformUtility.RectangleContainsScreenPoint(rect, handle.transform.position)); }
public void ResetItem() { m_item = null; }