Esempio n. 1
0
    protected override void BuildAfterLoad(WorldMapData data)
    {
        foreach (CityData cityData in data.Cities)
        {
            GameObject go   = Instantiate(cityPrefab) as GameObject;
            City       city = go.AddComponent <City>();

            city.transform.SetParent(worldMapObject.transform, false);
            city.Load(cityData);

            if (!AddCity(city, cityData.CityNum))
            {
                continue;
            }
        }

        foreach (PathData pathData in data.Paths)
        {
            if (!UpdateCityNeighbors(pathData.connection))
            {
                continue;
            }

            GameObject go = Instantiate(pathPrefab) as GameObject;
            go.transform.SetParent(worldMapObject.transform);
            WayPath path = go.AddComponent <WayPath>();
            path.prefab = pathPrefab;
            path.LoadPathInEditor(pathData);
            pathTable.Add(pathData.connection, path);
        }
    }
Esempio n. 2
0
    public void CreateNewPath(int dest1, int dest2, int numOfNodesBtn, Color c)
    {
        if (!CheckConnectionValid(new Vector2(dest1, dest2)))
        {
            Debug.LogError("Invalid path connection");
            return;
        }

        int smallerNum = dest1 < dest2? dest1:dest2;
        int biggerNum  = dest1 > dest2? dest1: dest2;

        Point connection = new Point(smallerNum, biggerNum);

        if (pathTable.ContainsKey(connection))
        {
            Debug.Log("Path already exists.");
            return;
        }

        PathData pData = new PathData(connection);

        pData.points = CreateNodesInPath(smallerNum, biggerNum, numOfNodesBtn);
        pData.c      = c;

        GameObject go = Instantiate(pathPrefab) as GameObject;

        go.transform.SetParent(worldMapObject.transform, false);

        WayPath path = go.AddComponent <WayPath>();

        path.prefab = nodePrefab;
        path.LoadPathInEditor(pData);
        pathTable.Add(pData.connection, path);
    }