I am streaming data from in my Resources folder in my DLL.
Web Player does not handle System.IO do what is an alternative to System IO Stream ?
In this script I get an image resource from a dll.
It uses Stream, which seems to not be handles by web player ?? MonoCompatability
public static Texture2D Load(string resourceName)
{
// first try to load as local resource, in case not running dll version
// also lets you override dll resources locally for rapid iteration
Texture2D texture = (Texture2D)Resources.Load(resourceName);
if (texture != null)
{
Debug.Log("Loaded local resource: " + resourceName);
return texture;
}
// if unavailable, try assembly
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream = myAssembly.GetManifestResourceStream(myAssembly.GetName().Name + ".Resources." + "monkey.jpg");
texture = new Texture2D(10, 10, TextureFormat.ARGB32, false);
texture.LoadImage(ReadToEnd(myStream));
if (texture == null)
{
Debug.LogError("Missing Dll resource: " + resourceName);
}
return texture;
}
I would then pipe myStream into a Stream
static byte[] ReadToEnd(Stream stream)
{
long originalPosition = stream.Position;
stream.Position = 0;
try
{
byte[] readBuffer = new byte[4096];
int totalBytesRead = 0;
int bytesRead;
while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
{
totalBytesRead += bytesRead;
if (totalBytesRead == readBuffer.Length)
{
int nextByte = stream.ReadByte();
if (nextByte != -1)
{
byte[] temp = new byte[readBuffer.Length * 2];
Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
Buffer.SetByte(temp, totalBytesRead, (byte)nextByte);
readBuffer = temp;
totalBytesRead++;
}
}
}
byte[] buffer = readBuffer;
if (readBuffer.Length != totalBytesRead)
{
buffer = new byte[totalBytesRead];
Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
}
return buffer;
}
finally
{
stream.Position = originalPosition;
}
}
UPDATE TO PROBLEM
I removed to script from the dll , left the monkey.jpg image in the dll as an embedded resource and then made sure to include a dummy class in the dll which i call in a mono script which is placed on a gameobject so that that the dll gets built too when i build the game . then i realised that it was not the scrpt that was the problem but the image …or its setting. I am not sure what to do here