using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Assets.Zion.Scripts.Adam { public class WRJManager : MonoBehaviour { public RectTransform wrjMenuSetPanel; public RectTransform canvasRect; private void Start() { wrjMenuSetPanel.gameObject.SetActive(false); } private void Update() { if (UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) == "0" && Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject()) return; if (FormationManager.Instance.isStartFormation) return; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 1000)) { if (CheckGuiRaycastObjects()) return; EquipmentCommon ec = hitInfo.collider.GetComponent(); if (ec != null && ec.isPlayer) { if (hitInfo.collider.tag == "WRJ") { wrjMenuSetPanel.localScale = Vector3.one; Vector3 posItem = GetScreenPosition(hitInfo.collider.gameObject); wrjMenuSetPanel.gameObject.SetActive(true); wrjMenuSetPanel.anchoredPosition = new Vector3(posItem.x + 100f, posItem.y, posItem.z); } else { GameManager.Instance.GetWRJParameter(); wrjMenuSetPanel.localScale = Vector3.zero; } } else { GameManager.Instance.GetWRJParameter(); wrjMenuSetPanel.localScale = Vector3.zero; } } else { GameManager.Instance.GetWRJParameter(); wrjMenuSetPanel.localScale = Vector3.zero; } } } public EventSystem eventsystem; public GraphicRaycaster RaycastInCanvas; /// /// UI 防穿透 /// /// public bool CheckGuiRaycastObjects() { PointerEventData eventData = new PointerEventData(eventsystem); eventData.pressPosition = Input.mousePosition; eventData.position = Input.mousePosition; List list = new List(); RaycastInCanvas.Raycast(eventData, list); return list.Count > 0; } public Vector3 GetScreenPosition(GameObject target) { float width = canvasRect.sizeDelta.x; float height = canvasRect.sizeDelta.y; Vector3 pos = Camera.main.WorldToScreenPoint(target.transform.position); pos.x *= width / Screen.width; pos.y *= height / Screen.height; pos.x -= width * 0.5f; pos.y -= height * 0.5f; return pos; } } }