private void OnNotiKeyDown(Notification noti) { GameKey.EKey key = (GameKey.EKey)noti.Data; // GameKey.EKey modifier = (GameKey.EKey)noti.ExtraData; if (key == GameKey.EKey.K_A)//在老虎机的周围,按键A,生成道具(没有扣除金币数),没有调用接口 { actor = GameObject.Find("actor").transform; //playerPosition = PlayerControl.transform.position; //人物Position playerPosition = actor.position; GpsMapCell player = Document.Instance.Map.GetCell(playerPosition); int x1 = player.Row - tiger1.Row; //行 int y1 = player.Col - tiger1.Col; //列 int x2 = player.Row - tiger2.Row; int y2 = player.Col - tiger2.Col; if (y1 < 3 && y1 > -3 && x1 < 1 && x1 > -1) { AudioSource.PlayClipAtPoint(get, TIGER_MACHINE1.transform.position); //声音 item = Document.Instance.OpenTigerMachine(Document.Instance.Getcode("T01")); //T01老虎机编号,调用接口 } if (y2 < 3 && y2 > -3 && x2 < 1 && x2 > -1) { AudioSource.PlayClipAtPoint(get, TIGER_MACHINE2.transform.position); //声音 Document.Instance.OpenTigerMachine(Document.Instance.Getcode("T04")); //T01老虎机编号,调用接口 } } }
private void OnNotiKeyDown(Notification noti) { GameKey.EKey key = (GameKey.EKey)noti.Data; GameKey.EKey modifier = (GameKey.EKey)noti.ExtraData; Cell newCell = new Cell(this.cell); int multiple = GameKey.IsControlKey(modifier) ? 3 : 1; switch (key) { case GameKey.EKey.K_UpArrow: newCell.Row -= multiple; break; case GameKey.EKey.K_DownArrow: newCell.Row += multiple; break; case GameKey.EKey.K_LeftArrow: { leftorright = false; newCell.Col--; } break; case GameKey.EKey.K_RightArrow: { leftorright = true; newCell.Col++; } break; case GameKey.EKey.K_Space: { newCell.Row--; } break; default: return; } GpsMapCell gnc = Document.Instance.Map.GetCell(this.cell.Row, this.cell.Col); GpsMapCell gpc = Document.Instance.Map.GetCell(newCell.Row, newCell.Col); if (gpc != null) { if (gpc.Type == GpsMapCell.EType.EN_ROPE) { MoveTo(newCell); } if (key != GameKey.EKey.K_Space) { if (gpc.Type == GpsMapCell.EType.EN_ROAD || gpc.Type == GpsMapCell.EType.EN_CROSS) { MoveTo(newCell); //行走动画 role.SetBool("walking", true); /*if (key == GameKey.EKey.K_UpArrow || key == GameKey.EKey.K_DownArrow) * { * role.SetBool("walking", false); * role.SetBool("climbing", true); * }*/ } //攀爬 if (gpc.Type == GpsMapCell.EType.EN_LADDER) { MoveTo(newCell); role.SetBool("climbing", true); /*if(key == GameKey.EKey.K_Space && gpc.Type == GpsMapCell.EType.EN_SELECTION) * { * MoveTo(newCell); * temp_actor.Row = newCell.Row; * temp_actor.Col = newCell.Col; * this.falling = true; * }*/ } if (gpc.Type == GpsMapCell.EType.EN_SELECTION && key != GameKey.EKey.K_UpArrow && key != GameKey.EKey.K_DownArrow) { if (gnc.Type != GpsMapCell.EType.EN_ROPE && gnc.Type != GpsMapCell.EType.EN_LADDER) { MoveTo(newCell); temp_actor.Row = newCell.Row; temp_actor.Col = newCell.Col; // this.falling = true; } } } // 处理跳跃 if (gpc.Type == GpsMapCell.EType.EN_SELECTION) { if (gnc.Type == GpsMapCell.EType.EN_ROAD || gnc.Type == GpsMapCell.EType.EN_CROSS /*&& !this.falling*/) { if (key == GameKey.EKey.K_Space) //|| key == GameKey.EKey.K_RightArrow || key == GameKey.EKey.K_LeftArrow) { MoveTo(newCell); temp_actor.Row = newCell.Row; temp_actor.Col = newCell.Col; this.falling = false; this.jump = true; //跳跃动画判断 role.SetBool("jumping", true); } } } } }
private void DealWithInput() { if (this.DisableInput) { return; } Notification noti = new Notification(this, Notification.NOTI_NULL); GameKey gk = new GameKey(); GameKey.EKey key = gk.GetKeyUp(); if (key != GameKey.EKey.K_NULL) { noti.Name = Notification.NOTI_KEY_UP; noti.Data = key; XxdwDebugger.Log(noti.Name + ":" + gk.GetKeyString(key)); this.SendNotification(noti); } else if ((key = gk.GetKeyDown()) != GameKey.EKey.K_NULL) { noti.Name = Notification.NOTI_KEY_DOWN; noti.Data = key; noti.ExtraData = gk.GetModifier(); XxdwDebugger.Log(noti.Name + ":" + gk.GetKeyString(key) + "," + gk.GetKeyString(gk.GetModifier())); this.SendNotification(noti); } if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { int touchCount = 0; int touch1 = 0, touch2 = 0; for (int i = 0; i < Input.touches.Length; i++) { if (Input.touches[i].phase != TouchPhase.Canceled) { if (touchCount == 0) { touch1 = i; touchCount++; } else { touch2 = i; touchCount++; break; } } } if (touchCount == 0) { return; } Vector3 pos = new Vector3(Input.touches[touch1].position.x, Input.touches[touch1].position.y, 0); if (touchCount == 2 && Input.touches[touch1].phase == TouchPhase.Moved && Input.touches[touch2].phase == TouchPhase.Moved) { XxdwDebugger.Log("TouchPhase.SizeChanged"); float distNow = Vector2.Distance(Input.touches[touch1].position, Input.touches[touch2].position); Vector2 pre1 = Input.touches[touch1].position - Input.touches[touch1].deltaPosition; Vector2 pre2 = Input.touches[touch2].position - Input.touches[touch2].deltaPosition; float distPre = Vector2.Distance(pre1, pre2); if (distNow > distPre) { XxdwDebugger.Log("Touch Zoom in"); noti.Name = Notification.NOTI_ZOOM_IN; } else { XxdwDebugger.Log("Touch Zoom out"); noti.Name = Notification.NOTI_ZOOM_OUT; } noti.Data = Math.Abs(distNow - distPre); if ((float)noti.Data > Parameters.MIN_SIZE_TRIGGER_ZOOM) { this.SendNotification(noti); } //XxdwDebugger.DisplayMessage("dist:" + Math.Abs(distNow - distPre)); } else { switch (Input.touches[touch1].phase) { case TouchPhase.Began: XxdwDebugger.Log("TouchPhase.Began"); this.touchDownTime = Time.time; this.posPrevious = pos; noti.Name = Notification.NOTI_TOUCH_DOWN; noti.Data = pos; this.SendNotification(noti); break; case TouchPhase.Ended: if (PeekDisableTouchUp() == 0) { XxdwDebugger.Log("TouchPhase.Ended."); noti.Name = Notification.NOTI_TOUCH_UP; noti.Data = pos; this.SendNotification(noti); } break; case TouchPhase.Moved: if (Input.touches[touch1].deltaPosition.sqrMagnitude > Parameters.MIN_COORDINATE_OFFSET) { XxdwDebugger.Log("TouchPhase.Moved"); // 拖动 noti.Name = Notification.NOTI_DRAG; noti.Data = pos; noti.ExtraData = this.posPrevious; this.touchDownTime = Time.time; this.posPrevious = pos; this.SendNotification(noti); } else { goto STATIONARY; } break; case TouchPhase.Stationary: STATIONARY: if (Time.time - touchDownTime > Parameters.LONG_TOUCH_INTERVAL) { XxdwDebugger.Log("MouseButtonUp Long."); this.touchDownTime = Time.time; noti.Name = Notification.NOTI_LONG_TOUCH_UP; noti.Data = Input.mousePosition; this.SendNotification(noti); } break; } } } else if (Application.platform <= RuntimePlatform.WindowsEditor) { // 按下鼠标 if (Input.GetMouseButtonDown((int)Parameters.MouseTypeEnum.LEFT)) { XxdwDebugger.Log("MouseButtonDown"); this.touchDownTime = Time.time; this.posPrevious.Set(Input.mousePosition.x, Input.mousePosition.y, 0); noti.Name = Notification.NOTI_TOUCH_DOWN; noti.Data = Input.mousePosition; this.touched = true; this.SendNotification(noti); } // 松开鼠标 else if (Input.GetMouseButtonUp((int)Parameters.MouseTypeEnum.LEFT)) { XxdwDebugger.Log("MouseButtonUp"); noti.Name = Notification.NOTI_TOUCH_UP; noti.Data = Input.mousePosition; this.touched = false; this.SendNotification(noti); } // 松开鼠标右键 else if (Input.GetMouseButtonUp((int)Parameters.MouseTypeEnum.RIGHT)) { XxdwDebugger.Log("MouseButtonUp"); noti.Name = Notification.NOTI_RIGHT_CLICK; noti.Data = Input.mousePosition; this.SendNotification(noti); } else if (this.touched) { Vector3 pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0); Vector2 diff = new Vector2(pos.x - this.posPrevious.x, pos.y - this.posPrevious.y); if (diff.sqrMagnitude > Parameters.MIN_COORDINATE_OFFSET) { // 拖动 noti.Name = Notification.NOTI_DRAG; noti.Data = Input.mousePosition; noti.ExtraData = this.posPrevious; this.touchDownTime = Time.time; this.posPrevious = pos; this.SendNotification(noti); } else if (Time.time - touchDownTime > Parameters.LONG_TOUCH_INTERVAL) { XxdwDebugger.Log("MouseButtonUp Long."); noti.Name = Notification.NOTI_LONG_TOUCH_UP; noti.Data = Input.mousePosition; this.touched = false; this.SendNotification(noti); } } else { // 鼠标滚轮拉近拉远 float mouseScroll = Input.GetAxis("Mouse ScrollWheel"); if (Mathf.Abs(mouseScroll) > Parameters.MIN_COORDINATE_OFFSET) { if (mouseScroll > 0) { XxdwDebugger.Log("Mouse Scroll Zoom in"); noti.Name = Notification.NOTI_ZOOM_IN; noti.Data = mouseScroll; } else { XxdwDebugger.Log("Mouse Scroll Zoom out"); noti.Name = Notification.NOTI_ZOOM_OUT; noti.Data = -mouseScroll; } this.SendNotification(noti); } } } } // DealWithInput()