void Update()
        {
            PluginEntry.Poll();

            if (_receiver == System.IntPtr.Zero)
            {
                // The receiver hasn't been set up yet; try to get one.
                SearchAndCreateTexture();
            }
            else
            {
                // We've received textures via this receiver
                // but now it's disconnected from the sender -> Destroy it.
                if (PluginEntry.GetTexturePointer(_receiver) != System.IntPtr.Zero &&
                    PluginEntry.DetectDisconnection(_receiver))
                {
                    OnDestroy();
                }
            }

            if (_receiver != System.IntPtr.Zero)
            {
                if (_sharedTexture == null)
                {
                    // Try to initialize the shared texture.
                    var ptr = PluginEntry.GetTexturePointer(_receiver);
                    if (ptr != System.IntPtr.Zero)
                    {
                        _sharedTexture = Texture2D.CreateExternalTexture(
                            PluginEntry.GetTextureWidth(_receiver),
                            PluginEntry.GetTextureHeight(_receiver),
                            TextureFormat.ARGB32, false, false, ptr
                            );
                    }
                }
                else
                {
                    // Update external objects.
                    if (_targetTexture != null)
                    {
                        Graphics.Blit(_sharedTexture, _targetTexture, _fixupMaterial, 1);
                    }
                    else
                    {
                        if (_fixedTexture == null)
                        {
                            _fixedTexture = new RenderTexture(_sharedTexture.width, _sharedTexture.height, 0);
                        }
                        Graphics.Blit(_sharedTexture, _fixedTexture, _fixupMaterial, 1);
                    }

                    if (_targetRenderer != null)
                    {
                        _propertyBlock.SetTexture(_targetMaterialProperty, receivedTexture);
                        _targetRenderer.SetPropertyBlock(_propertyBlock);
                    }
                }
            }
        }
Exemple #2
0
 void Update()
 {
     PluginEntry.Poll();
 }