Example #1
0
    public static IEnumerator <WWW> LoadMaterial(string id, string type)
    {
        if (!MaterialIndex.ContainsKey(id))
        {
            string materialKey = type + "-" + id;
            // First check if it exists in loaded resources...
            if (MaterialResources.ContainsKey(materialKey))
            {
                // Resource found - just add it to our index
                Material material = MaterialResources [materialKey];
                MaterialIndex.Add(id, material);
//				Debug.Log ("Publishing Material: " + id);
                PubSub.publish("Material-" + id);
                yield return(null);
            }
            else if (MaterialAvailable.ContainsKey(materialKey))
            {
                // Material is available, need to download and construct the material from the texture
                if (!DownloadingMaterial.Contains(materialKey))
                {
                    DownloadingMaterial.Add(materialKey);
                    bool   isAvailableLocally = MaterialAvailableLocally.Contains(materialKey);
                    string baseUrl            = isAvailableLocally ? localMaterialBaseUrl : remoteMaterialBaseUrl;

                    WWW connection = CacheWWW.Get(baseUrl + MaterialAvailable[materialKey]);
                    yield return(connection);

                    DownloadAndCreateMaterial(connection, id, type, MaterialAvailable [materialKey], materialKey, !isAvailableLocally);
                }
            }
            else
            {
                if (isSyncRemoteDone && isSyncLocalDone)
                {
                    // Material is missing, what to do?
                    // TODO - This isn't correct - investigate later
//					Debug.LogWarning ("Couldn't find material for ID: " + id + " (" + type+ ")");
                    yield return(null);
                }
                else
                {
                    queuedMaterialsForAfterSync.Add(new KeyValuePair <string, string>(id, type));
                }
            }
        }
        else
        {
            yield return(null);
        }
    }
    private IEnumerator loadPeopleConfig(string peopleConfigUrl)
    {
        WWW www = CacheWWW.Get(peopleConfigUrl);

        yield return(www);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(www.text);

        XmlNodeList people = xmlDoc.SelectNodes("/people/person");

        foreach (XmlNode person in people)
        {
            string personUrl = Misc.xmlString(person.Attributes.GetNamedItem("href"));
            yield return(loadPersonConfig(personUrl));
        }
    }
    private IEnumerator loadMissionConfig(string peopleConfigUrl)
    {
        WWW www = CacheWWW.Get(peopleConfigUrl);

        yield return(www);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(www.text);

        XmlNode mission = xmlDoc.SelectSingleNode("/mission");

        yield return(MissionConfig.LoadConfig(mission));

        buildMission();

        pauseGame();
    }
Example #4
0
    private IEnumerator focusCountry(string code)
    {
        countryFocused = true;
        hoveredCountry.onUnfocused();
        float endTime = Time.time + Country.focusTimeMax;

        // Start loading cities
        WWW www = CacheWWW.Get(Game.endpointBaseUrl + Game.citiesMetaDataRelativeUrl + Game.countryCodeDataQuerystringPrefix + code);

        // Reset zoom
        yield return(CameraHandler.ResetZoom());

        // Fade out other countries
        fadeAllCountries(true, code);

        // "Smart zoom" selected country
        Rect    countryRect   = hoveredCountry.rect;
        float   countrySize   = Mathf.Max(countryRect.width / Misc.GetWidthRatio(), countryRect.height / Misc.GetHeightRatio());
        Vector3 countryCenter = hoveredCountry.countryCenter;

        zoomSize = countrySize / 2f + MAX_CAMERA_SIZE / 120f;
        CameraHandler.ZoomToSizeAndMoveToPointThenSetNewMinMaxZoomAndCenter(zoomSize, countryCenter, FOCUSED_COUNTRY_ZOOM_FACTOR);

        // Make sure cities data is loaded before parsing cities data
        yield return(www);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(www.text);

        // Parse cities and place them out
        Cities cities = new Cities(xmlDoc);

        createCities(cities, code, zoomSize);
        setVisibleCitiesLevel(1);

        // If any time is left before country have finished it's unfocus - wait a bit
        float timeLeft = endTime - Time.time;

        if (timeLeft > 0)
        {
            yield return(new WaitForSeconds(timeLeft));
        }
    }
