public static bool isInnerCircle(GuidCircleData circle, Vector2 pos) { float dis = Vector2.Distance(pos, circle.centerPos); if (dis <= circle.radius) { return(true); } return(false); }
public static GuidMaskBoardData InitMask(List <GuidMaskData> maskDatas, RectTransform m_RectRoot, GuidUIData uiData) { Vector4[] circleCenter = new Vector4[4]; float[] circleRadius = new float[4]; Vector4[] rectCenter = new Vector4[4]; float[] rectWidth = new float[4]; float[] rectHeigh = new float[4]; int circleIndex = 0; int rectIndex = 0; for (int i = 0; i < maskDatas.Count; i++) { GuidMaskData maskData = maskDatas[i]; Vector2 localLeftBottom = WordToLocalPos(m_RectRoot, maskData.leftBottom); Vector2 localLeftTop = WordToLocalPos(m_RectRoot, maskData.leftTop); Vector2 localRightBottom = WordToLocalPos(m_RectRoot, maskData.rightBottom); Vector2 localRightTop = WordToLocalPos(m_RectRoot, maskData.rightTop); float centerx = (localLeftBottom.x + localRightBottom.x) / 2f; float centery = (localLeftBottom.y + localRightTop.y) / 2f; Vector2 center = new Vector2(centerx, centery); //Vector2 center = WordToLocalPos(maskData.centerPos); float width = localRightBottom.x - localLeftBottom.x; //maskData.width; float heigh = localRightTop.y - localLeftBottom.y; //maskData.heigh; if (maskData.maskType == GuidMaskType.Rect) { rectCenter[rectIndex] = center; rectWidth[rectIndex] = width / 2f; rectHeigh[rectIndex] = heigh / 2f; rectIndex++; uiData.AddRectData(maskData); } else if (maskData.maskType == GuidMaskType.Circle) { circleCenter[circleIndex] = center; circleRadius[circleIndex] = Mathf.Max(width, heigh) / 2f; circleIndex++; GuidCircleData circleData = new GuidCircleData(); circleData.centerPos = new Vector2((maskData.leftBottom.x + maskData.rightBottom.x) / 2f, (maskData.leftBottom.y + maskData.rightTop.y) / 2f); circleData.radius = Mathf.Max(maskData.rightBottom.x - maskData.leftBottom.x, maskData.rightTop.y - maskData.leftBottom.y); circleData.btnName = maskData.btnName; uiData.AddCircleData(circleData); } } GuidMaskBoardData board = new GuidMaskBoardData(circleCenter, circleRadius, rectCenter, rectWidth, rectHeigh); return(board); }
public string CheckLegalPoint(Vector2 worldPos) { for (int i = 0; i < m_rectData.Count; i++) { GuidMaskData rectData = m_rectData[i]; if (GuidTools.isInnerRect(rectData, worldPos)) { //MaskClick(rectData.btnName); return(rectData.btnName); } } for (int i = 0; i < m_CircleData.Count; i++) { GuidCircleData circle = m_CircleData[i]; if (GuidTools.isInnerCircle(circle, worldPos)) { //MaskClick(circle.btnName); return(circle.btnName); } } return(null); }
public void AddCircleData(GuidCircleData data) { CircleData.Add(data); }