public override void WhenCannotMoveTo(Vector2 moveTo) { Vector2 camPos2D = Math_F.Vector3_2D(cacheTrans.position); Vector2 tryPos = camPos2D + (moveTo - camPos2D).normalized * 0.5f; #if UNITY_EDITOR Vector3 tryPos3D = cacheTrans.position; tryPos3D.x = tryPos.x; tryPos3D.z = tryPos.y; tryPoint.position = tryPos3D; Vector3 moveToPos3D = cacheTrans.position; moveToPos3D.x = moveTo.x; moveToPos3D.z = moveTo.y; moveToPoint.position = moveToPos3D; #endif Vector2 lineStart; int idxStart; Vector2 lineEnd; int idxEnd; Vector2 crossPos = Math_F.GetClosestCrossPoint(tryPos, cameraArea, out lineStart, out idxStart, out lineEnd, out idxEnd); #if UNITY_EDITOR LogWarp.LogErrorFormat("WhenCannotMoveTo moveToPoint={0}, crossPos={1}, lineStart={2}, idxStart={3}, lineEnd={4}, idxEnd={5}", moveToPos3D, crossPos, lineStart, idxStart, lineEnd, idxEnd); #endif bool isCrossInLine = false; Vector2 crossDir = Vector2.zero; for (int i = 0; i < cameraArea.Count; i++) { if (Math_F.Approximate2D(crossPos, cameraArea[i], 0.5f)) { LogWarp.LogErrorFormat("WhenCannotMoveTo crossPos == {0}", i); isCrossInLine = true; crossDir = (cameraArea[(i + 1) % cameraArea.Count] - cameraArea[i]).normalized; break; } } //Debug.LogError("GetClosestCrossPoint"); //if (Math_F.IsPointInPolygon(crossPos, cameraArea)) { //Debug.LogError("IsPointInPolygon"); Vector3 camPos3D = cacheTrans.position; camPos3D.x = crossPos.x; camPos3D.z = crossPos.y; #if UNITY_EDITOR crossPoint.position = camPos3D; #endif switch (dragType) { case DragType.Normal: cacheTrans.position = camPos3D; break; case DragType.NormalPlus: if (!isCrossInLine) { dragSmoothDir = (lineEnd - lineStart).normalized * crossSensitivity; float dot = Vector2.Dot((moveTo - camPos2D).normalized, (lineEnd - lineStart).normalized); if (dot < 0) { dragSmoothDir *= -1f; } } else { dragSmoothDir = crossDir * crossSensitivity; } break; default: string e = string.Format("不支持滑动类型{0}", dragType); throw new System.Exception(e); } } }