Ejemplo n.º 1
0
    public IEnumerator IEnumeratorGet(string url, string token)
    {
        UnityEngine.Networking.UnityWebRequest webRequest = UnityEngine.Networking.UnityWebRequest.Get(url);
        webRequest.SetRequestHeader("X-Authorization", token);
        yield return(webRequest.Send());

        if (webRequest.responseCode != 200)
        {
            switch (webRequest.responseCode)
            {
            case 400:
                print("Invalid Data");
                yield break;

            case 401:
                print("User not found");
                yield break;

            case 403:
                print("Forbidden");
                yield break;
            }
        }
        user = JsonUtility.FromJson <User>(webRequest.downloadHandler.text);
        sceneLoader.ChangeToScene("main");
    }
Ejemplo n.º 2
0
    IEnumerator load_sub_asset_bundle(string bundle_name)
    {
        // This coroutine loads a single asset bundle at a time
        string uri;
        string path_to_use;

#if UNITY_ANDROID && !UNITY_EDITOR
        // This is the path to require an asset bundle in Assets/StreamingAssets on Android
        path_to_use = Path.Combine("jar:file://" + Application.dataPath + "!assets/", bundle_name);
        uri         = path_to_use;
#else
        // This is the same path but for your computer to recognize
        path_to_use = Application.streamingAssetsPath;
        uri         = path_to_use + "/" + bundle_name;
#endif

        // Ask for the bundle
        UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequestAssetBundle.GetAssetBundle(uri, 0);

        yield return(request.Send());

        switch (bundle_name)
        {
        case "weapons":
            // Get the bundle data and store it in the AssetBundle variable created at the begining.
            weapons_bundle = DownloadHandlerAssetBundle.GetContent(request);
            break;

        default:
            break;
        }
        // Delay for now is just to make sure it loads properly before its use.
        yield return(new WaitForSeconds(1F));
    }
Ejemplo n.º 3
0
        /// <summary>
        /// 本地或服务器加载依赖
        /// </summary>
        public IEnumerator UnityManifestWebRequest(bool isLocal, string assetBundleName)
        {
            UnityEngine.Networking.UnityWebRequest manifestReq = null;
            if (!isLocal)
            {
                string assetBundlePath = ServerPath("AssetBundles");
                manifestReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(assetBundlePath);
            }
            else
            {
                string assetBundlePath = LocalPath("AssetBundles");
                manifestReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle("file://" + assetBundlePath);
            }
            yield return(manifestReq.Send());

            AssetBundle         manifestAB = DownloadHandlerAssetBundle.GetContent(manifestReq);
            AssetBundleManifest manifest   = manifestAB.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

            string[] strs = manifest.GetAllDependencies(assetBundleName);
            foreach (string name in strs)
            {
                UnityEngine.Networking.UnityWebRequest dependenceReq = null;
                if (!isLocal)
                {
                    dependenceReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(ServerPath(name));
                }
                else
                {
                    dependenceReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(LocalPath(name));
                }
                yield return(dependenceReq.Send());

                AssetBundle dependenceAB = DownloadHandlerAssetBundle.GetContent(dependenceReq);
            }
        }
Ejemplo n.º 4
0
    private IEnumerator GetRequest(string ip, string port)
    {
        UnityEngine.Debug.Log(ip);
        UnityEngine.Networking.UnityWebRequest req = UnityEngine.Networking.UnityWebRequest.Get("http://" + ip + ":" + port + "/get");
        //UnityWebRequest req = UnityWebRequest.Get("10.1.144.91/get");
        //UnityWebRequest req = UnityWebRequest.Get("10.1.169.147:25687/get");
        yield return(req.Send());

        UnityEngine.Debug.Log("Get Result");
        UnityEngine.Debug.Log(req.error);
        UnityEngine.Debug.Log(req.downloadHandler.text);
    }
