public void OnBeginDrag(PointerEventData eventData) { transform.SetSiblingIndex(transform.childCount); StartPosition = rectTransform.anchoredPosition; isDrag = true; wasInBottom = true; if (isInFormContainer == false) { wasInBottom = false; } LevelM.RegenerateCurrentLevel(); }
public void OnEndDrag(PointerEventData eventData) { float x = rectTransform.anchoredPosition.x; float y = rectTransform.anchoredPosition.y; System.Action <ITween <Vector3> > updateSize = (t) => { gameObject.transform.localScale = t.CurrentValue; }; if (isInFormContainer == false) { if (rectTransform.anchoredPosition.x < 0) { rectTransform.anchoredPosition = new Vector2(000, y); } if (rectTransform.anchoredPosition.y > 0) { rectTransform.anchoredPosition = new Vector2(x, 000); } if (rectTransform.anchoredPosition.x > 576 - FormBuild.Width * 32) { rectTransform.anchoredPosition = new Vector2(576 - FormBuild.Width * 32, y); } if (rectTransform.anchoredPosition.y < -832 + FormBuild.Height * 32) { rectTransform.anchoredPosition = new Vector2(x, -832 + FormBuild.Height * 32); } //Snap to Grid x = rectTransform.anchoredPosition.x; y = rectTransform.anchoredPosition.y; int xf = (int)Mathf.Round(x / 64); int yf = (int)Mathf.Round(y / 64); x = xf * 64 - 32; y = yf * 64 - 32; //x = xf * 32 + LevelM.LevelWUneven * 16; //y = yf * 32 + LevelM.LevelHUneven * 16; rectTransform.anchoredPosition = new Vector2(x, y); xpos = (int)x; ypos = (int)y; RealX = (xpos - (int)LevelM.LevelX) / 64 - 1; RealY = (ypos + (int)LevelM.LevelY + 235) / 64 * -1 - 2; if (LevelM.CheckNoCollision(this) == false) { if (wasInBottom == true) { gameObject.transform.parent = GameObject.Find("ScaleThem").transform; gameObject.Tween("SizeUp", Vector3.one, Vector3.one * 0.5f, 0.1f, TweenScaleFunctions.CubicEaseIn, updateSize); isInFormContainer = true; rectTransform.anchoredPosition = StartPosition; xpos = (int)StartPosition.x; ypos = (int)StartPosition.y; } else { rectTransform.anchoredPosition = StartPosition; xpos = (int)StartPosition.x; ypos = (int)StartPosition.y; } } } else { if (x < 10) { x = 10; } if (x > 580 - FormBuild.Width * 32) { x = 580 - FormBuild.Width * 32; } if (y < -290 + FormBuild.Height * 32) { y = -290 + FormBuild.Height * 32; } rectTransform.anchoredPosition = new Vector2(x, y); } isDrag = false; LevelM.RegenerateCurrentLevel(); this.transform.Find("shadow").GetComponent <Image>().enabled = false; }