Exemplo n.º 1
0
        protected virtual void RallyPointChanged(object model, Vector2?value)
        {
            Debug.LogError("RallyPointChanged " + value.ToString());
            ProductionBuildingModel m = (ProductionBuildingModel)model;

            if (m.Highlighted)
            {
                CreateRallyPointObject(m);
            }
        }
Exemplo n.º 2
0
        private void CreateRallyPointObject(ProductionBuildingModel model)
        {
            // Clean the previous one if it exists
            DestroyRallyPointObject();
            if (model.RallyPoint.HasValue)
            {
                _rallyPointObject = Instantiate(_rallyPointPrefab);
                _rallyPointObject.SetParent(_rectTransform.parent, false);

                var pos = _rectTransform.anchoredPosition;
                pos.x += (model.RallyPoint.Value.x - model.CoordX) * GameConstants.CellSize;

                // Subtract on the y axis to move correctly on UI space.
                pos.y -= (model.RallyPoint.Value.y - model.CoordY) * GameConstants.CellSize;

                _rallyPointObject.anchoredPosition = pos;
            }
        }
Exemplo n.º 3
0
        protected override void HighlightedChanged(object model, bool highlighted)
        {
            base.HighlightedChanged(model, highlighted);

            ProductionBuildingModel m = (ProductionBuildingModel)model;

            if (m.RallyPoint.HasValue)
            {
                if (highlighted)
                {
                    CreateRallyPointObject(m);
                }
                else
                {
                    DestroyRallyPointObject();
                }
            }
        }
Exemplo n.º 4
0
        private void OnUnitProduced(GameView sender, ProductionBuildingModel building, Type producttype)
        {
            var model = (GameModel)this._viewToModel[sender];


            var initialPlace = GridManager.Instance.GetAvailableSlotAroundRect(building.CoordX, building.CoordY, building.Width,
                                                                               building.Height,
                                                                               (building.RallyPoint.HasValue) ? (int)building.RallyPoint.Value.x : building.CoordX,
                                                                               (building.RallyPoint.HasValue) ? (int)building.RallyPoint.Value.y : building.CoordY);

            if (initialPlace.HasValue)
            {
                var soldier = EntityFactory.CreateSoldier(sender);
                soldier.CoordX = (int)initialPlace.Value.x;
                soldier.CoordY = (int)initialPlace.Value.y;

                Debug.LogError(initialPlace);

                if (building.RallyPoint.HasValue)
                {
                    var path = GridManager.Instance.FindPath(soldier.CoordX, soldier.CoordY,
                                                             (int)building.RallyPoint.Value.x,
                                                             (int)building.RallyPoint.Value.y);

                    if (path != null)
                    {
                        soldier.Path = path;
                    }
                    else
                    {
                        Debug.LogError("Could not find a path.");
                    }
                }
                model.AddUnit(soldier);
            }
            else
            {
                Debug.LogError("There is no available spot for a soldier around the building.");
            }
        }