コード例 #1
0
    private void GetNewPlans()
    {
        //Removing non-valid plans from existing dictionary
        Dictionary <Tile, GameObject> temp = new Dictionary <Tile, GameObject>(_tiles);

        foreach (KeyValuePair <Tile, GameObject> pair in temp)
        {
            if (_selectionArea.Contains(pair.Key.Position) == false)
            {
                pair.Value.SetActive(false);
                _jobIconsPool.Push(pair.Value);
                _tiles.Remove(pair.Key);
            }
        }
        temp.Clear();

        //Detecting new tiles where we can create a plan.
        foreach (Vector2Int position in _selectionArea.GetPositions())
        {
            Tile t = Utils.TileAt(position.x, position.y);
            if ((t is null) ||
                _tiles.ContainsKey(t) ||
                (t.Contents?.StaticObject is null && t.IsTraversable == false))
            {
                continue;
            }

            //(t.content?.staticObject != null && t.content.staticObject.GetType() != typeof(Vegetation))

            _tiles.Add(t, CreateJobIcon(t));
        }
    }
コード例 #2
0
 private void FilterTilesBySelectionArea <T>(IList <T> origin) where T : IPosition
 {
     for (int i = origin.Count - 1; i >= 0; i--)
     {
         if (_selectionArea.Contains(origin[i].Position) == false)
         {
             origin.Remove(origin[i]);
         }
     }
 }
コード例 #3
0
    private void GetNewTrees()
    {
        //Removing non-valid trees from existing dictionary
        Dictionary <Tree, GameObject> temp = new Dictionary <Tree, GameObject>(_trees);

        foreach (KeyValuePair <Tree, GameObject> pair in temp)
        {
            if (_selectionArea.Contains(pair.Key.Position) == false)
            {
                pair.Value.SetActive(false);
                _jobIconsPool.Push(pair.Value);
                _trees.Remove(pair.Key);
            }
        }
        temp.Clear();

        //Detecting new trees.
        foreach (Vector2Int position in _selectionArea.GetPositions())
        {
            Tile t = Utils.TileAt(position.x, position.y);
            if (t is null || t.Contents is null || t.Contents.StaticObject is null)
            {
                continue;
            }

            StaticObject staticObject = t.Contents.StaticObject;

            if (staticObject.GetType() != typeof(Tree) || (staticObject as Tree).HasCutJob)
            {
                continue;
            }

            if (_trees.ContainsKey(staticObject as Tree) == false)
            {
                _trees.Add(staticObject as Tree, CreateJobIcon(staticObject as Tree));
            }
        }
    }