Пример #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);
    }
Пример #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);
        }
    }
Пример #3
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);
    }
Пример #4
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
        }
    }
Пример #5
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);
    }
Пример #6
0
    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);
        }
    }
Пример #7
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);
    }