FuZhou_Custom_BulkCargo_3D/FuZhou_FirstPage/Assets/Scripts/Item/ModelItem.cs

66 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Competition.Mysql.Model;
using LitJson;
using Competition.Mysql.Other;
public class ModelItem : MonoBehaviour
{
public erprise_model_version modelData;
public Image icon;
public Button btn;
public Text text;
public Sprite nochoseSprite;
public Sprite choseSprite;
/// <summary>
/// 企业item预制体
/// </summary>
public static GameObject modelItemPrefb;
private RectTransform rectTransform;
public void Init(erprise_model_version modelData,RectTransform citytrans)
{
this.modelData = modelData;
text.text = modelData.ModelName;
rectTransform = GetComponent<RectTransform>();
rectTransform.anchoredPosition = new Vector2(float.Parse(modelData.MapLongitude)* citytrans.rect.width, float.Parse(modelData.MapLatitude)* citytrans.rect.height);
modelData.MapLongitude=(rectTransform.position.x/Screen.width).ToString();
modelData.MapLatitude= (rectTransform.position.y/Screen.height).ToString();
#if !UNITY_EDITOR
icon.gameObject.SetActive(false);
btn.gameObject.SetActive(false);
text.gameObject.SetActive(false);
#endif
}
/// <summary>
/// 设置新的xy值给前端
/// </summary>
public void SetNowPostion()
{
modelData.MapLongitude = (rectTransform.position.x / Screen.width).ToString();
modelData.MapLatitude = (rectTransform.position.y / Screen.height).ToString();
}
public void PointIn(BaseEventData data)
{
icon.sprite = choseSprite;
//Application.ExternalCall("ChoseModel", JsonMapper.ToJson(modelData));
//Debug.Log(JsonMapper.ToJson(modelData));
}
public void PointOut(BaseEventData data)
{
icon.sprite = nochoseSprite;
//Application.ExternalCall("NoChoseModel");
//Debug.Log("取消选中");
}
}