174 lines
4.4 KiB
C#
174 lines
4.4 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
using UnityEngine.Networking;
|
||
using UnityEngine.UI;
|
||
|
||
public class FirstPanel : MonoBehaviour
|
||
{
|
||
public static FirstPanel instance;
|
||
/// <summary>
|
||
/// 检测的图片
|
||
/// </summary>
|
||
public List<Image> checkImages;
|
||
/// <summary>
|
||
/// 选中的图片
|
||
/// </summary>
|
||
public List<GameObject> showImages;
|
||
/// <summary>
|
||
/// 省级
|
||
/// </summary>
|
||
public GameObject sheng_Panel;
|
||
/// <summary>
|
||
/// 返回福建省地图
|
||
/// </summary>
|
||
public Button backbtn;
|
||
|
||
/// <summary>
|
||
/// 目录
|
||
/// </summary>
|
||
public GameObject tab;
|
||
|
||
/// <summary>
|
||
/// 市
|
||
/// </summary>
|
||
public GameObject citys;
|
||
|
||
/// <summary>
|
||
/// 服务器IP
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string serverIP;
|
||
/// <summary>
|
||
/// 当前选中的海关
|
||
/// </summary>
|
||
public static CustomItem currentChoseCustonItem;
|
||
|
||
|
||
|
||
void Awake()
|
||
{
|
||
currentChoseCustonItem = null;
|
||
instance = this;
|
||
backbtn.onClick.AddListener(() =>
|
||
{
|
||
//点福州海关,回到首页,当前无选中关区
|
||
currentChoseCustonItem = null;
|
||
sheng_Panel.gameObject.SetActive(true);
|
||
//关闭所有市
|
||
citys.transform.GetComponentsInChildren<CityPanel>().ToList().ForEach(a =>
|
||
{
|
||
a.gameObject.SetActive(false);
|
||
});
|
||
//取消所有标签选中
|
||
FirstPanel.instance.tab.GetComponentsInChildren<TabItem>().ToList().ForEach(a =>
|
||
{
|
||
a.SetNoChoseState();
|
||
});
|
||
Application.ExternalCall("ClickCustom", "");
|
||
Debug.Log("调前端回到首页");
|
||
});
|
||
|
||
//初始化
|
||
Application.ExternalCall("OnWake");
|
||
|
||
#if UNITY_EDITOR
|
||
serverIP = "111.229.30.246";
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 前端调用初始化传IP
|
||
/// </summary>
|
||
/// <param name="serverIP"></param>
|
||
public void InitUnity(string serverIP)
|
||
{
|
||
this.serverIP= serverIP;
|
||
Debug.Log("接收IP:"+serverIP);
|
||
}
|
||
|
||
|
||
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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否触发区域
|
||
/// </summary>
|
||
/// <param name="image"></param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上一个显示的
|
||
/// </summary>
|
||
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 IEnumerator CallGet(string url,Action<bool,string> back)
|
||
{
|
||
UnityWebRequest request = UnityWebRequest.Get(url);
|
||
yield return request.SendWebRequest();
|
||
if(!request.isHttpError && !request.isNetworkError)
|
||
{
|
||
back(true,request.downloadHandler.text);
|
||
}
|
||
else
|
||
{
|
||
back(false, request.error);
|
||
}
|
||
}
|
||
}
|