Example #1
0
    public static bool Initialize()
    {
        Dictionary <string, object> djson = new Dictionary <string, object>();
        Dictionary <string, object> app;

        djson["application"] = app = new Dictionary <string, object>();

        string dataPath = Application.dataPath;

#if !UNITY_EDITOR && UNITY_STANDALONE_OSX
        // Unity 5 bug
        dataPath += "/Resources";
#endif

        app["dataPath"]              = dataPath;
        app["persistentDataPath"]    = Application.persistentDataPath;
        app["temporaryCachePath"]    = Application.temporaryCachePath;
        app["streamingAssetsPath"]   = Application.streamingAssetsPath;
        app["isEditor"]              = Application.isEditor;
        app["platform"]              = Application.platform;
        app["unityVersion"]          = Application.unityVersion;
        app["targetFrameRate"]       = Application.targetFrameRate;
        app["graphicsDeviceVersion"] = SystemInfo.graphicsDeviceVersion;

        app["rootCacheFolder"] = UWKConfig.RootCacheFolder;
        app["cacheName"]       = UWKConfig.CacheName;

        app["userAgent"]      = UWKConfig.UserAgent;
        app["productVersion"] = UWKConfig.UserAgentProductVersion;
        app["debugPort"]      = UWKConfig.ChromiumDebugPort;
        app["webSecurity"]    = UWKConfig.WebSecurity;

        //app["imeEnabled"] = UWKCore.IMEEnabled;

        // WARNING: modifying the following line to obscure the version of Unity running
        // violates the terms of the uWebKit3 EULA
        app["hasProLicense"] = Application.HasProLicense();

        // TODO: Proxy Support

        /*
         *      app["proxyEnabled"] = UWKConfig.ProxyEnabled;
         *      app["proxyHostName"] = UWKConfig.ProxyHostname;
         *      app["proxyUsername"] = UWKConfig.ProxyUsername;
         *      app["proxyPassword"] = UWKConfig.ProxyPassword;
         *      app["proxyPort"] = UWKConfig.ProxyPort;
         *      app["authEnabled"] = UWKConfig.AuthEnabled;
         *      app["authUsername"] = UWKConfig.AuthUsername;
         *      app["authPassword"] = UWKConfig.AuthPassword;
         */

        var json         = UWKJson.Serialize(djson);
        var nativeString = NativeUtf8FromString(json);
        var success      = UWK_Initialize(log, error, processUWKEvent, beta, nativeString);
        Marshal.FreeHGlobal(nativeString);

        return(success);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Vector3 eulerAngle = transform.localEulerAngles;

        eulerAngle.z = isShaking ? Mathf.Sin(Time.time * shakeSpeed) * shakeAmplitude : 0;
        transform.localEulerAngles = eulerAngle;
        closeBtn.SetActive(isShaking);

        if (queryReady && queryQueue.Count > 0)
        {
            var qry = queryQueue.Dequeue();
            webView.EvaluateJavascript(string.Format("makeQuery({0})", UWKJson.Serialize(qry.qry)), qry.callback);
        }
    }
Example #3
0
    void onWebQuery(UWKWebQuery query)
    {
        var request = UWKJson.Deserialize(query.Request) as Dictionary <string, object>;

        var message = request["message"] as string;

        if (message == "UnityMessage")
        {
            var payload = request["payload"] as Dictionary <string, object>;

            var messageCount = (long)payload["messageCount"];

            query.Success("Query Response from Unity: Message Count = " + messageCount);
        }
    }
Example #4
0
    public static bool Initialize()
    {
        Dictionary <string, object> djson = new Dictionary <string, object>();
        Dictionary <string, object> app;

        djson["application"] = app = new Dictionary <string, object>();

        string dataPath = Application.dataPath;

#if !UNITY_EDITOR && UNITY_STANDALONE_OSX
        // Unity 5 bug
        dataPath += "/Resources";
#endif

        app["dataPath"]              = dataPath;
        app["persistentDataPath"]    = Application.persistentDataPath;
        app["temporaryCachePath"]    = Application.temporaryCachePath;
        app["streamingAssetsPath"]   = Application.streamingAssetsPath;
        app["isEditor"]              = Application.isEditor;
        app["platform"]              = Application.platform;
        app["unityVersion"]          = Application.unityVersion;
        app["targetFrameRate"]       = Application.targetFrameRate;
        app["graphicsDeviceVersion"] = SystemInfo.graphicsDeviceVersion;
        app["hasProLicense"]         = Application.HasProLicense();
        //app["imeEnabled"] = UWKCore.IMEEnabled;

        // TODO: Proxy Support

        /*
         *      app["proxyEnabled"] = UWKConfig.ProxyEnabled;
         *      app["proxyHostName"] = UWKConfig.ProxyHostname;
         *      app["proxyUsername"] = UWKConfig.ProxyUsername;
         *      app["proxyPassword"] = UWKConfig.ProxyPassword;
         *      app["proxyPort"] = UWKConfig.ProxyPort;
         *      app["authEnabled"] = UWKConfig.AuthEnabled;
         *      app["authUsername"] = UWKConfig.AuthUsername;
         *      app["authPassword"] = UWKConfig.AuthPassword;
         */

        var json         = UWKJson.Serialize(djson);
        var nativeString = NativeUtf8FromString(json);
        var success      = UWK_Initialize(log, error, processUWKEvent, beta, nativeString);
        Marshal.FreeHGlobal(nativeString);

        return(success);
    }
