コード例 #1
0
    /// <summary>
    /// Creates one scrollview for the selected city and one for each of the selected
    /// city's neighbors. Players will then be able to assign the units from the selected city
    /// to a neighboring city.
    /// </summary>
    void AddNeighboringCityScrollviews(City selectedCity)
    {
        DestroyAllScrollviews();

        // City selectedCity = (City) GameManager.instance.placeSelection;

        List <City> neighboringCities = selectedCity.GetNeighbors();

        UnitsScrollview selectedCitySv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        selectedCitySv.AddTitle(selectedCity.placeName);
        selectedCitySv.transform.SetParent(unitsScrollviewLayout.transform);

        // Create a new list here to prevent overriding values
        selectedCitySv.SetContent(new List <Unit>(selectedCity.occupyingUnits), CycleUnit);

        scrollviewCityPairs.Add(new ScrollviewCityPair(selectedCity, selectedCitySv));

        foreach (City neighboringCity in neighboringCities)
        {
            UnitsScrollview unitsScrollviewCopy = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);
            unitsScrollviewCopy.AddTitle("To " + neighboringCity.placeName);
            unitsScrollviewCopy.transform.SetParent(unitsScrollviewLayout.transform);
            unitsScrollviewCopy.SetContent(new List <Unit>(), CycleUnit);
            scrollviewCityPairs.Add(new ScrollviewCityPair(neighboringCity, unitsScrollviewCopy));
        }
    }
コード例 #2
0
    /// <summary>
    /// Creates one scrollview for the selected city and one for each of the selected
    /// city's neighbors. Players will then be able to assign the units from the selected city
    /// to a neighboring city.
    /// </summary>
    void CreateAttackFromCityScrollviews(City selectedCity)
    {
        DestroyAllScrollviews();

        // Get all the roads into the city
        List <Road> connectedRoads = selectedCity.GetConnectedRoads();

        // Create a scrollview of the units in the selected city
        UnitsScrollview selectedCitySv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        selectedCitySv.AddTitle(selectedCity.placeName);
        selectedCitySv.transform.SetParent(unitsScrollviewLayout.transform);

        // Populate the selected city scrollview with the current units
        selectedCitySv.SetContent(new List <Unit>(selectedCity.occupyingUnits), CycleUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedCity, selectedCitySv));

        // Create scrollviews from the neighboring roads that have
        // enemy units camped within them
        foreach (Road road in connectedRoads)
        {
            UnitsScrollview unitsScrollviewCopy = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);
            unitsScrollviewCopy.AddTitle("Camp on Via " + road.placeName);
            unitsScrollviewCopy.transform.SetParent(unitsScrollviewLayout.transform);
            unitsScrollviewCopy.SetContent(new List <Unit>(), CycleUnit);
            scrollviewPairs.Add(new ScrollviewPair(road, unitsScrollviewCopy));
        }
    }
コード例 #3
0
    /// <summary>
    /// Creates two scrollviews, one for each camp on the city.
    /// Creates two other scrollviews for the cities the road connects.
    /// </summary>
    void CreateAttackFromRoadScrollviews(Road selectedRoad)
    {
        print("City1: " + selectedRoad.city1.placeName);
        print("City2: " + selectedRoad.city2.placeName);

        /// Clear any existing scrollviews
        DestroyAllScrollviews();

        /// Creates a scrollview for the units camped near the first city

        UnitsScrollview city1CampSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city1CampSv.AddTitle("Camp near " + selectedRoad.city1.placeName);
        city1CampSv.transform.SetParent(unitsScrollviewLayout.transform);

        // Fill the city 1 camp scrollview
        // Copy units to a new list to prevent overriding values
        // TODO: Create "CycleRoadUnit" method instead of basic "CycleUnit" method.
        city1CampSv.SetContent(new List <Unit>(selectedRoad.GetEncampedUnits(selectedRoad.city1)), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city1, city1CampSv));

        // Create empty scrollviews for the first city
        // Units chosen to attack will populate the scrollview
        UnitsScrollview city1AttackingUnitsSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city1AttackingUnitsSv.AddTitle("Attack " + selectedRoad.city1.placeName);
        city1AttackingUnitsSv.transform.SetParent(unitsScrollviewLayout.transform);
        city1AttackingUnitsSv.SetContent(new List <Unit>(), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city1, city1AttackingUnitsSv));

        // Repeat process for the second city
        // This ensures the "camp" and "attacking" scrollviews will be next to each other
        UnitsScrollview city2CampSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city2CampSv.AddTitle("Camp near " + selectedRoad.city2.placeName);
        city2CampSv.transform.SetParent(unitsScrollviewLayout.transform);
        city2CampSv.SetContent(new List <Unit>(selectedRoad.GetEncampedUnits(selectedRoad.city2)), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city2, city2CampSv));

        UnitsScrollview city2AttackingUnitsSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city2AttackingUnitsSv.AddTitle("Attack " + selectedRoad.city2.placeName);
        city2AttackingUnitsSv.transform.SetParent(unitsScrollviewLayout.transform);
        city2AttackingUnitsSv.SetContent(new List <Unit>(), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city2, city2AttackingUnitsSv));

        // Pair the scrollviews
        city1ScrollviewPair = new RoadScrollviewPair(city1AttackingUnitsSv, city1CampSv);
        city2ScrollviewPair = new RoadScrollviewPair(city2AttackingUnitsSv, city2CampSv);
    }