NewN_UAVPlane/Assets/Zion/Scripts/Adam/WRJManager.cs

59 lines
1.9 KiB
C#

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<WRJController> wRJControllers = new List<WRJController>();
public WRJController currentWRJ;
public RectTransform wrjMenuSetPanel;
public RectTransform canvasRect;
private void Start()
{
wrjMenuSetPanel.gameObject.SetActive(false);
}
private void Update()
{
if (Input.GetMouseButtonDown(1))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, 1000, 1 << 9))
{
Debug.Log("daadad");
currentWRJ = hitInfo.collider.GetComponent<WRJController>();
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;
}
}
}