Example #5
0
    private static void onWebQuery(UWKWebQuery query)
    {
        var request = UWKJson.Deserialize(query.Request) as Dictionary <string, object>;

        var message = request ["message"] as string;

        if (message == "ButtonClicked")
        {
            var payload = UWKJson.Serialize(request ["payload"] as Dictionary <string, object>);

            query.Success("Query Response from Unity: Success!");

                        #if UNITY_EDITOR
            EditorUtility.DisplayDialog("Hello!", "Button clicked, value passed:\n" + payload, "OK!");
                        #endif
        }
    }
Example #6
0
        public void saveFile()
        {
            Dictionary <string, object> qry = new Dictionary <string, object>();

            qry.Add("cmd", "saveFile");
            qry.Add("params", new Dictionary <string, object>());

            view.makeQuery(qry, delegate(bool success, string value) {
                if (!success)
                {
                    Debug.LogError("Query failed.");
                }
                else
                {
                    content = (UWKJson.Deserialize(value) as IDictionary <string, object>)["content"] as string;
                }
            });
        }
Example #7
0
    /// <summary>
    /// Sends a Javascript message to the page
    /// </summary>
    public void SendJSMessage(string msgName, Dictionary <string, object> msgValues)
    {
        var json = UWKJson.Serialize(msgValues);

        UWKPlugin.SendJSMessage(ID, msgName, json);
    }
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (path.Contains(".exe"))
        {
            path = path.Replace(".exe", "_Data");
        }

        bool windowsBuild = target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64;
        bool linuxBuild   = target == BuildTarget.StandaloneLinux || target == BuildTarget.StandaloneLinux64 || target == BuildTarget.StandaloneLinuxUniversal;
        bool osxBuild     = target == BuildTarget.StandaloneOSXIntel || target == BuildTarget.StandaloneOSXIntel64 || target == BuildTarget.StandaloneOSXUniversal;

        #if !UNITY_4_6
        bool iosBuild = target == BuildTarget.iOS;
        #else
        bool iosBuild = target == BuildTarget.iPhone;
        #endif

        // build the target-specific streaming asset directories used for deployment
        List <string> assetDirectories = new List <string>()
        {
            "uWebKit/Mac/x86",
            "uWebKit/Mac/x86_64",
            "uWebKit/Windows/x86",
            "uWebKit/Windows/x86_64"
        };

        string assetDirectoryPrefix = string.Empty;

        if (windowsBuild || linuxBuild)
        {
            assetDirectoryPrefix = path + "/StreamingAssets/";
        }
        else if (osxBuild)
        {
            #if !UNITY_4_6
            assetDirectoryPrefix = path + "/Contents/Resources/Data/StreamingAssets/";
            #else
            assetDirectoryPrefix = path + "/Contents/Data/StreamingAssets/";
            #endif
        }
        else if (iosBuild)
        {
            assetDirectoryPrefix = path + "/Data/Raw/";
        }
        else
        {
            // log an error but at least allow compiling to continue by preventing further errors
            Debug.LogError("Unable to remove deployment paths for uWebKit on this platform");
            return;
        }

        List <string> deployPathsToDelete = new List <string>();
        foreach (string assetDirectory in assetDirectories)
        {
            deployPathsToDelete.Add(assetDirectoryPrefix + assetDirectory);
        }

        // protect the directory for the current target by removing it from the deletion list
        if (target == BuildTarget.StandaloneWindows)
        {
            deployPathsToDelete.Remove(assetDirectoryPrefix + "uWebKit/Windows/x86");
        }
        else if (target == BuildTarget.StandaloneWindows64)
        {
            deployPathsToDelete.Remove(assetDirectoryPrefix + "uWebKit/Windows/x86_64");
        }
        else if (target == BuildTarget.StandaloneOSXIntel)
        {
            deployPathsToDelete.Remove(assetDirectoryPrefix + "uWebKit/Mac/x86");
        }
        else if (target == BuildTarget.StandaloneOSXIntel64)
        {
            deployPathsToDelete.Remove(assetDirectoryPrefix + "uWebKit/Mac/x86_64");
        }

        RemovePaths(deployPathsToDelete);

        // save off config for data that Unity does not make available at runtime
        string cfgpath = assetDirectoryPrefix + "/uWebKit/Config";
        if (!Directory.Exists(cfgpath))
        {
            Directory.CreateDirectory(cfgpath);
        }
        ;

        Dictionary <string, object> jconfig = new Dictionary <string, object> ();
        jconfig["companyName"] = PlayerSettings.companyName;
        jconfig["productName"] = PlayerSettings.productName;
        var json = UWKJson.Serialize(jconfig);

        using (StreamWriter cfgfile = new StreamWriter(cfgpath + "/uwebkit.cfg"))
        {
            cfgfile.Write(json);
        }
    }
