大连中石油电子沙盘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
1.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AX.NetworkSystem;
using System;
using System.IO;
using AX.Network.Protocols;
using AX.Serialization;
public class DownloadFileTest : MonoBehaviour
{
public string Fullname;
public string Filename;
private string progress;
private bool completed;
private void Start()
{
if (Fullname == null || Filename == null)
throw new ArgumentNullException(Fullname + " | " + Filename);
NetworkMessageDispatcher.AddListener("ERROR", OnError);
}
private void OnDestroy()
{
NetworkMessageDispatcher.RemoveListener("ERROR", OnError);
}
private void OnError(BinaryMessage message)
{
var error = message.Body.Deserialize<ErrorInfo>();
if (error.ErrorCode == 404)
Debug.LogError(error.ErrorMessage);
}
private void OnGUI()
{
GUILayout.BeginArea(new Rect(0, 0, 600, 400));
GUILayout.BeginVertical();
if (GUILayout.Button("下载文件" + "{" + Filename + "}"))
{
NetworkManager.Default.DownloadFileAsync(Fullname, Filename, null, OnProgressChanged, OnCompleted);
}
GUILayout.BeginHorizontal();
GUILayout.Label(Fullname + ": 进度 ");
GUILayout.Label(progress + ", 完成 ");
GUILayout.Label(completed ? "√" : "×");
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndArea();
}
private void OnCompleted(string fullname, string filename)
{
completed = true;
}
private void OnProgressChanged(string fullname, string filename, float progress)
{
this.progress = progress.ToString();
}
}