Ejemplo n.º 5
0
    public IEnumerator Download_World()
    {
        yield return(new WaitUntil(() => download));

        string world_name = doARsState.search;

        Debug.Log(world_name);
        // Download the file from the URL. It will not be saved in the Cache
        string BundleURL = "http://www.arnocular.org/handle_doARs/";

        // string BundleURL = "http://127.0.0.1:2567/handle_doARs/";
        UnityEngine.Networking.UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(BundleURL, 0);
        request.SetRequestHeader("world", world_name);
        yield return(request.Send());

        AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);

        Debug.Log(bundle);
        if (world_name == "")
        {
            Instantiate(bundle.mainAsset);
        }
        else
        {
            Handheld.Vibrate();
            UnityEngine.Object[] list_of_worlds = bundle.LoadAllAssets();
            foreach (UnityEngine.Object world in list_of_worlds)
            {
                // GameObject core = GameObject.Find("ModifiedARCore");
                // Transform t = core.transform;
                // t.position += new Vector3(0,0,-1);
                try {
                    UnityEngine.Object clone = Instantiate(world);
                    Debug.Log(clone.name);
                    GameObject f = GameObject.Find(clone.name);
                    f.gameObject.AddComponent <SelfDestruct>();
                    GameObject k = GameObject.Find("PortalWindow");
                    k.GetComponent <Portal>().device = GameObject.Find("First Person Camera").transform;
                }
                catch {
                    Debug.Log("Not available");
                }
            }
            // Instantiate(bundle.LoadAsset(world_name));
        }
        // Unload the AssetBundles compressed contents to conserve memory
        Debug.Log("download asset bundle");
        bundle.Unload(false);
        doARsState.goToState(doARs_state.rest);
        download = false;
        StartCoroutine(Download_World());
    } // memory is freed from the web stream (www.Dispose() gets called implicitly)
 static int Send(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.Networking.UnityWebRequest obj = (UnityEngine.Networking.UnityWebRequest)ToLua.CheckObject(L, 1, typeof(UnityEngine.Networking.UnityWebRequest));
         UnityEngine.AsyncOperation             o   = obj.Send();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    IEnumerator Start2()
    {
        //服务器地址
        string uri = @"http://localhost//AssetBundles/scene/sphere.test";

        //本地地址
        //string uri = @"file://D:/Unity3d/APlan_Siki/09_AssetBundleProject/Assets/AssetBundles/scene/sphere.test";
        UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(uri, 0);
        yield return(request.Send());//开始下载到缓存

        AssetBundle ab     = DownloadHandlerAssetBundle.GetContent(request);
        var         prefab = ab.LoadAsset <GameObject>("Sphere");

        GameObject.Instantiate(prefab);
    }
Ejemplo n.º 8
0
    private IEnumerator PostRequest(string ip)
    {
        WWWForm form = new WWWForm();

        UnityEngine.Debug.Log("Posting");
        form.AddField("seed", 1234567890);
        UnityEngine.Debug.Log(form.data);

        //UnityWebRequest r = UnityWebRequest.Put("http://" + ip + "/send", "1234567890");
        //r.method = "Post";
        //yield return r.Send();
        UnityEngine.Networking.UnityWebRequest req = UnityEngine.Networking.UnityWebRequest.Post("http://" + ip + "/send", form);
        yield return(req.Send());

        UnityEngine.Debug.Log("Post Result");
        UnityEngine.Debug.Log(req.uploadHandler.data);
        UnityEngine.Debug.Log(req.error);
    }
Ejemplo n.º 9
0
    public IEnumerator UnityWebRequest(string uri, uint version)
    {
        using (UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(uri, version))
        {
            yield return(request.Send());

            if (request.isError)
            {
                Debug.Log(request.error);
                Debug.Log(request.responseCode);
            }

            AssetBundle bundle = UnityEngine.Networking.DownloadHandlerAssetBundle.GetContent(request);

            addBundle(bundle.name, bundle);
        }

        yield return(null);
    }
Ejemplo n.º 10
0
    public IEnumerator LoadJsonOnAndroid(string fileName)
    {
        string filePath;

        filePath = Path.Combine(Application.streamingAssetsPath + "/", fileName);
        string dataAsJson;

        if (filePath.Contains("://") || filePath.Contains(":///"))
        {
            UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Get(filePath);
            yield return(www.Send());

            dataAsJson = www.downloadHandler.text;
        }
        else
        {
            dataAsJson     = File.ReadAllText(filePath);
            wholeLevelData = JsonMapper.ToObject(dataAsJson);
        }
    }
Ejemplo n.º 11
0
    public bool share(string id = "", string name = "", Dictionary <string, string> values = null)
    {
        if (api_access_token == null || !api_access_token.isValid())
        {
            if (!getAccessToken())
            {
                return(false);
            }
        }

        // If no id is supplied but we have one stored, reuse it.
        if (id == "" && statistic_id != "")
        {
            id = statistic_id;
        }

        string url = "https://api.globalstats.io/v1/statistics";

        if (id != "")
        {
            url = "https://api.globalstats.io/v1/statistics/" + id;
        }
        else
        {
            if (name == "")
            {
                name = "anonymous";
            }
        }

        string json_payload = "{\"name\":\"" + name + "\",\"values\":{";

        bool semicolon = false;

        foreach (KeyValuePair <string, string> value in values)
        {
            if (semicolon)
            {
                json_payload += ",";
            }
            json_payload += "\"" + value.Key + "\":\"" + value.Value + "\"";
            semicolon     = true;
        }
        json_payload += "}}";

        byte[] pData = Encoding.ASCII.GetBytes(json_payload.ToCharArray());

        GlobalstatsIO_StatisticResponse statistic = null;

        if (id == "")
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();
            headers.Add("Authorization", "Bearer " + api_access_token.access_token);
            headers.Add("Content-Type", "application/json");
            headers.Add("Content-Length", json_payload.Length.ToString());

            WWW www = new WWW(url, pData, headers);

            while (!www.isDone)
            {
                System.Threading.Thread.Sleep(100);
            }

            // check for errors
            if (www.error == null)
            {
                //UnityEngine.Debug.Log ("WWW POST Ok!");
            }
            else
            {
                UnityEngine.Debug.Log("WWW POST Error: " + www.error);
                UnityEngine.Debug.Log("WWW POST Content: " + www.text);
                return(false);
            }

            statistic = JsonUtility.FromJson <GlobalstatsIO_StatisticResponse>(www.text);
        }
        else
        {
            UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Put(url, pData);
            www.SetRequestHeader("Authorization", "Bearer " + api_access_token.access_token);
            www.SetRequestHeader("Content-Type", "application/json");

            UnityEngine.Networking.UploadHandler uploader = new UnityEngine.Networking.UploadHandlerRaw(pData);
            www.uploadHandler = uploader;

            www.Send();

            while (!www.isDone)
            {
                System.Threading.Thread.Sleep(100);
            }

            // check for errors
            if (www.error == null)
            {
                //UnityEngine.Debug.Log ("WWW PUT Ok!");
            }
            else
            {
                UnityEngine.Debug.Log("WWW PUT Error: " + www.error);
                UnityEngine.Debug.Log("WWW PUT Content: " + Encoding.ASCII.GetString(www.downloadHandler.data));
                return(false);
            }

            statistic = JsonUtility.FromJson <GlobalstatsIO_StatisticResponse>(Encoding.ASCII.GetString(www.downloadHandler.data));
        }

        // ID is available only on create, not on update, so do not overwrite it
        if (statistic._id != null && statistic._id != "")
        {
            statistic_id = statistic._id;
        }

        user_name = statistic.name;

        //Store the returned data statically
        foreach (GlobalstatsIO_StatisticValues value in statistic.values)
        {
            bool updated_existing = false;
            for (int i = 0; i < statistic_values.Count; i++)
            {
                if (statistic_values[i].key == value.key)
                {
                    statistic_values[i] = value;
                    updated_existing    = true;
                    break;
                }
            }
            if (!updated_existing)
            {
                statistic_values.Add(value);
            }
        }

        return(true);
    }