Example #5
0
    private IEnumerator loadLevels(string levelListUrl)
    {
        string loadingSpinnerId = levelType == LEVEL_TYPES.CUSTOM ? "custom-levels" : "bundled-levels";

        LoadingSpinner.StartSpinner(loadingSpinnerId);

        WWW www = CacheWWW.Get(levelListUrl);

        yield return(www);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(www.text);

        levels = new Levels(xmlDoc);

        LoadingSpinner.StopSpinner(loadingSpinnerId);

        updateLevelGameObjects();
    }
Example #6
0
//	https://github.com/fiorix/freegeoip/releases (need https://golang.org?)
    public static IEnumerator getGeoLocation()
    {
        WWW www = CacheWWW.Get(Game.endpointBaseUrl + Game.getLocationRelativeUrl);

        yield return(www);

        XmlDocument xmlDoc = new XmlDocument();

//        System.IO.StringReader stringReader = new System.IO.StringReader(www.text);
//        stringReader.Read(); // skip BOM
//        System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stringReader);

//        string content = System.IO.File.ReadAllText( www.text );
        if (!www.text.Contains("ECONNREFUSED"))
        {
              xmlDoc.LoadXml(www.text);

            Game.instance.lat         = Convert.ToSingle(xmlDoc.SelectSingleNode("/geoData/lat").InnerText);
            Game.instance.lon         = Convert.ToSingle(xmlDoc.SelectSingleNode("/geoData/lon").InnerText);
            Game.instance.countryCode = Convert.ToString(xmlDoc.SelectSingleNode("/geoData/countryCode").InnerText);
            Game.instance.country     = Convert.ToString(xmlDoc.SelectSingleNode("/geoData/country").InnerText);
        }
    }
    public IEnumerator loadPersonConfig(string personConfigUrl)
    {
        WWW www = CacheWWW.Get(personConfigUrl);

        yield return(www);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(www.text);

        // Load Texture for passport photo that belongs to this config
        string photoUrl = Misc.xmlString(xmlDoc.SelectSingleNode("/person").Attributes.GetNamedItem("photo"));
        WWW    photoWWW = CacheWWW.Get(photoUrl);

        yield return(photoWWW);

        Texture2D passportTexture = new Texture2D(350, 389);

        photoWWW.LoadImageIntoTexture(passportTexture);

        peopleConfigs.Add(xmlDoc);
        passportTextures.Add(passportTexture);
    }
    // cacheTimeMs = 0 means no cache time (expire directly) - default (-1) means to read the response and get specific header with timeout
    public static WWW Get(string url, long cacheTimeMs = -1)
    {
        WWW www;

        if (cacheTimeMs != 0 && CacheWWW.HasValidCache(url))
        {
//            UnityEngine.Debug.Log("CACHED");
            www = Cache[url].www;
        }
        else
        {
//            UnityEngine.Debug.Log("NOT CACHED");
            WWWrapper wwwrapper = new WWWrapper(url, cacheTimeMs);
            Cache.Add(url, wwwrapper);
            www = wwwrapper.www;

            if (cacheTimeMs == -1)
            {
                // Read header in response and use as cachetime
                Singleton <SingletonInstance> .Instance.StartCoroutine(updateWWWrapperWithCacheOnResponse(wwwrapper));
            }
        }
        return(www);
    }
Example #9
0
    private IEnumerator loadImage(Level level)
    {
        WWW www = CacheWWW.Get(level.iconUrl);

        yield return(www);

        Texture2D materialTexture = new Texture2D(256, 256);

        www.LoadImageIntoTexture(materialTexture);

        Sprite imageSprite = Sprite.Create(materialTexture, new Rect(0, 0, 256, 256), Vector3.zero);

        Image image = GetComponent <Image> ();

        image.sprite = imageSprite;

        // Flag icon
        string     countryCode = level.countryCode;
        GameObject flag        = Misc.FindDeepChild(transform, "flag").gameObject;
        RawImage   flagImage   = flag.GetComponent <RawImage>();

        flagImage.texture = Misc.getCountryFlag(countryCode);
        flagImage.color   = Color.white;
    }
