///初始化位置,为接下来的move做准备 public override void TouchBegin(Vector3 point) { RaycastHit hit; if (eternalTarget != null) { target = eternalTarget; } else if (target == null && RayDetection(out hit)) { target = hit.transform; } if (target != null) { touchStatusCallback = target.GetComponent <TouchStatusCallback>(); if (touchStatusCallback != null) { touchStatusCallback.TouchBegin(point); target = touchStatusCallback.GetMoveTransform(); } beginP = point; endP = point; speed = Vector3.zero; DataManager.Instance.getData("TouchStatus").SetNumberValue("pickUp", 1); Renderer rend = target.GetComponent <Renderer>(); if (rend != null) { targetSize = rend.bounds.size; } else { Image image = target.GetComponent <Image>(); if (image != null) { targetSize = image.GetComponent <RectTransform>().sizeDelta *image.transform.localScale.y *uiRect.lossyScale.y; } else { targetSize = Vector3.zero; } } isTouch = true; if (isBounds) { if (isReverse) { //保证不会移出包围盒 tempMin = new Vector2(minVec3.x - (targetSize.x - sizeVec3.x) + targetSize.x / 2, minVec3.y - (targetSize.y - sizeVec3.y) + targetSize.y / 2); tempMax = new Vector2(maxVec3.x + (targetSize.x - sizeVec3.x) - targetSize.x / 2, maxVec3.y + (targetSize.y - sizeVec3.y) - targetSize.y / 2); } else { //保证不会移出包围盒 tempMin = new Vector2(minVec3.x + targetSize.x / 2, minVec3.y + targetSize.y / 2); tempMax = new Vector2(maxVec3.x - targetSize.x / 2, maxVec3.y - targetSize.y / 2); } } } }
///Move结束,清除数据 public override void TouchEnd(Vector3 point) { if (!isSlide) { target = null; speed = Vector3.zero; } beginP = point; DataManager.Instance.getData("TouchStatus").SetNumberValue("pickUp", 0); if (touchStatusCallback != null) { touchStatusCallback.TouchEnd(point); touchStatusCallback = null; } isTouch = false; }