public void OnDrag(UnityEngine.EventSystems.PointerEventData eventData) { if (m_Canvas != null) { this.transform.localPosition = JerryUtil.PosScreen2Canvas(m_Canvas, JerryUtil.GetClickPos(), this.transform); } }
private void UpdateCtr() { if (m_Selected && Input.GetKeyDown(KeyCode.N)) { Flag.Inst.Set2Pos(JerryUtil.GetClickPos() - m_Offset); } }
private void CalOffset() { Vector3 pos = MapUtil.GetMap(m_InitData.m_CurWall).Adjust2Wall(this.transform.position); //Debug.LogWarning("calOffset " + pos + " wall=" + m_InitData.m_CurWall + " " + MapUtil.Vector3String(this.transform.position)); m_Offset = JerryUtil.GetClickPos() - Camera.main.WorldToScreenPoint(pos); //第一步,先记录一下位置,不给走 m_LastDragingPos = JerryUtil.GetClickPos() - m_Offset; }
private void OnCameraDown(bool usefull) { this.StopCoroutine("IE_AdjustCamera"); m_DragUsefull = usefull; if (!usefull) { return; } m_LastPos = JerryUtil.GetClickPos(); }
private void JudgeDrag() { m_Offset = JerryUtil.GetClickPos() - m_LastPos; if (Mathf.Abs(m_Offset.x) < 3f) { return; } m_LastPos = JerryUtil.GetClickPos(); m_LastOffset = m_Offset; m_LastOffsetTime = Time.realtimeSinceStartup; DoDrag(-m_Offset.x); }
private bool JudgePosOutScreen() { if (JerryUtil.GetClickPos().x < GameApp.Inst.m_OutScreenJudgeFactor) { CameraCtr.Inst.DoDrag(-GameApp.Inst.m_OutScreenDragFactor); return(true); } else if (Screen.width - JerryUtil.GetClickPos().x < GameApp.Inst.m_OutScreenJudgeFactor) { CameraCtr.Inst.DoDrag(GameApp.Inst.m_OutScreenDragFactor); return(true); } return(false); }
private void UpdatePC() { if (Input.GetMouseButtonDown(0)) { m_TouchStarted = true; m_TouchStartPos = JerryUtil.GetClickPos(); } else if (Input.GetMouseButtonUp(0)) { if (m_TouchStarted) { Judge(); m_TouchStarted = false; } } }
/// <summary> /// 静态化可以其他地方复用 /// </summary> /// <returns></returns> public static RayClickInfo DoRayClick() { clickInfo.Init(); ray = Camera.main.ScreenPointToRay(JerryUtil.GetClickPos()); if (Physics.Raycast(ray, out hitInfo, 100)) { if (hitInfo.collider != null) { clickInfo.pos = hitInfo.point; clickInfo.col = hitInfo.collider; clickInfo.time = Time.realtimeSinceStartup; clickInfo.screenPos = JerryUtil.GetClickPos(); } } return(clickInfo); }
void Awake() { m_Canvas = this.transform.parent.GetComponent <Canvas>(); UGUIEventListener.Get(this.gameObject).onDown += (go) => { m_LastDownPos = JerryUtil.GetClickPos(); }; UGUIEventListener.Get(this.gameObject).onUp += (go) => { Vector3 pos = JerryUtil.GetClickPos(); if ((pos - m_LastDownPos).sqrMagnitude > 0.01f) { return; } DoClick(); }; }
private void Judge() { Vector3 start = m_TouchStartPos; Vector3 end = JerryUtil.GetClickPos(); float dis = Vector2.Distance(start, end); if (dis < m_MinSwipeDistancePixels) { return; } float angle = Mathf.Rad2Deg * Mathf.Atan2(end.y - start.y, end.x - start.x); angle = (360 + angle) % 360; int iAngle = (int)((angle + m_PartAngle * 0.5f) % 360); //Debug.LogWarning("i:" + iAngle + " " + angle); JudgeDir(iAngle / m_PartAngle); }
private IEnumerator IE_DoDrag() { Camera camera = Camera.main; if (camera == null) { yield break; } CalOffset(); while (m_InDraging) { if (Util.Vector3Equal(JerryUtil.GetClickPos() - m_Offset, m_LastDragingPos, 2) && !JudgePosOutScreen()) //移动屏幕的时候,相对位置永远不变,这样物体不会更随 { yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame());//等两帧,减小频率 continue; } m_LastDragingPos = JerryUtil.GetClickPos() - m_Offset; m_Ray = Camera.main.ScreenPointToRay(m_LastDragingPos); if (Physics.Raycast(m_Ray, out m_HitInfo, 100, JerryUtil.MakeLayerMask(JerryUtil.MakeLayerMask(false), MapUtil.GetWallLayerNames(m_Config.setType)))) { if (m_HitInfo.collider != null && m_HitInfo.collider.gameObject != null) { RayClickPos fp = new RayClickPos(); fp.pos = m_HitInfo.point; fp.wallType = MapUtil.WallLayer2WallEnum(m_HitInfo.collider.gameObject.layer); //Debug.LogWarning(fp.wallType + " xxx " + m_InitData.m_CurWall); if (fp.wallType != m_InitData.m_CurWall || !Util.Vector3Equal(fp.pos, m_LastPos)) { m_LastPos = fp.pos; if (fp.wallType == m_InitData.m_CurWall) { UI_Ctr.Inst.HideCtr(); //Debug.LogWarning("bbbb================ " + MapUtil.Vector3String(fp.pos)); if (Place2Pos(fp.pos, true)) { CalOffset(); //yield break; } } else { if (fp.wallType != Enum_Wall.Floor && m_Config.setType != MapUtil.SetType.Floor) { //Debug.LogWarning("aaaa================"); UI_Ctr.Inst.HideCtr(); SelectChange2Wall(m_InitData.m_CurWall, fp.wallType, fp.pos); //yield return new WaitForEndOfFrame(); CalOffset(); //yield break; } } } } } yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame());//等两帧,减小频率 } if (m_Selected) { UI_Ctr.Inst.ShowCtr(); //Debug.LogWarning("Click ShowCtr"); } }