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.
78 lines
1.8 KiB
78 lines
1.8 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.NetworkSystem;
|
||
|
using System;
|
||
|
using System.IO;
|
||
|
|
||
|
public class SendFileTest : MonoBehaviour
|
||
|
{
|
||
|
public string[] FileList;
|
||
|
public string Tag;
|
||
|
|
||
|
private float[] progressList;
|
||
|
private bool[] completedList;
|
||
|
|
||
|
private string baseFolder;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
if (FileList == null)
|
||
|
Debug.LogError("出大事了!");
|
||
|
|
||
|
progressList = new float[FileList.Length];
|
||
|
completedList = new bool[FileList.Length];
|
||
|
|
||
|
baseFolder = Application.dataPath + "/";
|
||
|
}
|
||
|
|
||
|
private void OnGUI()
|
||
|
{
|
||
|
GUILayout.BeginArea(new Rect(0, 0, 500, 400));
|
||
|
|
||
|
GUILayout.BeginVertical();
|
||
|
|
||
|
if (GUILayout.Button("开始转发"))
|
||
|
{
|
||
|
|
||
|
for (var i = 0; i < FileList.Length; ++i)
|
||
|
{
|
||
|
var fullname = baseFolder + FileList[i];
|
||
|
|
||
|
NetworkManager.Chat.SendFileAsync(fullname, Tag, OnProgressChanged, OnCompleted);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (var i = 0; i < FileList.Length; ++i)
|
||
|
{
|
||
|
GUILayout.BeginHorizontal();
|
||
|
GUILayout.Label(FileList[i] + ": 进度 ");
|
||
|
GUILayout.Label(progressList[i].ToString() + ", 完成 ");
|
||
|
GUILayout.Label(completedList[i] ? "√" : "×");
|
||
|
GUILayout.EndHorizontal();
|
||
|
}
|
||
|
|
||
|
GUILayout.EndVertical();
|
||
|
|
||
|
GUILayout.EndArea();
|
||
|
}
|
||
|
|
||
|
private void OnCompleted(string fullname)
|
||
|
{
|
||
|
var filename = Path.GetFileName(fullname);
|
||
|
|
||
|
var index = Array.IndexOf(FileList, filename);
|
||
|
|
||
|
completedList[index] = true;
|
||
|
}
|
||
|
|
||
|
private void OnProgressChanged(string fullname, float progress)
|
||
|
{
|
||
|
var filename = Path.GetFileName(fullname);
|
||
|
|
||
|
var index = Array.IndexOf(FileList, filename);
|
||
|
|
||
|
progressList[index] = progress;
|
||
|
}
|
||
|
}
|