Example #9
0
    public static void Initialize()
    {
        // TODO: setup initialization JSON elsewhere, possibly a file
        Dictionary <string, object> djson = new Dictionary <string, object>();

        Dictionary <string, object> app;

        djson["application"] = app = new Dictionary <string, object>();

        app["hasProLicense"] = Application.HasProLicense();

        string dataPath = Application.dataPath;

        #if UNITY_5_0
            #if !UNITY_EDITOR
        // Unity 5 bug
        dataPath += "/Resources";
            #endif
        #endif

        app["dataPath"]              = dataPath;
        app["persistentDataPath"]    = Application.persistentDataPath;
        app["temporaryCachePath"]    = Application.temporaryCachePath;
        app["isEditor"]              = Application.isEditor;
        app["platform"]              = Application.platform;
        app["unityVersion"]          = Application.unityVersion;
        app["targetFrameRate"]       = Application.targetFrameRate;
        app["graphicsDeviceVersion"] = SystemInfo.graphicsDeviceVersion;
        app["imeEnabled"]            = UWKCore.IMEEnabled;

        // Proxy
        app["proxyEnabled"]  = UWKConfig.ProxyEnabled;
        app["proxyHostName"] = UWKConfig.ProxyHostname;
        app["proxyUsername"] = UWKConfig.ProxyUsername;
        app["proxyPassword"] = UWKConfig.ProxyPassword;
        app["proxyPort"]     = UWKConfig.ProxyPort;
        app["authEnabled"]   = UWKConfig.AuthEnabled;
        app["authUsername"]  = UWKConfig.AuthUsername;
        app["authPassword"]  = UWKConfig.AuthPassword;

#if UNITY_EDITOR
        app["companyName"] = PlayerSettings.companyName;
        app["productName"] = PlayerSettings.productName;
#else
        // Unity doesn't provide this data at runtime
        // so, load it from our config

        app["companyName"] = "DefaultCompany";
        app["productName"] = "DefaultProduct";

        var cfgfile = Application.streamingAssetsPath + "/uWebKit/Config/uwebkit.cfg";

        if (File.Exists(cfgfile))
        {
            var jsonString = "";

            #if !UNITY_WEBPLAYER
            jsonString = File.ReadAllText(cfgfile);
            #endif

            var cfg = UWKJson.Deserialize(jsonString) as Dictionary <string, object>;

            if (cfg.ContainsKey("companyName"))
            {
                app["companyName"] = (string)cfg["companyName"];
            }

            if (cfg.ContainsKey("productName"))
            {
                app["productName"] = (string)cfg["productName"];
            }
        }
#endif

        var json         = UWKJson.Serialize(djson);
        var nativeString = NativeUtf8FromString(json);

        int betaCheck = UWK_Initialize(log, error, processMessage, nativeString);

        if (betaCheck >= 99)
        {
            UWKCore.BetaVersion = true;

            betaCheck -= 100;

            if (betaCheck == -1)
            {
                Debug.LogError("uWebKit Beta Expired");
#if UNITY_EDITOR
                EditorUtility.DisplayDialog("uWebKit Beta Expired", "This BETA version of uWebKit has expired.\nPlease visit http://www.uwebkit.com", "Ok");
                EditorApplication.ExecuteMenuItem("Edit/Play");
#endif
            }
            else
            {
                string message = String.Format("There are {0} days left of this expiring uWebKit BETA", betaCheck);

                if (betaCheck == 0)
                {
                    message = String.Format("There is less than a day left of this expiring uWebKit BETA");
                }

                if (!UWK_HasDisplayedBetaMessage())
                {
#if UNITY_EDITOR
                    EditorUtility.DisplayDialog("uWebKit BETA Version", "\nThis is a BETA version of uWebKit.\n\n" + message, "Ok");
#endif
                }

                Debug.Log(message);
            }
        }

        Marshal.FreeHGlobal(nativeString);
    }
