149 lines
5.2 KiB
C#
149 lines
5.2 KiB
C#
using Competition.Mysql.Other;
|
|
using LitJson;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class WorkPlacePanel : MonoBehaviour
|
|
{
|
|
WorkPlaceItem workPlaceItem;
|
|
RectTransform rectTransform;
|
|
public void Init(string custCodes, WorkPlaceItem workPlaceItem)
|
|
{
|
|
this.workPlaceItem = workPlaceItem;
|
|
rectTransform = GetComponent<RectTransform>();
|
|
InitModel(custCodes);
|
|
}
|
|
/// <summary>
|
|
/// 生成企业图标
|
|
/// </summary>
|
|
/// <param name="custCodes"></param>
|
|
private void InitModel(string custCodes)
|
|
{
|
|
//删除所有模型
|
|
GetComponentsInChildren<ModelItem>(true).ToList().ForEach(a =>
|
|
{
|
|
Destroy(a.gameObject);
|
|
});
|
|
|
|
//获取关区下所有企业信息
|
|
//string url = "http://" + FirstPanel.instance.serverIP + ":4000/api/Corporation/GetAllPosition?customCodes=" + custCodes;
|
|
string url = "http://" + FirstPanel.instance.serverIP + ":4000/api/GetModelVersionList";
|
|
Debug.Log("获取企业模型:" + url);
|
|
StartCoroutine(FirstPanel.instance.CallGet(url, (isok, result) =>
|
|
{
|
|
Debug.Log("获取企业模型返回 "+ result);
|
|
if (isok)
|
|
{
|
|
//生成企业模型
|
|
JsonData data = JsonMapper.ToObject(result);
|
|
var tmp = data["data"]["list"];
|
|
|
|
List<erprise_model_version> list = new List<erprise_model_version>();
|
|
foreach (JsonData item in tmp)
|
|
{
|
|
erprise_model_version v = JsonMapper.ToObject<erprise_model_version>(item.ToJson());
|
|
if (!string.IsNullOrEmpty(v.MapLatitude) && !string.IsNullOrEmpty(v.MapLongitude))
|
|
{
|
|
list.Add(v);
|
|
}
|
|
}
|
|
|
|
//本关区的
|
|
List<erprise_model_version> showAll=new List<erprise_model_version>();
|
|
if (workPlaceItem.workPlaceName == "驻罗源湾办事处")
|
|
{
|
|
showAll = list.FindAll(a => a.DistrictCode=="3505");
|
|
}
|
|
else if (workPlaceItem.workPlaceName == "驻福清办事处")
|
|
{
|
|
showAll = list.FindAll(a => a.DistrictCode == "3502");
|
|
//读取福清配置文件
|
|
List<erprise_model_version> tmpComps = JsonMapper.ToObject<List<erprise_model_version>>(FirstPanel.instance.fuqingWorkPlaceJson);
|
|
showAll.AddRange(tmpComps);
|
|
}
|
|
|
|
showAll.ForEach(a =>
|
|
{
|
|
//生成本关区的图标
|
|
if (ModelItem.modelItemPrefb == null)
|
|
{
|
|
ModelItem.modelItemPrefb = Resources.Load<GameObject>("prefeb/modelItem");
|
|
}
|
|
GameObject go = Instantiate<GameObject>(ModelItem.modelItemPrefb, transform);
|
|
go.GetComponent<ModelItem>().Init(a, GetComponent<RectTransform>());
|
|
});
|
|
|
|
Application.ExternalCall("ClickCustom", JsonMapper.ToJson(showAll));
|
|
Debug.Log("调前端显示企业" + custCodes);
|
|
|
|
|
|
//福清默认放大
|
|
if (workPlaceItem.workPlaceName == "驻福清办事处")
|
|
{
|
|
SetPos(new Vector2(124.3824f, 583.4997f));
|
|
SetScale(3);
|
|
}
|
|
else
|
|
{
|
|
SetPos(Vector2.zero);
|
|
SetScale(1);
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
Debug.Log(JsonMapper.ToJson(showAll));
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError(result);
|
|
}
|
|
}));
|
|
}
|
|
|
|
public void OnMove(BaseEventData baseEvent)
|
|
{
|
|
PointerEventData evnetdata = (PointerEventData)baseEvent;
|
|
if (evnetdata.button == PointerEventData.InputButton.Left)
|
|
{
|
|
SetPos(rectTransform.anchoredPosition + evnetdata.delta);
|
|
}
|
|
}
|
|
public void OnScorll(BaseEventData baseEvent)
|
|
{
|
|
PointerEventData evnetdata = (PointerEventData)baseEvent;
|
|
float value = (rectTransform.localScale.x + evnetdata.scrollDelta.y* 0.1f);
|
|
value = Mathf.Clamp(value, 1f, 3f);
|
|
SetScale(value);
|
|
}
|
|
|
|
private void SetPos(Vector2 anchoredPosition)
|
|
{
|
|
rectTransform.anchoredPosition = anchoredPosition;
|
|
//更新坐标
|
|
List<erprise_model_version> list = new List<erprise_model_version>();
|
|
transform.GetComponentsInChildren<ModelItem>(true).ToList().ForEach(a =>
|
|
{
|
|
a.SetNowPostion();
|
|
list.Add(a.modelData);
|
|
});
|
|
Application.ExternalCall("OnBanShiChuChange", JsonMapper.ToJson(list));
|
|
}
|
|
private void SetScale(float scale)
|
|
{
|
|
rectTransform.localScale = new Vector3(scale, scale, scale);
|
|
|
|
//更新坐标
|
|
List<erprise_model_version> list = new List<erprise_model_version>();
|
|
transform.GetComponentsInChildren<ModelItem>(true).ToList().ForEach(a =>
|
|
{
|
|
a.SetNowPostion();
|
|
list.Add(a.modelData);
|
|
});
|
|
Application.ExternalCall("OnBanShiChuChange", JsonMapper.ToJson(list));
|
|
}
|
|
}
|