public static bool isInnerRect(GuidMaskData maskdata, Vector2 pos) { if (pos.x >= maskdata.leftBottom.x && pos.x <= maskdata.rightBottom.x && pos.y >= maskdata.leftBottom.y && pos.y <= maskdata.rightTop.y) { 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 AddRectData(GuidMaskData data) { RectData.Add(data); }
protected override void OnOpenUI(GUIFrame uiLogic) { base.OnOpenUI(uiLogic); TimeModule.Instance.SetTimeout(delegate() { tweens.Clear(); GuidMaskCommonData maskCommonDatas = new GuidMaskCommonData(); List <GuidMaskData> maskDatas = new List <GuidMaskData>(); for (int i = 0; i < m_CurConf.maskName.Length; i++) { string btnStr = m_CurConf.maskName[i].Replace(":", "/"); Transform srcTran = uiLogic.FrameRootTransform.Find(btnStr); if (srcTran == null) { continue; } //if (srcTran.GetComponent<Image>() == null && srcTran.GetComponent<RawImage>() == null) //{ // Image srcRay = srcTran.gameObject.AddComponent<Image>(); // srcRay.raycastTarget = true; // srcRay.color = new Color(1,1,1,0.01f); //} //TweenScale srcTween = srcTran.gameObject.AddComponent<TweenScale>(); //srcTween.to = Vector3.one * 1.2f; //srcTween.duration = 0.5f; //srcTween.style = UITweenerBase.Style.PingPong; //srcTween.Play(); //tweens.Add(srcTween); RectTransform srcRect = srcTran.GetComponent <RectTransform>(); if (srcRect != null) { Vector2[] cornPos = GuidTools.getCornPos(srcRect); GuidMaskData maskData = new GuidMaskData(); maskData.leftBottom = cornPos[0]; maskData.leftTop = cornPos[1]; maskData.rightTop = cornPos[2]; maskData.rightBottom = cornPos[3]; maskData.maskType = (GuidMaskType)m_CurConf.maskType[i]; if (m_CurConf.btnName.Length > i) { maskData.btnName = m_CurConf.btnName[i]; } else { maskData.btnName = string.Empty; } maskDatas.Add(maskData); } } List <Vector2> artAnchor = GuidTools.getArtPos(uiLogic.FrameRootTransform, m_CurConf); maskCommonDatas.m_confGuid = m_CurConf; maskCommonDatas.m_maskdata = maskDatas; maskCommonDatas.hasEvent = true; maskCommonDatas.m_artPos = artAnchor; maskCommonDatas.eventPassType = (EventPassType)m_CurConf.eventPassType; //maskCommonDatas.m_artPath = new List<string>(m_CurConf.artPath); if (m_CurConf.btnName == null || m_CurConf.btnName.Length == 0) { maskCommonDatas.hasEvent = false; } maskCommonDatas.m_operaType = (GuidEnum)m_CurConf.type; float.TryParse(m_CurConf.typeValue, out maskCommonDatas.m_TypeValue); FrameMgr.OpenUIParams param = new FrameMgr.OpenUIParams(UIDefine.UI_GUID); param.Param = maskCommonDatas; EngineCoreEvents.UIEvent.ShowUIEventWithParam.SafeInvoke(param); }, 0.1f); }