Пример #1
0
    public IEnumerator Start()
    {
        Debug.Log( "Initializing WebCore." );
        // WebCoreInitializer.Awake() initializes the WebCore
        // before any Start() function on any script is called.
        // We create a web-view here.

        //NewsManager manejaNews = NewsManager.getInstance();
        NewsManager manejaNews = new NewsManager();

        manejaNews.getBackNews(newsCategory,newsFaculty);

        yield return new WaitForSeconds (7f); //Espera unos segundos (por defecto elegimos 7) a que se complete la descarga. Sabemos que es horrible esto pero de momento queda así, todos los intentos de descarga asincrónica fallaron

        //Debug.Log("OUT "+manejaNews.isDownloadFinished()+"    #= "+ manejaNews.getCantNoticias());

        int newsAmmount= manejaNews.getCantNoticias();
        News noticia;
        html = "<html><body bgcolor=2B593D text=white> <p> <center> <h1> Noticias de " + newsCategory + " en " + newsFaculty + "</h1> </center> </p>";
        //html = "<html><body bgcolor=2B593D text=white> <p> <marquee> <h1> Noticias de " + newsCategory + " en " + newsFaculty + "</h1></marquee></p>"; //CON MARQUESINA  (decrementa muchísimo la performance)
        //Agrega las noticias
        if (newsAmmount == 0){
            html+= "<p>No hay noticias disponibles.</p>";
        }
        else{
            ArrayList noticias = manejaNews.getAllNews();
            for (int i=0; i< newsAmmount; i++){
                noticia = (News)noticias[i];
                Debug.Log (i+" - Title: "+noticia.getTitle());
        //				Debug.Log ("Content: "+noticia.getContent());
                html+="<p><h3>" + noticia.getTitle()+ "</h3>"+ noticia.getContent()+"</p>";
                html+="<p><HR></p>";
            }
        }

        html= html+ "</body></html>";

        webView = WebCore.CreateWebView( width, height );

        // Load the defined URL.
        //webView.LoadURL( initialURL );

        webView.LoadHTML(html);
        // Prepare and a assign a texture to the component.
        // The texture will display the pixel buffer of the WebView.
        texture = new Texture2D( width, height, TextureFormat.RGBA32, false );
        Pixels = texture.GetPixels32( 0 );
        PixelsHandle = GCHandle.Alloc( Pixels, GCHandleType.Pinned );

        if ( GetComponent<Renderer>() ){
            GetComponent<Renderer>().material.mainTexture = texture;
        }
        else if ( GetComponent( typeof( GUITexture ) ) )
        {
            GUITexture gui = GetComponent( typeof( GUITexture ) ) as GUITexture;
            gui.texture = texture;
        }
        else
            Debug.LogError( "Game Object has no Material or GUI Texture, we cannot render a web-page to this object!" );

        // Handle some important events.
        webView.OpenExternalLink += OnWebViewOpenExternalLink;
        webView.ShowJavascriptDialog += OnJavascriptDialog;
        webView.LoginRequest += OnLoginRequest;
    }