void Update() { if (mapControl != null) { mapControl.Update(); _mouseStatus.Update(); if (_mouseStatus.GetMouseJustDown(MouseStatus.KEY.LEFT) && !UICamera.Raycast(Input.mousePosition)) { Vector3 worldPoint; Vector3 mousePosition = _mouseStatus.GetMouseJustDownPos(); bool raycast = _campaignCamera.ProjectScreenPointToPlane(out worldPoint, mousePosition); if (raycast) { int tileIndex = mapControl.DetectTileIndex(worldPoint); if (tileIndex >= 0) { if (_campaignPanel != null) { _campaignPanel.OnSelectMission(tileIndex + 1); } } } } } }
void OnSelect(bool selected) { if (Locked) { return; } RaycastHit hit; UICamera.Raycast(Input.mousePosition, out hit); if (null == hit.transform || hit.transform.GetComponent <UIScrollView>() == null) { return; } if (null != Owner && null != Owner.OldSelectedItem) { Owner.OldSelectedItem.Selected = false; } Owner.OldSelectedItem = this; if (null != SelectedItem) { SelectedItem.gameObject.SetActive(selected); } Selected = selected; if (onSelect != null) { onSelect(this, selected); } }
private void OnDrag(DragGesture gesture) { if (Pinch) { return; } switch (gesture.Phase) { case ContinuousGesturePhase.Started: if (UICamera.Raycast(gesture.StartPosition) == false) { m_Drag = gesture; Drag = true; DragDelta = gesture.DeltaMove; } break; case ContinuousGesturePhase.Updated: if (Drag && gesture.ClusterId == m_Drag.ClusterId) { DragDelta = gesture.DeltaMove; } break; case ContinuousGesturePhase.Ended: case ContinuousGesturePhase.None: if (m_Drag != null && m_Drag.ClusterId == gesture.ClusterId) { m_Drag = null; Drag = false; DragDelta = Vector2.zero; } break; } }
private void OnFingerUp(FingerUpEvent eventData) { if (Camera.main == null) { return; } if (Drag || Pinch) { return; } if (UICamera.Raycast(eventData.Position)) { return; } if (UICamera.Raycast(eventData.Finger.Position)) { return; } if (UICamera.Raycast(eventData.Finger.StartPosition)) { return; } RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(eventData.Position); if (Physics.Raycast(ray, out hit, 1000, 1 << GTLayer.LAYER_DEFAULT) && Application.isEditor) { GTNetworkSend.Instance.TryPursue(hit.point); } }
bool CheckInputNGUI() { return(false); // RaycastHit hit = new RaycastHit(); return(UICamera.Raycast(Input.mousePosition)); // , out hit) ; }
/// <summary> /// 使用的时候parents一定要用成员变量,不要临时声明,造成无所谓的GC者,拖出去爆菊1个小时 /// </summary> /// <param name="button">鼠标的左键右键</param> /// <param name="parents">在NGUI层上需要关闭点击容器的父节点,比如一个grid里面要屏蔽掉 /// 所有item的点击的话,请使用把grid的transform设置在parent中 /// </param> /// <returns></returns> public static bool GetMouseButtonDown(int button, List <Transform> parents) { if (Input.GetMouseButtonDown(button)) { if (!UICamera.isOverUI) { return(true); } if (Input.touchCount > 0 && UICamera.Raycast(Input.GetTouch(0).position)) { return(false); } Ray ray = UICamera.mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity, 1 << GameConst.Layer.UI); for (int i = 0; i < hits.Length; i++) { if (CheckHasParent(hits[i].collider.transform, parents)) { return(false); } } return(true); } return(false); }
private bool _UpdateSelectFromTouch() { if (!Input.GetMouseButton((0))) { return(true); } var touchPosition = Input.mousePosition; if (UICamera.Raycast(touchPosition)) { return(true); } var ray = CameraHelper.Middle.ScreenPointToRay(touchPosition); RaycastHit hitInfo; var fish = (from r in Physics.RaycastAll(ray) let collider = r.collider.GetComponent <FishCollider>() where collider != null && collider.Id != 0 select new { id = collider.Id, FishType = collider.FishType }).FirstOrDefault(); if (fish != null && fish.id != 0) { _Selected = fish.id; _FishType = fish.FishType; } if (TouchFireEvent != null) { TouchFireEvent(); } return(false); }
/* 场景中可交互物体射线检测 */ private void InteractiveCheck() { if (isPlayingAnime || isFacing2Obj) { return; } RaycastHit hit; #if UNITY_EDITOR if (UICamera.hoveredObject && UICamera.hoveredObject.GetComponent <Collider>() == null && Physics.Raycast(MainSceneCamera.ScreenPointToRay(Input.mousePosition), out hit)) { if (hit.collider.tag == "Clickable") { HandleOnRaycastHit(hit); } } #endif #if UNITY_ANDROID if (Input.touchCount > 0 && !UICamera.Raycast(Input.GetTouch(0).position) && Physics.Raycast(MainSceneCamera.ScreenPointToRay(Input.GetTouch(0).position), out hit)) { if (hit.collider.tag == "Clickable") { HandleOnRaycastHit(hit); } } #endif }
void CameraRotation() { if (transform.rotation != TargetRotation) { transform.rotation = TargetRotation; } if (UIInput.selection == null && (Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.E))) { if (Input.GetKey(KeyCode.Q)) { Gap.y -= 0.5f * RotationSpeed; } else { Gap.y += 0.5f * RotationSpeed; } TargetRotation = Quaternion.Euler(Gap); // 카메라벡터 객체에 Axis객체의 x,z회전 값을 제외한 y값만을 넘긴다. Quaternion q = TargetRotation; q.x = q.z = 0; CameraVector.transform.rotation = q; } if (Input.GetMouseButton(0) == false && Input.GetMouseButton(1) == false) { First_Click_is_UI = false; } if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { if (UICamera.Raycast(Input.mousePosition)) { First_Click_is_UI = true; } LastFrameMouse = Input.mousePosition; } if (First_Click_is_UI == false && (Input.GetMouseButton(0) || Input.GetMouseButton(1))) { Vector3 axis = Input.mousePosition - LastFrameMouse; axis /= 10; LastFrameMouse = Input.mousePosition; // 값을 축적. Gap.x += axis.y * RotationSpeed * -1; Gap.y += axis.x * RotationSpeed; // 카메라 회전범위 제한. Gap.x = Mathf.Clamp(Gap.x, 3f, 85f); // 회전 값을 변수에 저장. TargetRotation = Quaternion.Euler(Gap); // 카메라벡터 객체에 Axis객체의 x,z회전 값을 제외한 y값만을 넘긴다. Quaternion q = TargetRotation; q.x = q.z = 0; CameraVector.transform.rotation = q; //Cursor.lockState = CursorLockMode.Locked; } }
void Update() { if (bPress) { if (UICamera.Raycast(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0))) { Eventer.Fire("BatchSelectCardHover", new object[] { UICamera.lastHit.collider.gameObject }); } } }
protected override bool HitTest(Vector2 position) { #if NGUI if (UICamera.Raycast(position)) { return(false); } #endif return(cl.Raycast(activeCamera.ScreenPointToRay(position), out lastRaycastHit, OnlineMapsUtils.maxRaycastDistance)); }
void Update() { RaycastHit hit; UIButtonController buttonController = null; #if UNITY_EDITOR for (int i = 0; i < 3; ++i) { if (Input.GetMouseButtonDown(i)) { if (UICamera.Raycast(Input.mousePosition, out hit)) { buttonController = hit.collider.GetComponent <UIButtonController>(); if (buttonController != null) { buttonController.Press(); } } } else if (Input.GetMouseButton(i)) { if (UICamera.Raycast(Input.mousePosition, out hit)) { buttonController = hit.collider.GetComponent <UIButtonController>(); if (buttonController != null) { buttonController.Holding(); } } } } #else foreach (Touch touch in Input.touches) { if (UICamera.Raycast(touch.position, out hit)) { buttonController = hit.collider.GetComponent <UIButtonController>(); if (buttonController != null) { switch (touch.phase) { case TouchPhase.Began: buttonController.Press(); break; case TouchPhase.Moved: case TouchPhase.Stationary: buttonController.Holding(); break; } } } } #endif }
static int Raycast(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); Vector3 arg0 = LuaScriptMgr.GetVector3(L, 1); RaycastHit arg1; bool o = UICamera.Raycast(arg0, out arg1); LuaScriptMgr.Push(L, o); LuaScriptMgr.Push(L, arg1); return(2); }
private bool CurrentTouchOverUI() { var t = new UICamera.MouseOrTouch(); t.pos = lasttouch; UICamera.Raycast(t); if (t.current != null && t.current != UICamera.fallThrough && NGUITools.FindInParents <UIRoot>(t.current) != null) { return(true); } return(false); }
public static bool GetMouseButtonUp(int button) { if (UICamera.isOverUI) { return(false); } if (Input.touchCount > 0 && UICamera.Raycast(Input.GetTouch(0).position)) { return(false); } return(Input.GetMouseButtonUp(button)); }
void DisCamera() { if (UICamera.Raycast(Input.mousePosition) == false) { Distance += Input.GetAxis("Mouse ScrollWheel") * ZoomSpeed * -1; } Distance = Mathf.Clamp(Distance, 5f, 30f); AxisVec = transform.forward * -1; AxisVec *= Distance; MainCamera.position = transform.position + AxisVec; }
/// <summary> /// 判断鼠标是否在有包围盒的UI上 /// </summary> public static bool isMouseOverNGUI() { Vector3 mousePostion = Input.mousePosition; if (UICamera.Raycast(mousePostion)) { if (UICamera.lastHit.collider != null) { return(true); } } return(false); }
protected void TouchPoint() { if (Input.touchCount == 0) { return; } if (Input.touchCount > 1) { if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved) //这个手势是缩放手势 { return; } } for (int i = 0; i < Input.touchCount; ++i) { Touch input = Input.GetTouch(i); bool unpressed = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended); if (!unpressed)//只处理触摸弹起的事件 { continue; } Vector3 pos = new Vector3(input.position.x, input.position.y, 0); if (!UICamera.Raycast(pos))//检测是否按到了UI控件 { continue; } Ray _ray = GameCenter.cameraMng.uiCamera.ScreenPointToRay(pos); RaycastHit _hit; if (Physics.Raycast(_ray, out _hit, Mathf.Infinity, LayerMng.uiMask)) { clickPoint.transform.position = _hit.point; Vector3 diffPoint = clickPoint.localPosition; GameCenter.curMainPlayer.CancelCommands(); GameCenter.curMainPlayer.GoTraceTarget(GameCenter.mainPlayerMng.MainPlayerInfo.SceneID, (int)(diffPoint.x / posXRate), (int)(diffPoint.y / posYRate)); //zsy InitFlyPoint(new Vector3((int)(diffPoint.x / posXRate), (int)(diffPoint.y / posYRate))); //Command_MoveTo moveto = new Command_MoveTo(); //moveto.destPos = ActorMoveFSM.LineCast(new Vector3(diffPoint.x / posXRate, 0, diffPoint.y / posYRate), true); //moveto.maxDistance = 0f; //GameCenter.curMainPlayer.commandMng.PushCommand(moveto); //GameCenter.taskMng.CurTargetPoint = moveto.destPos;//显示出寻路中。。 //GameCenter.uIMng.GenGUI(GUIType.TASK_FINDING, true); } } }
// 判断是否点击在ngui控件上. public static bool IsMouseOverUI() { Vector3 mousePosition = Input.mousePosition; GameObject hoverObj = UICamera.Raycast(mousePosition) ? UICamera.lastHit.collider.gameObject : null; if (hoverObj != null) { return(true); } else { return(false); } }
//void Callback(bool isUpdate) //{ // Debug.LogWarning("isUpdate:" + isUpdate); // if (isUpdate) // { // GameResManager.Singleton.DownloadUpdatePackage(); // } //} bool ShouldProcessTouch(int fingerIndex, Vector2 position) { return(!UICamera.Raycast(position)); //return true; //Ray ray = UICamera.currentCamera.ScreenPointToRay(position); //RaycastHit hitInfo; //bool touchUI = Physics.Raycast(ray, out hitInfo ,float.PositiveInfinity,LayerMask.NameToLayer("UIRoot")); //if (touchUI) //{ // Debug.LogWarning("Touch UI:" + hitInfo.collider.gameObject.name); //} //return !touchUI; }
public void ProcessTouches() { for (int i = 0; i < Input.touchCount; i++) { Touch touch = Input.GetTouch(i); UICamera.currentTouchID = ((!this.allowMultiTouch) ? 1 : touch.fingerId); UICamera.currentTouch = UICamera.GetTouch(UICamera.currentTouchID); bool flag = touch.phase == TouchPhase.Began || UICamera.currentTouch.touchBegan; bool flag2 = touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended; UICamera.currentTouch.touchBegan = false; if (flag) { UICamera.currentTouch.delta = Vectors.v2zero; } else { UICamera.currentTouch.delta = touch.position - UICamera.currentTouch.pos; } UICamera.currentTouch.pos = touch.position; UICamera.hoveredObject = ((!UICamera.Raycast(UICamera.currentTouch.pos, ref UICamera.lastHit)) ? UICamera.fallThrough : UICamera.lastHit.collider.gameObject); if (UICamera.hoveredObject == null) { UICamera.hoveredObject = UICamera.genericEventHandler; } UICamera.currentTouch.current = UICamera.hoveredObject; UICamera.lastTouchPosition = UICamera.currentTouch.pos; if (flag) { UICamera.currentTouch.pressedCam = UICamera.currentCamera; } else if (UICamera.currentTouch.pressed != null) { UICamera.currentCamera = UICamera.currentTouch.pressedCam; } if (touch.tapCount > 1) { UICamera.currentTouch.clickTime = Time.realtimeSinceStartup; } this.ProcessTouch(flag, flag2); if (flag2) { UICamera.RemoveTouch(UICamera.currentTouchID); } UICamera.currentTouch = null; if (!this.allowMultiTouch) { break; } } }
private void FixedUpdate() { if (this.useMouse && Application.isPlaying && this.handlesEvents) { UICamera.hoveredObject = ((!UICamera.Raycast(Input.mousePosition, ref UICamera.lastHit)) ? UICamera.fallThrough : UICamera.lastHit.collider.gameObject); if (UICamera.hoveredObject == null) { UICamera.hoveredObject = UICamera.genericEventHandler; } for (int i = 0; i < 3; i++) { UICamera.mMouse[i].current = UICamera.hoveredObject; } } }
//防UI穿透 private bool HitTestUI() { /********以下两种判读都可以*******/ //如果在主Camer上也挂一个UICamera,这两种判读会一直返回真(为什么呢???) //如果有碰到NGUI对象,返回真 if (UICamera.hoveredObject != null) { return(true); } print("UICamera.Raycast___" + UICamera.Raycast(Input.mousePosition)); //如果从UICamer到当前鼠标位置的射线碰到了NGUI对象,返回真 //if(UICamera.Raycast(Input.mousePosition)) { return true; } return(false); }
void Update() { Process(); if (targetCharacter_ != null) { // RaycastHit besthitinfo; // if (UICamera.Raycast(Input.mousePosition, out besthitinfo) == false) if (UICamera.Raycast(Input.mousePosition) == false) { if (Input.GetButton("Fire1") == true) { PlayerController pc = targetCharacter_.GetComponent <PlayerController>(); pc.enabled = true; pc.Click2Go(); } } } }
public static PointData creatPointData(Vector3 pos, LayerMask Hitlayer) { if (UICamera.Raycast(pos) || PlayerInputListener.mainCamera == null)//检测是否按到了UI控件 { return(null); } Ray _ray = PlayerInputListener.mainCamera.ScreenPointToRay(pos); RaycastHit _hit; if (Physics.Raycast(_ray, out _hit, Mathf.Infinity, Hitlayer.value)) { PointData d = new PointData(); d.pos = pos; d.hit = _hit; return(d); } return(null); }
void FingerGestures_OnFingerDown(FingerGestures.Finger finger) { int fingerIndex = finger.Index; Vector2 fingerPos = finger.Position; if (UICamera.Raycast(fingerPos)) { fingerMap.Remove(fingerIndex); //even though this should not happen. Just put here in case.. //fingerMap[fingerIndex] = null; return; } fingerMap[fingerIndex] = finger; fingerPosMap[fingerIndex] = fingerPos; // Debug.LogError("FingerGestures_OnFingerDown " + fingerIndex + " " + fingerPos + " " + Time.frameCount); //check whether this is joy stick. If joy stick mode, this finger will be ignored. if (CheckWhetherJoyStickFinger(fingerIndex, fingerPos)) { if (JoyStickControl.TheMode == JoyStickMode.None) { //Debug.LogError("joy stick pos " + fingerPos); JoyStickControl.TheMode = JoyStickMode.JoyStick; JoyStickFinger = fingerIndex; } } else { if (JoyStickControl.TheMode == JoyStickMode.None) { JoyStickControl.TheMode = JoyStickMode.DragControl; } if (lastFingerIndex == -1) { lastFingerIndex = fingerIndex; } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (UICamera.Raycast(Input.mousePosition) == false) { CreateTempLine(Camera.main.ScreenToWorldPoint(Input.mousePosition)); m_IsDrawing = true; } } if (m_IsDrawing) { CurSlideTime -= Time.deltaTime; SlideChangeEvent.Invoke(CurSlideTime / _MaxSlideTime); m_Line.EndPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (m_Line.EndPosition.y < -160 || _CurSlideTime <= 0.0f) { m_IsDrawing = false; Destroy(m_Line.gameObject); GameObject.Find("Player").GetComponent <PlayerControl>().SlideEnd(); } } if (Input.GetMouseButtonUp(0) && m_IsDrawing) { m_IsDrawing = false; m_Line.DrawEnd(); } if (!m_IsDrawing) { SlideChangeEvent.Invoke(CurSlideTime / _MaxSlideTime); } }
public bool rayCast(Camera cam, GameObject go) { if (cam == null) { return(false); } if (UICamera.Raycast(cam.WorldToScreenPoint(go.transform.position)) == false) { return(false); } if (UICamera.hoveredObject == null) { return(false); } #if UNITY_EDITOR Debug.Log(UICamera.hoveredObject); #endif return(UICamera.hoveredObject == go); }
private void UpdateIdle() { _firingSkill = null; if (_game.state != BattleGame.STATE.BATTLE) { return; } if (!_game.gameSkill.IsSelecting()) { return; } if (_mouseStatus.GetMouseJustDown() && !UICamera.Raycast(Input.mousePosition)) { _state = STATE.DETECT; _firingSkill = _game.gameSkill.GetCurrentSelectSkill(); return; } }
private void OnPinch(PinchGesture gesture) { for (int i = 0; i < gesture.Fingers.Count; i++) { if (UICamera.Raycast(gesture.Fingers[i].StartPosition)) { Pinch = false; PinchDelta = 0; return; } } switch (gesture.Phase) { case ContinuousGesturePhase.Started: { Pinch = true; PinchDelta = gesture.Delta; } break; case ContinuousGesturePhase.Updated: if (Pinch) { PinchDelta = gesture.Delta; } break; case ContinuousGesturePhase.None: case ContinuousGesturePhase.Ended: { Pinch = false; PinchDelta = 0; } break; } }