using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class FirstPanel : MonoBehaviour { /// /// 检测的图片 /// public List checkImages; /// /// 选中的图片 /// public List showImages; /// /// 服务器IP /// public string serverIP; /// /// 前端调用初始化传IP /// /// public void InitUnity(string serverIP) { this.serverIP= serverIP; //CallGet(""/*)*/ } private void Update() { int index = 0; foreach (Image image in checkImages) { if (IsTrig(image)) { //触发此市 Debug.Log(image.name); Chose(index); return; } index++; } Debug.Log("未触发"); Chose(-1); } /// /// 是否触发区域 /// /// /// private bool IsTrig(Image image) { //检测鼠标 RectTransformUtility.ScreenPointToLocalPointInRectangle(image.rectTransform, Input.mousePosition, null, out Vector2 localPos); Vector2 bil = new Vector2((localPos.x + image.rectTransform.rect.width / 2f) / image.rectTransform.rect.width, (localPos.y + image.rectTransform.rect.height / 2f) / image.rectTransform.rect.height); Color pixelColor = image.sprite.texture.GetPixelBilinear(bil.x, bil.y); //Debug.Log("鼠标点:"+Input.mousePosition + " -> 纹理点:" + localPos + " -> 纹理点序列化:"+ bil + " -> 透明度值:"+ pixelColor.a); if (pixelColor.a == 1) { return true; } else { return false; } } /// /// 上一个显示的 /// GameObject lastShow; private void Chose(int index) { if(index==-1) { if (lastShow != null) { lastShow.gameObject.SetActive(false); } } else { if (lastShow != null) { lastShow.gameObject.SetActive(false); } showImages[index].gameObject.SetActive(true); lastShow = showImages[index].gameObject; } } public void CallGet(string url) { UnityWebRequest request = UnityWebRequest.Get(url); } }