Ejemplo n.º 12
0
    IEnumerator _Refresh_IOS()
    {
        currentGPSPosition = Input.location.lastData;

        var usingSensor = false;

        #if UNITY_IPHONE
        usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;
        #endif

        int    m_i        = 0;
        string markerdata = "";
        foreach (var i in markers)
        {
            markerdata += "&markers=" + string.Format("size:{0}%7Ccolor%3A{1}%7Clabel:{2}", i.size.ToString().ToLower(), i.color, i.label);
            foreach (var loc in i.locations)
            {
                if (loc.address != "")
                {
                    markerdata += "%7C" + loc.address;
                }
                else
                {
                    if (m_i != 0)
                    {
                        markerdata += "%7C" + string.Format("{0},{1}", loc.latitude, loc.longitude);
                    }
                    else
                    {
                        markerdata += "%7C" + string.Format("{0},{1}", currentGPSPosition.latitude, currentGPSPosition.longitude);
                    }
                }
            }
            m_i++;
        }

        //Debug.Log(markerdata);

        string keys = "&key=AIzaSyDM58tFvVQv1558qHoe0CdFlWA3jJ18PQI";

        //

        //



        string nurl = "https://maps.googleapis.com/maps/api/staticmap?center=" + "37.57284" + "," + "126.9768" +
                      "&zoom=" + zoom + "&size=640x640&maptype=" + mapType.ToString().ToLower() + markerdata + keys;

        UnityEngine.Networking.UnityWebRequest www1 = UnityEngine.Networking.UnityWebRequest.GetTexture(nurl);
        yield return(www1.Send());

        //GetComponent<Renderer>().material.mainTexture = ((UnityEngine.Networking.DownloadHandlerTexture)www1.downloadHandler).texture;

        //Debug.Log (currentGPSPosition);

        if (www1.isError)
        {
            Debug.Log("Error while downloading image: " + www1.error);
        }
        else
        {
            imageDisp.texture = ((UnityEngine.Networking.DownloadHandlerTexture)www1.downloadHandler).texture;
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// WWW加载方式,可从本地上加载,也可以从服务器上加载(废弃)
        /// </summary>
        //public void LoadFromCacheOrDownload(bool isLocal, string assetBundleName, int version, string objName, Action<UnityEngine.Object> handler)
        //{
        //    StartCoroutine(LoadFromCacheOrDownload(isLocal, assetBundleName, version, null, objName, handler));
        //}

        /// <summary>
        /// 本地或服务器加载
        /// </summary>
        public IEnumerator UnityWebRequest(bool isLocal, bool hasDependence, string assetBundleName, string objName, Action <UnityEngine.Object> handler)
        {
            if (hasDependence)
            {
                UnityEngine.Networking.UnityWebRequest manifestReq = null;
                if (!isLocal)
                {
                    string assetBundlePath = ServerPath("AssetBundles");
                    manifestReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(assetBundlePath);
                }
                else
                {
                    string assetBundlePath = LocalPath("AssetBundles");
                    manifestReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle("file://" + assetBundlePath);
                }
                yield return(manifestReq.Send());

                AssetBundle         manifestAB = DownloadHandlerAssetBundle.GetContent(manifestReq);
                AssetBundleManifest manifest   = manifestAB.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

                string[] strs = manifest.GetAllDependencies(assetBundleName);
                foreach (string name in strs)
                {
                    UnityEngine.Networking.UnityWebRequest dependenceReq = null;
                    if (!isLocal)
                    {
                        dependenceReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(ServerPath(name));
                    }
                    else
                    {
                        dependenceReq = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(LocalPath(name));
                    }
                    yield return(dependenceReq.Send());

                    AssetBundle dependenceAB = DownloadHandlerAssetBundle.GetContent(dependenceReq);
                }
            }

            UnityEngine.Networking.UnityWebRequest request = null;
            if (!isLocal)
            {
                string assetBundlePath = ServerPath(assetBundleName);
                request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(assetBundlePath);
                yield return(request.Send());
            }
            else
            {
                string assetBundlePath = LocalPath(assetBundleName);
                request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle("file://" + assetBundlePath);
                yield return(request.Send());
            }

            AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
            //AssetBundle ab = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;

            //if (!string.IsNullOrEmpty(dependenceName))
            //{
            //    UnityEngine.Networking.UnityWebRequest requestDP = null;
            //    if (!isLocal)
            //    {
            //        string dependencePath = ServerPath(dependenceName);
            //        requestDP = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(dependencePath);
            //        yield return requestDP.Send();
            //    }
            //    else
            //    {
            //        string dependencePath = LocalPath(dependenceName);
            //        requestDP = UnityEngine.Networking.UnityWebRequest.GetAssetBundle("file://" + dependencePath);
            //        yield return requestDP.Send();
            //    }

            //    AssetBundle abDependence = DownloadHandlerAssetBundle.GetContent(requestDP);
            //    //AssetBundle abDependence = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
            //}

            var go = ab.LoadAsset <UnityEngine.Object>(objName);

            if (handler != null)
            {
                handler(go);
            }
        }