Example #10
0
    /// <summary>
    /// Internal Plugin -> Unity message receiving
    /// </summary>
    public static void ProcessMessage(ref UWKMessage msg)
    {
        UWKWebView view = null;

        bool msgView = false;

        switch (msg.type)
        {
        case UWKMessageType.UMSG_VIEW_LOADFINISHED:
        case UWKMessageType.UMSG_VIEW_URLCHANGED:
        case UWKMessageType.UMSG_VIEW_TITLECHANGED:
        case UWKMessageType.UMSG_VIEW_LOADPROGRESS:
        case UWKMessageType.UMSG_VIEW_ICONCHANGED:
        case UWKMessageType.UMSG_JAVASCRIPT_CONSOLE:
        case UWKMessageType.UMSG_JAVASCRIPT_MESSAGE:
        case UWKMessageType.UMSG_VIEW_CONTENTSIZECHANGED:
        case UWKMessageType.UMSG_IME_FOCUSIN:
        case UWKMessageType.UMSG_IME_FOCUSOUT:
        case UWKMessageType.UMSG_VIEW_REQUESTNEWVIEW:
            msgView = true;
            break;
        }

        if (msgView)
        {
            if (!viewLookup.TryGetValue(msg.browserID, out view))
            {
                Debug.Log("Warning: Unable to get view for message: " + Enum.GetName(typeof(UWKMessageType), msg.type));
                return;
            }
        }

        switch (msg.type)
        {
        case UWKMessageType.UMSG_VIEW_LOADFINISHED:
            view.LoadFinished(view);
            break;

        case UWKMessageType.UMSG_VIEW_URLCHANGED:
            view.URLChanged(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_VIEW_TITLECHANGED:
            view.TitleChanged(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_VIEW_LOADPROGRESS:
            view.LoadProgress(view, msg.iParams[0]);
            break;

        case UWKMessageType.UMSG_VIEW_ICONCHANGED:

            int size = UWKPlugin.GetMsgDataSize(ref msg, 0);

            if (size > 0)
            {
                byte[] bytes = new byte[size];

                if (UWKPlugin.GetMsgDataBytes(ref msg, 0, size, bytes))
                {
                    view.IconChanged(msg.iParams[0], msg.iParams[1], bytes);
                }
            }

            break;

        case UWKMessageType.UMSG_JAVASCRIPT_CONSOLE:
            view.JSConsole(view, UWKPlugin.GetMessageString(ref msg, 0), msg.iParams[0], UWKPlugin.GetMessageString(ref msg, 1));
            break;

        case UWKMessageType.UMSG_JAVASCRIPT_MESSAGE:
            var json = UWKPlugin.GetMessageString(ref msg, 1);
            var dict = UWKJson.Deserialize(json) as Dictionary <string, object>;
            view.JSMessageReceived(view, UWKPlugin.GetMessageString(ref msg, 0), json, dict);
            break;

        case UWKMessageType.UMSG_VIEW_CONTENTSIZECHANGED:
            view.ContentSizeChanged(view, msg.iParams[0], msg.iParams[1]);
            break;

        case UWKMessageType.UMSG_IME_FOCUSIN:
            view.IMEFocusIn(ref msg);
            break;

        case UWKMessageType.UMSG_IME_FOCUSOUT:
            view.IMEFocusOut();
            break;

        case UWKMessageType.UMSG_VIEW_REQUESTNEWVIEW:
            view.NewViewRequested(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_ACTIVATION_STATE:
            #if UNITY_EDITOR
            if (msg.iParams[0] != 1 && msg.iParams[0] != 5)
            {
                if (sInstance.gameObject.GetComponent <UWKActivation>() == null)
                {
                    sInstance.gameObject.AddComponent <UWKActivation>();
                }
            }
            UWKActivation.SetActivationState(msg.iParams[0]);
            #endif

            break;
        }
    }