https://www.bilibili.com/video/bv1iD4y1X7e8
首先打开服务器,然后打开客户端,修改StreamingAssets的ip地址,然后打开客户端,在服务器里面输入图片的本地路径,输入完成后,点下enter键就能通过服务器传送大客户端里面了
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class GameLoop : MonoBehaviour
{
public InputField inputField;
public RawImage rawImage;
public SendPhoto sendPhoto;
public static GameLoop Instance;
void Start()
{
Instance = this;
inputField.onEndEdit.AddListener((str) =>
{
Debug.Log(str);
byte[] bytstmp = GetTexture(str);
if (bytstmp == null)
{
inputField.text = "";
}
else
{
Texture2D texture = new Texture2D(960, 540);
texture.LoadImage(bytstmp);
rawImage.gameObject.SetActive(true);
rawImage.texture = texture;
inputField.gameObject.SetActive(false);
sendPhoto.Send(bytstmp);
}
});
}
public void Refrush()
{
inputField.gameObject.SetActive(true);
inputField.text = "";
rawImage.gameObject.SetActive(false);
}
byte[] GetTexture(string path)
{
byte[] bytstmp = null;
try
{
bytstmp = File.ReadAllBytes(path);
}
catch (System.Exception)
{
return null;
}
return bytstmp;
}
}