Ejemplo n.º 1
0
        private void CreateBuildings(JSONObject mapData, Vector2 worldCenter)
        {
            //filter to just polygons
            foreach (var geo in mapData["features"].list.Where(x => x["geometry"]["type"].str == "Polygon"))
            {
                var buildIngNameOBJ = geo["properties"]["name"]; //.str == "G1"
                var buildingNameStr = "";
                if (!ReferenceEquals(buildIngNameOBJ, null))
                {
                    buildingNameStr = buildIngNameOBJ.str;
                    if (buildingNameStr == "G1")
                    {
                        Debug.Log("Stop");
                    }
                }

                //convert and add points
                var l = new List <Vector3>();
                for (int i = 0; i < geo["geometry"]["coordinates"][0].list.Count - 1; i++)
                {
                    var c  = geo["geometry"]["coordinates"][0].list[i];
                    var bm = GM.LatLonToMeters(c[1].f, c[0].f);
                    var pm = new Vector2(bm.x - Rect.center.x, bm.y - Rect.center.y);
                    l.Add(pm.ToVector3xz());
                }
                //make them buildings
                try
                {
                    var center = l.Aggregate((acc, cur) => acc + cur) / l.Count;
                    if (!BuildingDictionary.ContainsKey(center))
                    {
                        var bh = new BuildingHolder(center, l);
                        for (int i = 0; i < l.Count; i++)
                        {
                            l[i] = l[i] - bh.Center;
                        }
                        BuildingDictionary.Add(center, bh);

                        var m = bh.CreateModel(BuildingMaterial);
                        m.name                    = "building " + buildingNameStr;
                        m.transform.parent        = this.transform;
                        center                    = new Vector3(center.x, center.y, center.z);
                        m.transform.localPosition = center;
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log(ex);
                }
            }
        }
Ejemplo n.º 2
0
    public IEnumerator LoadInGameData()
    {
        Debug.Log("Fetching Building Data . . .");
        Coroutine c1 = StartCoroutine(GetRequest("/BuildingData.json", (UnityWebRequest req) =>
        {
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error}: {req.downloadHandler.text}");
            }
            else
            {
                allBuildingData = new BuildingDictionary();

                Building[] buildings = JsonHelper.FromJson <Building>(req.downloadHandler.text);
                foreach (Building building in buildings)
                {
                    allBuildingData.Add(building.type, building);
                }

                Debug.Log("Fetching Building Data completed.\n");
            }
        }));

        Debug.Log("Fetching Quest Data  . . .");
        Coroutine c2 = StartCoroutine(GetRequest("/QuestData.json", (UnityWebRequest req) =>
        {
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error}: {req.downloadHandler.text}");
            }
            else
            {
                allQuestData           = new QuestDataDictionary();
                QuestData[] questDatas = JsonHelper.FromJson <QuestData>(req.downloadHandler.text);
                foreach (QuestData questData in questDatas)
                {
                    allQuestData.Add(questData.questID, questData);
                }
                Debug.Log("Fetching Quest Data completed.\n");
            }
        }));

        Debug.Log("Fetching Resource Data . . .");
        Coroutine c3 = StartCoroutine(GetRequest("/ResourceData.json", (UnityWebRequest req) =>
        {
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error}: {req.downloadHandler.text}");
            }
            else
            {
                allResourceData      = new ResourceDictionary();
                Resource[] resources = JsonHelper.FromJson <Resource>(req.downloadHandler.text);
                foreach (Resource resource in resources)
                {
                    allResourceData.Add(resource.Name, resource);
                }
                Debug.Log("Fetching Resource Data completed.\n");
            }
        }));

        Debug.Log("Fetching Equipment Data . . .");
        Coroutine c4 = StartCoroutine(GetRequest("/EquipmentData.json", (UnityWebRequest req) =>
        {
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error}: {req.downloadHandler.text}");
            }
            else
            {
                allEquipmentData       = new EquipmentDictionary();
                Equipment[] equipments = JsonHelper.FromJson <Equipment>(req.downloadHandler.text);
                foreach (Equipment equipment in equipments)
                {
                    allEquipmentData.Add(equipment.Name, equipment);
                }
                Debug.Log("Fetching Equipment Data completed.\n");
            }
        }));

        Debug.Log("Fetching Enemy Data  . . .");
        Coroutine c5 = StartCoroutine(GetRequest("/EnemyData.json", (UnityWebRequest req) =>
        {
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error}: {req.downloadHandler.text}");
            }
            else
            {
                allEnemyData = new List <Enemy>();
                Debug.Log("Fetching Enemy Data completed.\n");
                allEnemyData.AddRange(JsonHelper.FromJson <Enemy>(req.downloadHandler.text));
            }
        }));
        Coroutine c6 = StartCoroutine(LoadManager.Instance.GetRequest("/CharacterData.json", (UnityWebRequest req) =>
        {
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error}: {req.downloadHandler.text}");
            }
            else
            {
                allCharacterData = new List <Character.CharacterData>();
                Debug.Log("Fetching Character Data completed.\n");
                allCharacterData.AddRange(JsonHelper.FromJson <Character.CharacterData>(req.downloadHandler.text));
            }
        }));
        Coroutine c7 = StartCoroutine(LoadManager.Instance.GetRequest("/BirthMarkData.json", (UnityWebRequest req) =>
        {
            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log($"{req.error}: {req.downloadHandler.text}");
            }
            else
            {
                allBirthMarkDatas = new List <BirthMarkData>();
                Debug.Log("Fetching Character BirthMark Data completed.\n");

                BirthMarkSerializer birthMarkSerializer = new BirthMarkSerializer();

                birthMarkSerializer = JsonUtility.FromJson <BirthMarkSerializer>(req.downloadHandler.text);

                allBirthMarkDatas = birthMarkSerializer.birthMarkDatas;
            }
        }));

        Debug.Log("Now Waiting . . .");

        yield return(c1);

        yield return(c2);

        yield return(c3);

        yield return(c4);

        yield return(c5);

        yield return(c6);

        yield return(c7);

        Debug.Log("Load GameData Complete.");
    }
