UnitySetGraphicsDevice

Anyone know how to implement the Native plugin links:

extern “C” void EXPORT_API UnitySetGraphicsDevice(void* device, int deviceType, int eventType)

I get issues with “dllimport cannot be used on user-defined methods” which is fine, but I can’t see how you hook these methods in?

Thanks,

Jon

You can’t use Platform Invoke on Windows Phone 8. One way would be to use Windows Phone Runtime Component, and then import it using a plugin.

Hi Tautvydas,

UnitySetGraphicsDevice is called automatically from Unity to the plugin, does this get called in the Runtime Component, and if so how to I create my method?

Thanks,

Jon

I managed to do what I needed with GetNativeTexturePtr(); then grabbing the device from that.

Could you share with us how you did to get back the graphics device from the texture pointer? I’ve got the same issue and your trick may help me a lot.

Sure:

//Assuming you have a Texture2D called tex, like:
Texture2D tex;

IntPtr ptr=tex.GetNativeTexturePtr();
//You then need to pass this to a Native C++ plugin (see the plugins in Windows Phone as to how to set up a plugin it has to be a C++ one because DirectX access is only available in C++)
//Then in C++ plugin

void* g_TexturePointer=(void*)ptr;
ID3D11Texture2D* d3dtex= (ID3D11Texture2D)g_TexturePointer;
ID3D11Device* g_D3D11Device;
d3dtex->GetDevice(&g_D3D11Device);

And thats how I got it!