void Start()
    {
        // Initialize Berkelium
        UnityBerkelium.init();

        // Create the texture that will represent the website (with optional transparency and without mipmaps)
        TextureFormat texFormat = transparency ? TextureFormat.ARGB32 : TextureFormat.RGB24;
        m_Texture = new Texture2D (width, height, texFormat, false);

        // Create the pixel array for the plugin to write into at startup
        m_Pixels = m_Texture.GetPixels (0);
        // "pin" the array in memory, so we can pass direct pointer to it's data to the plugin,
        // without costly marshaling of array of structures.
        m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned);

        // Save the texture ID
        m_TextureID = m_Texture.GetInstanceID();

        // Improve rendering at shallow angles
        m_Texture.filterMode = FilterMode.Trilinear;
        m_Texture.anisoLevel = 2;

        // Assign texture to the renderer
        if (renderer)
        {
            renderer.material.mainTexture = m_Texture;

            // Transparency?
            if(transparency)
                renderer.material.shader = Shader.Find("Transparent/Diffuse");
            else
                renderer.material.shader = Shader.Find("Diffuse");

            // The texture has to be flipped
            renderer.material.mainTextureScale = new Vector2(1,-1);
        }
        // or gui texture
        else if (GetComponent(typeof(GUITexture)))
        {
            GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
            gui.texture = m_Texture;
        }
        else
        {
            Debug.Log("Game object has no renderer or gui texture to assign the generated texture to!");
        }

        // Create new web window
        UnityBerkelium.Window.create(m_TextureID, m_PixelsHandle.AddrOfPinnedObject(), transparency, width,height, url);
        print("Created new web window: " + m_TextureID);

        // Paint callbacks
        m_setPixelsFunc = new UnityBerkelium.SetPixelsFunc(this.SetPixels);
        m_applyTextureFunc = new UnityBerkelium.ApplyTextureFunc(this.ApplyTexture);
        UnityBerkelium.Window.setPaintFunctions(m_TextureID, m_setPixelsFunc, m_applyTextureFunc);

        // Set the external host callback (for calling Unity functions from javascript)
        m_externalHostFunc = new UnityBerkelium.ExternalHostFunc(this.onExternalHost);
        UnityBerkelium.Window.setExternalHostCallback(m_TextureID, m_externalHostFunc);
    }
Beispiel #2
0
    void Start()
    {
        // Initialize Berkelium
        UnityBerkelium.init();

        // Create the texture that will represent the website (with optional transparency and without mipmaps)
        TextureFormat texFormat = transparency ? TextureFormat.ARGB32 : TextureFormat.RGB24;

        m_Texture = new Texture2D(width, height, texFormat, false);

        // Create the pixel array for the plugin to write into at startup
        m_Pixels = m_Texture.GetPixels(0);
        // "pin" the array in memory, so we can pass direct pointer to it's data to the plugin,
        // without costly marshaling of array of structures.
        m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned);

        // Save the texture ID
        m_TextureID = m_Texture.GetInstanceID();

        // Improve rendering at shallow angles
        m_Texture.filterMode = FilterMode.Trilinear;
        m_Texture.anisoLevel = 2;

        // Assign texture to the renderer
        if (renderer)
        {
            renderer.material.mainTexture = m_Texture;

            // Transparency?
            if (transparency)
            {
                renderer.material.shader = Shader.Find("Transparent/Diffuse");
            }
            else
            {
                renderer.material.shader = Shader.Find("Diffuse");
            }

            // The texture has to be flipped
            renderer.material.mainTextureScale = new Vector2(1, -1);
        }
        // or gui texture
        else if (GetComponent(typeof(GUITexture)))
        {
            GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
            gui.texture = m_Texture;
        }
        else
        {
            Debug.Log("Game object has no renderer or gui texture to assign the generated texture to!");
        }

        // Create new web window
        UnityBerkelium.Window.create(m_TextureID, m_PixelsHandle.AddrOfPinnedObject(), transparency, width, height, url);
        print("Created new web window: " + m_TextureID);

        // Paint callbacks
        m_setPixelsFunc    = new UnityBerkelium.SetPixelsFunc(this.SetPixels);
        m_applyTextureFunc = new UnityBerkelium.ApplyTextureFunc(this.ApplyTexture);
        UnityBerkelium.Window.setPaintFunctions(m_TextureID, m_setPixelsFunc, m_applyTextureFunc);

        // Set the external host callback (for calling Unity functions from javascript)
        m_externalHostFunc = new UnityBerkelium.ExternalHostFunc(this.onExternalHost);
        UnityBerkelium.Window.setExternalHostCallback(m_TextureID, m_externalHostFunc);
    }