Ejemplo n.º 3
0
        private void CreateBuildings(JSONObject mapData, Vector2 worldCenter)
        {
            //filter to just polygons
            foreach (var geo in mapData["features"].list.Where(x => x["geometry"]["type"].str == "Polygon"))
            {
                //convert and add points

                var geocenterx = new List <float> ();
                var geocentery = new List <float> ();

                var l = new List <Vector3>();
                for (int i = 0; i < geo["geometry"]["coordinates"][0].list.Count - 1; i++)
                {
                    var c = geo["geometry"]["coordinates"][0].list[i];
                    geocenterx.Add(c [1].f);
                    geocentery.Add(c [0].f);
                    var bm = GM.LatLonToMeters(c[1].f, c[0].f);

                    //c[1].f====>33
                    var pm = new Vector2(bm.x - Rect.center.x, bm.y - Rect.center.y);
                    l.Add(pm.ToVector3xz());
                }


                try
                {
                    var center = l.Aggregate((acc, cur) => acc + cur) / l.Count;

                    float centerx = geocenterx.Sum() / geocenterx.Count;
                    float centery = geocentery.Sum() / geocentery.Count;



                    if (!BuildingDictionary.ContainsKey(center))
                    {
                        var bh = new BuildingHolder(center, l);
                        for (int i = 0; i < l.Count; i++)
                        {
                            l[i] = l[i] - bh.Center;
                        }
                        BuildingDictionary.Add(center, bh);

                        var m = bh.CreateModel();


                        if (geo["properties"]["name"] != null)
                        {
                            m.name = geo["properties"]["name"].ToString().Split('"')[1];
                        }
                        else
                        {
                            m.name = "Unknown_Building";
                        }
                        var st = m.gameObject.AddComponent <Storage>();
                        st.lat = centerx;
                        st.lng = centery;

                        //Debug.Log(m.name + " --- [" +centerx +"," + centery +"]");

                        if (geo["properties"]["height"] != null)
                        {
                            float heighttemp = float.Parse(geo["properties"]["height"].ToString());
                            m.transform.localScale = new Vector3(1, heighttemp / 16, 1);
                        }

                        m.transform.parent        = this.transform;
                        center                    = new Vector3(center.x, center.y, center.z);
                        m.transform.localPosition = center;


                        m.AddComponent <MeshCollider>();
                        m.tag = "Collider";


                        if (geo["properties"]["addr_housenumber"] != null)
                        {
                            st.adress = (geo["properties"]["addr_housenumber"].ToString().Split('\"')[1] + " " + geo["properties"]["addr_street"].ToString().Split('\"')[1]);
                        }

                        //check

//						Collider[] hitC = Physics.OverlapSphere (m.transform.position, 30);
//						for(int i = 0; i < hitC.Length;i++){
//							if(hitC[i].name != "Plane"){
//								GameObject.Destroy(m);
//								break;
//							}else{
//								Debug.Log(hitC[i].name);
//							}
//						}
                    }
                }
                catch (Exception ex)
                {
                    //Debug.Log(ex);
                }
            }
        }