Example #10
0
    public static IEnumerator <WWW> Init()
    {
        LoadLocalMaterials();

        // Ensure list of downloaded materials
        if (!Directory.Exists(downloadedMaterialsFolder))
        {
            Directory.CreateDirectory(downloadedMaterialsFolder);
            string listInitData = "# Type|ID-Name.png|width|height\n";
            File.AppendAllText(downloadedMaterialsFolder + "list.txt", listInitData);
        }

        WWW downloadedMaterialsList = CacheWWW.Get(localMaterialBaseUrl + "list.txt", Misc.getTsForReadable("1m"));

        yield return(downloadedMaterialsList);

        GetListOfRemoteMaterials(downloadedMaterialsList, false);

        WWW remoteMaterialsList = CacheWWW.Get(remoteMaterialBaseUrl + "list.txt");

        yield return(remoteMaterialsList);

        GetListOfRemoteMaterials(remoteMaterialsList);
    }
Example #11
0
    public IEnumerator getCountryData()
    {
        // Get country metadata
        WWW www = CacheWWW.Get(Game.endpointBaseUrl + Game.countryMetaDataRelativeUrl);

        yield return(www);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(www.text);

        XmlNodeList countries = xmlDoc.SelectNodes("/countries/country");
        int         numLeft   = countries.Count;

        foreach (XmlNode country in countries)
        {
            // TODO - Remove debug log - and to break after a few
            Debug.Log(numLeft--);
//            if (numLeft < 227) {
//                break;
//            }

            XmlAttributeCollection countryAttributes = country.Attributes;

            string code = Misc.xmlString(countryAttributes.GetNamedItem("code"));
            string name = Misc.xmlString(countryAttributes.GetNamedItem("name"));
            // TODO
//            string code = "ZA";
//            string name = "South Africa";

            // Country parent
            GameObject countryParent = new GameObject(name);
            Country    countryObj    = countryParent.AddComponent <Country> ();
            countryObj.countryName         = name;
            countryObj.code                = code;
            countryObj.tag                 = "Country";
            countryParent.transform.parent = transform;

            // Landarea parent
            GameObject landareaParent = new GameObject("Land");
            landareaParent.transform.parent = countryParent.transform;

            // Get country full outline data
            WWW countryWWW = CacheWWW.Get(Game.endpointBaseUrl + Game.countryMetaDataRelativeUrl + Game.countryCodeDataQuerystringPrefix + code);
            yield return(countryWWW);

            XmlDocument countryDataDoc = new XmlDocument();
            countryDataDoc.LoadXml(countryWWW.text);

            XmlNodeList polygons   = countryDataDoc.SelectNodes("/country/polygons/polygon");
            int         outerIndex = 0;
            int         innerIndex = 0;
            foreach (XmlNode polygon in polygons)
            {
                // Outer coordinates
                List <Vector3> outerCoordinates = new List <Vector3>();
                yield return(getCoordinates(polygon, "outer", outerCoordinates));

                if (outerCoordinates.Count > 0)
                {
                    GameObject outerPart = MapSurface.createPlaneMeshForPoints(outerCoordinates);
                    outerPart.name             = "Outer" + outerIndex++;
                    outerPart.transform.parent = landareaParent.transform;
                    countryObj.addCoords(outerCoordinates);
                }

                // Inner coordinates
                List <Vector3> innerCoordinates = new List <Vector3>();
                yield return(getCoordinates(polygon, "inner", innerCoordinates));

                if (innerCoordinates.Count > 0)
                {
                    GameObject innerPart = MapSurface.createPlaneMeshForPoints(innerCoordinates);
                    innerPart.name                    = "Inner" + innerIndex++;
                    innerPart.transform.parent        = landareaParent.transform;
                    innerPart.transform.localPosition = new Vector3(innerPart.transform.localPosition.x, innerPart.transform.localPosition.y, innerPart.transform.localPosition.z - 0.1f);
                    countryObj.addCoords(innerCoordinates, false);
                }
            }

            // Country name
            GameObject countryNameContainerInstance = Instantiate(countryNameContainer, countryObj.transform) as GameObject;
            TextMesh   countryNameTextMesh          = countryNameContainerInstance.GetComponentInChildren <TextMesh> ();
            countryNameTextMesh.text = name;
            countryObj.setupDone();
            countryObj.saveMeshes();

//            break; // TODO
        }

        analyzeAndMergeInners();


        Debug.Log("Done!");
    }