void MoveHandler(Peer peer, byte[] data) { Vector2Obj vector2Obj = MessagePackSerializer.Deserialize <Vector2Obj>(data); object args = new Vector2(vector2Obj.X, vector2Obj.Y); Unit unit = Root.GetChild <WorldEntity>().GetUnit(peers[peer.ID].UnitID); if (unit != null && unit.GetCombat(CombatAttribute.Move).IsExecutable(args)) { unit.Cancel(CombatAttribute.Ability); unit.Execute(CombatAttribute.Move, args); } }
void Update() { if (playerUnitInstance != null) { Team playerTeam = playerUnitInstance.GetComponent <Unit>().Info.GetTeam(); float playerCurHP = playerUnitInstance.GetComponent <Unit>().Info.GetCurHP(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); int unitLayerMask = LayerMask.GetMask("Unit"); int groundLayerMask = LayerMask.GetMask("Ground"); RaycastHit[] hits; hits = Physics.RaycastAll(ray, 1000f, unitLayerMask); Unit attackUnit = null; for (int i = 0; i < hits.Length; i++) { RaycastHit hit = hits[i]; Unit unit = hit.transform.GetComponentsInParent <Unit>()[0]; Team team = unit.Info.GetTeam(); float curHP = unit.Info.GetCurHP(); if (team != playerTeam && curHP > 0) { attackUnit = unit; break; } } RaycastHit hitInfo; Vector2 movePosition = Vector2.zero; if (Physics.Raycast(ray, out hitInfo, 10000f, groundLayerMask)) { movePosition = new Vector2(hitInfo.point.x, hitInfo.point.z); } if (Input.GetMouseButtonDown(1)) { if (attackUnit != null) { network.Send(MessageType.Attack, MessagePackSerializer.Serialize(attackUnit.Info.GetUnitID()), ENet.PacketFlags.Reliable); GameObject groundPointer = Instantiate(groundPointerPrefab); groundPointer.GetComponent <GroundPointer>().Init(attackUnit.transform); } else { Vector2Obj vector2Obj = new Vector2Obj() { X = movePosition.x, Y = movePosition.y }; network.Send(MessageType.Move, MessagePackSerializer.Serialize(vector2Obj), ENet.PacketFlags.Reliable); GameObject groundPointer = Instantiate(groundPointerPrefab); groundPointer.GetComponent <GroundPointer>().Init(new Vector2(hitInfo.point.x, hitInfo.point.z)); } } if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { Cursor.SetCursor(null, hotSpot, cursorMode); } else if (skillState != SkillState.None) { Cursor.SetCursor(castTexture, hotSpot, cursorMode); } else if (attackUnit != null) { Cursor.SetCursor(attackTexture, hotSpot, cursorMode); } else { Cursor.SetCursor(moveTexture, hotSpot, cursorMode); } if (Input.GetKeyDown(KeyCode.B)) { network.Send(MessageType.Recall, new byte[0], ENet.PacketFlags.Reliable); } for (KeyCode keyCode = KeyCode.Alpha1; keyCode < KeyCode.Alpha7; keyCode++) { if (Input.GetKeyDown(keyCode)) { IconPressed(keyCode); } } if (Input.GetKeyDown(KeyCode.Q)) { IconPressed(KeyCode.Q); } else if (Input.GetKeyDown(KeyCode.W)) { IconPressed(KeyCode.W); } else if (Input.GetKeyDown(KeyCode.E)) { IconPressed(KeyCode.E); } else if (Input.GetKeyDown(KeyCode.R)) { IconPressed(KeyCode.R); } } }