Search Unity

WebPlayer does not run in background (but setting is set...)?

Discussion in 'Editor & General Support' started by DubStepMaster, Mar 7, 2016.

  1. DubStepMaster

    DubStepMaster

    Joined:
    Jul 17, 2012
    Posts:
    40
    Hey there!

    I want to create a simple application, which catches URL-Links in the clipboard (Ctrl + C) and opens them in a window (also closes the old, opened window).

    I made a very simple script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System;
    5.  
    6. public class ClipboardWebpage : MonoBehaviour {
    7.  
    8.  
    9.     List<string> openedWindows = new List<string>();
    10.     void OpenNewPage(string url) {
    11.         string name = "window";
    12.         openedWindows.Add(name);
    13.         Application.ExternalEval("var " + name  + " = window.open('" + url + "', 'title')");
    14.     }
    15.  
    16.     void Start()
    17.     {
    18.         Application.runInBackground = true;
    19.     }
    20.  
    21.     string lastCheck = "";
    22.     void Update () {
    23.         string clip = getClipboard();
    24.         if (!lastCheck.Equals(clip))
    25.         {
    26.             lastCheck = clip;
    27.  
    28.             Uri uriResult;
    29.             bool result = Uri.TryCreate(lastCheck, UriKind.Absolute, out uriResult)
    30.                 && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
    31.             if (result)
    32.             {
    33.                 CloseAll();
    34.                 OpenNewPage(lastCheck);
    35.             }
    36.         }
    37.     }
    38.  
    39.     void CloseAll()
    40.     {
    41.         foreach (string name in openedWindows)
    42.         {
    43.             Application.ExternalEval(name + ".close()");
    44.         }
    45.     }
    46.  
    47.     string getClipboard()
    48.     {
    49.         return GUIUtility.systemCopyBuffer;
    50.     }
    51.  
    52.  
    53.     void setClipboard(string value)
    54.     {
    55.         GUIUtility.systemCopyBuffer = value;
    56.     }
    57. }
    58.  
    59.  
    The problem is, that the Web Player does not run this code, when it's not focused... (The run in background option is set in code and also in the player settings...)

    Does anyone know, how to solve my problem?

    Thank you!