So I worked a bit on the code to this point:
public class LaunchNotePad : MonoBehaviour
{
public string processId = string.Empty
public GameObject rightPanel = null;
private static readonly HttpClient client = new HttpClient();
public void Launch()
{
CreateItem item = new CreateItem()
{
IsTopMost = true,
ProcessPath = “notepad”,
ProcessURL = “file:///C:/Windows/notepad.exe”,
Argument = “”,
ScreenNumber = 1,
Fullscreen = false,
Title = “NotePad”
};
string data = JsonConvert.SerializeObject(item);
var buffer = System.Text.Encoding.UTF8.GetBytes(data);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue(“application/json”);
HttpResponseMessage response = client.PostAsync(“http://localhost:5000/api/create/”, byteContent).Result;
processId = response.Content.ReadAsStringAsync().Result;
GameObject sphere = GameObject.Find(“Sphere”);
sphere.SetActive(false);
rightPanel = GameObject.Find(“RightPanel2”);
}
void Update()
{
if (!rightPanel)
return;
HttpResponseMessage response = client.GetAsync(“http://localhost:5000/api/snapshot/” + processId).Result;
var imgName = response.Content.ReadAsStringAsync().Result;
Texture2D tex = null;
byte[ ] fileData;
if (File.Exists(imgName))
{
fileData = File.ReadAllBytes(imgName);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //…this will auto-resize the texture dimensions.
}
RectTransform rectTransform = rightPanel.GetComponent();
rightPanel.GetComponent<UnityEngine.UI.Image>().sprite = Sprite.Create(tex, rectTransform.rect, new Vector2(1, 1));
}
}
Because of the Update I generate regular screenshot and I want them to be used a sprite for the “RightPanel2”.
Even if the GameObject seems to be reached, the sprite is never showed.
In the Editor, the Source Image go from "None (Sprite) to " ".
What do I miss do you think?