Ejemplo n.º 1
0
        /// <summary>
        /// Set a property which will be accessible in Javascript.
        /// For example: Bridge.SetProperty("MyObject", "someValue", "Hello World!");
        /// would be accessible in Javascript as:
        /// MyObject.someValue;
        /// See uWebKitExamples/WebBrowser/UnityPageInfo.cs in examples
        /// </summary>
        public static void SetProperty(string objectName, string propName, string value)
        {
            if (!objects.ContainsKey(objectName))
            {
                AddObject(objectName);
            }

            BridgeObject bo = objects [objectName];

            string v;

            if (bo.Properties.TryGetValue(propName, out v))
            {
                if (value == v)
                {
                    return;
                }
            }
            // save the trip
            // instant here
            bo.Properties [propName] = value;

            // and out to web process
            Command cmd = Command.NewCommand("SETP", objectName, propName, value);

            cmd.Post();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Posts an exit command to the command queue
        /// </summary>
        public void Stop()
        {
#if !UNITY_IPHONE || UNITY_EDITOR
            if (UWKConfig.DebugProcess)
            {
                return;
            }

            Command cmd = Command.NewCommand("EXIT");
            cmd.Post();
#endif
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Explicitly add an object (Note: if you just set a property on a non-existant object will be created)
        /// </summary>
        public static BridgeObject AddObject(string objectName)
        {
            if (objects.ContainsKey(objectName))
            {
                Debug.LogWarning("Object " + objectName + " already exists");
                return(objects [objectName]);
            }

            BridgeObject bo = objects [objectName] = new BridgeObject();

            bo.Name = objectName;

            Command cmd = Command.NewCommand("ADDO", objectName);

            cmd.Post();

            return(bo);
        }
Ejemplo n.º 4
0
    void boot(ref Command cmd)
    {
        //Debug.Log("WebKit version: " + cmd.GetSParam (0));
        //Debug.Log("Qt version: " + cmd.GetSParam (1));

        ProductKey = cmd.GetSParam (2);

        int error = cmd.iParams [0];

        ProductTrial = cmd.iParams [3] == 1 ? true : false;

        if (error != 0) {
            Debug.Log ("Error starting uWebKit");

        }

        if (cmd.iParams [2] == 2) {
            //need to activate
            #if UNITY_EDITOR
            if (!EditorApplication.currentScene.Contains ("UWKActivationScene")) {
                EditorUtility.DisplayDialog ("uWebKit Activation Required", "Please select uWebKit/Activate from the Editor menu", "Ok");
                EditorApplication.ExecuteMenuItem ("Edit/Play");
            }
            #endif
        }

        if (cmd.iParams [1] == 0)
            StandardVersion = true;

        processUp = true;

        if (restarting) {
            restarting = false;
            UWKView.RestartAllViews ();
        }

        booted = true;

        #if UNITY_EDITOR
        if (StandardVersion)
            if (GetNumViews() > 1)
            {
                EditorUtility.DisplayDialog ("uWebKit Standard Version", "uWebKit Pro required for multiple web views", "Ok");
            }
        #endif

        // enable all views created before boot
        foreach (UWKView view in viewLookup.Values)
            view.enabled = true;

        cmd = Command.NewCommand ("ALWP", AllowJavascriptPopups ? 1 : 0);
        cmd.Post ();

        // set proxy if any
        if (UWKConfig.ProxyEnabled) {
            if (UWKConfig.ProxyHostname.Length > 0) {
                cmd = Command.NewCommand ("PRXY");
                cmd.numSParams = 1;
                cmd.SetSParam (0, UWKConfig.ProxyHostname);

                cmd.numIParams = 1;
                cmd.iParams [0] = UWKConfig.ProxyPort;

                if (UWKConfig.ProxyUsername.Length > 0) {
                    cmd.SetSParam (cmd.numSParams++, UWKConfig.ProxyUsername);

                    if (UWKConfig.ProxyPassword.Length > 0) {
                        cmd.SetSParam (cmd.numSParams++, UWKConfig.ProxyPassword);
                    }
                }

                // post proxy info
                cmd.Post ();
            }
        }

        // set auth if any
        if (UWKConfig.AuthEnabled && UWKConfig.AuthUsername.Length > 0 && UWKConfig.AuthPassword.Length > 0 ) {

            cmd = Command.NewCommand ("AUTH");
            cmd.numSParams = 2;
            cmd.SetSParam (0, UWKConfig.AuthUsername);
            cmd.SetSParam (1, UWKConfig.AuthPassword);
            cmd.Post ();
        }
    }