附近的人
This commit is contained in:
1 parent
725b510748
commit
2fcd9b23fa
94 files changed
+7063
-2007
No files matched your search
@@ -0,0 +1,115 @@
|
||||
using Assets.Cyp.Common;
|
||||
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 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>();
|
||||
}
|
||||
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
if (!_ratio.Equals(ratio))
|
||||
{
|
||||
Ratio.text = ratio;
|
||||
}
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
if (!_headUrl.Equals(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;
|
||||
}
|
||||
}
|
||||
|
||||
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(string url)
|
||||
{
|
||||
if (!_countryUrl.Equals(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user