133 lines
4.5 KiB
C#
133 lines
4.5 KiB
C#
using Assets.Scripts;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
public class NearByItemScript : MonoBehaviour
|
|
{
|
|
private RawImage Head;
|
|
private RawImage Country;
|
|
private Text Name;
|
|
private Text Speed;
|
|
private Text Distance;
|
|
private Text Ratio;//功体比
|
|
|
|
private int _userId = 0;
|
|
public int UserId { get { return _userId; } }
|
|
private string _headUrl=string.Empty;
|
|
private string _countryUrl = string.Empty;
|
|
private string _name = string.Empty;
|
|
private string _speed = string.Empty;
|
|
private string _distance = string.Empty;
|
|
private string _ratio = string.Empty;
|
|
private Texture countryTexture;
|
|
private void Awake()
|
|
{
|
|
Head = transform.Find("Head").GetComponent<RawImage>();
|
|
Country = transform.Find("Country").GetComponent<RawImage>();
|
|
Name = transform.Find("Name").GetComponent<Text>();
|
|
Speed = transform.Find("Speed").GetComponent<Text>();
|
|
Distance = transform.Find("Distance").GetComponent<Text>();
|
|
Ratio = transform.Find("Ratio").GetComponent<Text>();
|
|
countryTexture = Resources.Load<Sprite>("Images/flag_China_Person").texture;
|
|
}
|
|
|
|
public void setRatio(string ratio)
|
|
{
|
|
if (!_ratio.Equals(ratio))
|
|
{
|
|
Ratio.text = ratio;
|
|
}
|
|
}
|
|
|
|
public void setHead(string url)
|
|
{
|
|
if (!_headUrl.Equals(url))
|
|
{
|
|
//if (App.TextureCache.ContainsKey(url))
|
|
//{
|
|
// Head.texture = App.TextureCache[url];
|
|
//}
|
|
//else
|
|
//{
|
|
Utils.DisplayImage(Head, url, true);
|
|
//}
|
|
|
|
//Utils.DisplayImage(StartCoroutine, Head, url);
|
|
//StartCoroutine(DownloadImage(Head, url));
|
|
var rect = ((RectTransform)Head.transform).rect;
|
|
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
|
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
|
Head.material = material;
|
|
}
|
|
}
|
|
//private void ImageCallBack(string url)
|
|
//{
|
|
// if (!App.TextureCache.ContainsKey(url))
|
|
// App.TextureCache.Add(url, Head.texture);
|
|
//}
|
|
|
|
//IEnumerator DownloadImage(RawImage img, string MediaUrl)
|
|
//{
|
|
// if (!App.TextureCache.ContainsKey(MediaUrl))
|
|
// {
|
|
// UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
|
// yield return request.SendWebRequest();
|
|
// if (request.isNetworkError || request.isHttpError)
|
|
// Debug.Log(request.error);
|
|
// else
|
|
// img.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
|
|
|
|
// App.TextureCache.Add(MediaUrl, img.texture);
|
|
// }
|
|
// else
|
|
// {
|
|
// img.texture = App.TextureCache["MediaUrl"];
|
|
// }
|
|
//}
|
|
|
|
public void setCountry(Texture texture)
|
|
{
|
|
{
|
|
Country.texture = texture;
|
|
//Utils.DisplayImage(StartCoroutine, Country, url);
|
|
//StartCoroutine(DownloadImage(Country, url));
|
|
//var rect = ((RectTransform)Country.transform).rect;
|
|
//Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
|
//material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
|
//Country.material = material;
|
|
}
|
|
}
|
|
public void setName(string name)
|
|
{
|
|
if (!_name.Equals(name))
|
|
Name.text = name;
|
|
}
|
|
|
|
public void setSpeed(string speed)
|
|
{
|
|
if (!_speed.Equals(speed))
|
|
Speed.text = speed;
|
|
}
|
|
|
|
public void setDistance(string distance)
|
|
{
|
|
if (!_distance.Equals(distance))
|
|
Distance.text = distance;
|
|
}
|
|
|
|
public void setUserId(int userId)
|
|
{
|
|
_userId = userId;
|
|
}
|
|
}
|
|
}
|