/// <summary> /// 开枪的时候 /// </summary> /// <param name="msg">MsgPlayerWeaponShot</param> private void OnWeaponFire(MsgPlayerWeaponShot msg) { Vector2 localPoint; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_PointBox, msg.screenPoint, m_Camera, out localPoint)) { RectTransform point = null; for (int i = 0; i < m_PointBox.childCount; i++) { RectTransform current = m_PointBox.GetChild(i).GetComponent<RectTransform>(); if (!current.gameObject.activeSelf) { point = current; break; } } if (!point) { point = Object.Instantiate(m_PointTemplate, m_PointBox); } point.anchoredPosition = localPoint; point.gameObject.SetActive(true); m_PointToDeathTime.Add(point, Time.time + 0.1f); m_lastShotTime = Time.time; if (m_Point) m_Point.GetComponent<Image>().enabled = false; } }
/// <summary> /// 把这一次射击弹道对应的屏幕坐标传给UI /// </summary> private void SendScreenPositionOfShotToUI(Vector3 shootingDirection) { if (m_WeaponItem != m_PlayerSkillProxy.GetCurrentWeapon()) { return; } Camera cam = CameraManager.GetInstance()?.GetMainCamereComponent()?.GetCamera(); if (cam != null) { Vector3 screenPos = cam.WorldToScreenPoint(cam.transform.position + shootingDirection); MsgPlayerWeaponShot weaponShot = new MsgPlayerWeaponShot(); weaponShot.screenPoint = screenPos; GameFacade.Instance.SendNotification(NotificationName.PlayerWeaponShot, weaponShot); } }