103 lines
3.0 KiB
C#
103 lines
3.0 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
public static UIManager ins;
|
|
public LogOnState LogOnState = LogOnState.no;
|
|
[SerializeField] LogOn logOn;
|
|
[SerializeField] Transform MainPanel;
|
|
[SerializeField] Image im;
|
|
[SerializeField] user user;
|
|
[SerializeField] Button userBtn;
|
|
[SerializeField] Transform trans;
|
|
public int score;
|
|
public int TempScore;
|
|
public string UserPath = "https://img-blog.csdnimg.cn/20201110182621125.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzUxMTg3MQ==,size_16,color_FFFFFF,t_70#pic_center";
|
|
public string UserName = "明明";
|
|
public void Awake()
|
|
{
|
|
// 检查是否已经存在实例,如果存在则销毁当前对象
|
|
if (ins != null && ins != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
ins = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
PlayerPrefs.SetInt("isStart", 0);
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
Sprite sp = null;
|
|
//userBtn?.onClick.AddListener(()=>Logon());
|
|
}
|
|
public void Logon()
|
|
{
|
|
LogOn log = Instantiate(logOn, trans);
|
|
log.gameObject.SetActive(true);
|
|
}
|
|
/// <summary>
|
|
/// 登录成功
|
|
/// </summary>
|
|
public void LogOnTrue()
|
|
{
|
|
user.gameObject.SetActive(true);
|
|
userBtn.gameObject.SetActive(false);
|
|
}
|
|
public void end()
|
|
{
|
|
Debug.Log("完成大部分参数");
|
|
}
|
|
/// <summary>
|
|
/// 加载图片
|
|
/// </summary>
|
|
/// <param name="filePath">路径</param>
|
|
/// <param name="im">需要更改的Im</param>
|
|
/// <param name="isok">是否需要补全路径</param>
|
|
public void LoadImageAsync(string filePath,Image im,bool isok = true)
|
|
{
|
|
try
|
|
{
|
|
//this.im = im;
|
|
if (isok)
|
|
{
|
|
StartCoroutine(LoadImageAsync2(Application.streamingAssetsPath + "/" + filePath,im));
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(LoadImageAsync2(filePath,im));
|
|
}
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
Debug.LogError(ex.Message);
|
|
throw;
|
|
}
|
|
}
|
|
private IEnumerator LoadImageAsync2(string filePath,Image im)
|
|
{
|
|
using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(filePath))
|
|
{
|
|
yield return request.SendWebRequest();
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
{
|
|
Debug.LogError("加载失败: " + request.error);
|
|
yield break;
|
|
}
|
|
Texture2D texture = DownloadHandlerTexture.GetContent(request);
|
|
Rect rect = new Rect(0, 0, texture.width, texture.height);
|
|
Sprite sprite = Sprite.Create(texture, rect, Vector2.one * 0.5f);
|
|
im.sprite = sprite;
|
|
}
|
|
}
|
|
}
|
|
public enum LogOnState
|
|
{
|
|
ok,
|
|
no
|
|
}
|