powerfun-unity/Assets/Scenes/Ride/Scripts/SelectPlayerItemScript.cs

92 lines
2.5 KiB
C#

using Assets.Scripts;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
public class SelectPlayerItemScript:MonoBehaviour
{
private string Id ;
private RawImage Head;
private Text Name;
private Text Timer;
private Text WeightKg;
private Button selectbutton;
public bool isSelected;
private void Awake()
{
selectbutton = transform.GetComponent<Button>();
}
private void Start()
{
}
public string GetRankingId()
{
return Id;
}
public string GetName()
{
Name = transform.Find("Name").GetComponent<Text>();
return Name.text;
}
public Texture GetImageTexture()
{
return Head.texture;
}
public Button GetButton()
{
return selectbutton;
}
public void SetRankingId(string id)
{
Id = id;
}
public void SetName(string name)
{
Name = transform.Find("Name").GetComponent<Text>();
Name.text = name;
}
public void SetTimer(string timer)
{
Timer = transform.Find("Timer").GetComponent<Text>();
Timer.text = timer;
}
public void SetWeightKg(string value)
{
WeightKg = transform.Find("WeightKg").GetComponent<Text>();
WeightKg.text = value+"W/KG";
}
public void SetHeadImage(string url)
{
Head = transform.Find("Head").GetComponent<RawImage>();
if (App.TextureCache.ContainsKey(url))
{
Head.texture = App.TextureCache[url];
}
else
{
Utils.DisplayImageAysnc(StartCoroutine, Head, url, ImageCallBack);
}
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);
}
}
}