using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace Assets.Zion.Scripts.Adam { public class WRJManager : MonoBehaviour { public List wRJControllers = new List(); public WRJController currentWRJ; 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(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 1000)) { if (hitInfo.collider.tag == "WRJ") { Debug.Log("daadad"); currentWRJ = hitInfo.collider.GetComponent(); if (!wRJControllers.Contains(currentWRJ)) wRJControllers.Add(currentWRJ); wrjMenuSetPanel.gameObject.SetActive(true); Vector3 posItem = GetScreenPosition(hitInfo.collider.gameObject); wrjMenuSetPanel.anchoredPosition = new Vector3(posItem.x + 100f, posItem.y, posItem.z); } } else { wrjMenuSetPanel.gameObject.SetActive(false); } } } 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; } } }