示例#1
0
    public static ConstructionBehaviour CreateConstructionBehaviour(ConstructionData constructionData)
    {
        ConstructionBehaviour constructionBehaviour = Instantiate(constructionData.Prefab).AddComponent <ConstructionBehaviour>();

        constructionBehaviour.Initialize(constructionData, constructionBehaviour.GetComponent <IConstructable>());
        return(constructionBehaviour);
    }
示例#2
0
    void OnConstructionCancelation()
    {
        ReturnConstructionToPool(_currentStructureBehaviour.gameObject);

        _currentStructureBehaviour = null;
        _gameManager.Interaction   = GameManager.InteractionMode.NoSelection;
        _gameManager.Input.SetInGameLayout();
    }
示例#3
0
 public void StartPlacement(ConstructionData constructionData)
 {
     if (!IsInvoking())
     {
         _constructionBehaviour = CreateConstructionBehaviour(constructionData);
         InvokeRepeating(nameof(Routine), 0, Constant.DEFAULT_REFRESH_RATE);
     }
 }
示例#4
0
    void SetBlueprintedCurrentConstrution(GameObject gameObject)
    {
        _currentStructurePlacement = gameObject;

        ConstructionBehaviour constructionBehaviour = gameObject.GetComponent <ConstructionBehaviour>();

        constructionBehaviour.ResetToBlueprint();
        _currentStructureBehaviour = constructionBehaviour;
    }
示例#5
0
    // Callbacks
    void OnConstructionConfirmation()
    {
        ConstructConfirmationCount(_currentStructureBehaviour);

        _currentStructureBehaviour.Activate(OnStructureClick);
        _currentStructureBehaviour = null;
        _gameManager.Interaction   = GameManager.InteractionMode.NoSelection;
        _gameManager.Input.SetInGameLayout();

        _gameManager.Enemies.MapChanged();
    }
示例#6
0
    void OnDestroyConfirmation(GameObject gameObject)
    {
        Type constructionType = ReturnConstructionToPool(gameObject);

        DestructionConfirmationCount(constructionType);

        _currentStructureBehaviour = null;
        _gameManager.Interaction   = GameManager.InteractionMode.NoSelection;

        _gameManager.Input.SetInGameLayout();

        _gameManager.Enemies.MapChanged();
    }
示例#7
0
 void ConstructConfirmationCount(ConstructionBehaviour script)
 {
     if (script.GetType() == typeof(TowerBehaviour))
     {
         if (_towerPool.Available <= 0)
         {
             _gameManager.Input.SetVisibilityTowerButton(false);
         }
     }
     else   // WallBehaviour
     {
         if (_wallPool.Available <= 0)
         {
             _gameManager.Input.SetVisibilityWallButton(false);
         }
     }
 }
示例#8
0
            /// <summary>
            /// Place an object unto the map based on the available areas.
            /// </summary>
            /// <param name="constructionData"></param>
            public void Construct(ConstructionData constructionData)
            {
                ConstructionBehaviour constructionBehaviour = Foreman.CreateConstructionBehaviour(constructionData);
                ObjectBehaviour       objectBehaviour       = constructionBehaviour.GetComponent <ObjectBehaviour>();

                objectBehaviour.Initialize();

                bool        placed    = false;
                List <Area> splitArea = new List <Area>();
                int         count     = _availableAreas.Count;

                while (count > 0)
                {
                    // Generate a random index to check if the areas is ok.
                    int i = Random.Range(0, _availableAreas.Count);
                    if (_availableAreas[i].ObstacleCanFitInTheArea(objectBehaviour.Obstacle, out bool rotate))
                    {
                        Debug.Log("The obstacle " + objectBehaviour.Obstacle.Size + " can fit in: " + _availableAreas[i] + " with rotation: " + rotate);

                        // If the Obstacle fits if the area is rotated, rotate it.
                        if (rotate)
                        {
                            constructionBehaviour.Rotate();
                        }

                        // Remove the obstacle from the area.
                        if (Area.RemoveObstacleFromArea(_availableAreas[i], objectBehaviour.Obstacle, ref splitArea))
                        {
                            Vector3 origin    = Map.GetMapOriginInWorldPos(_encampment.Map, _encampment.transform.position);
                            Vector3 objectPos = new Vector3(_availableAreas[i].Origin.x, 0, _availableAreas[i].Origin.y);
                            Vector3 pos       = objectPos + origin + (new Vector3(_availableAreas[i].Size.x, 0, _availableAreas[i].Size.y) / 2);

                            // TODO get height at position on terrain.
                            constructionBehaviour.transform.position = pos;

                            if (!_encampment.Map.IsPositionValid(objectBehaviour.Obstacle, _encampment))
                            {
                                break;
                            }


                            objectBehaviour.RegisterZone(_encampment);
                            constructionBehaviour.StartConstruction();

                            _availableAreas.Remove(_availableAreas[i]);
                            RegisterAreas(splitArea);
                            placed = true;
                            break;
                        }
                        else
                        {
                            throw new UnityException("It should work.");
                        }
                    }
                    else
                    {
                        Debug.Log("The obstacle " + objectBehaviour.Obstacle.Size + " cannot fit in: " + _availableAreas[i]);
                    }
                    count--;
                }

                if (!placed)
                {
                    Destroy(constructionBehaviour.gameObject);
                }
            }
示例#9
0
 public ConstructArguments(ConstructionBehaviour constructionBehaviour)
 {
     ConstructionBehaviour = constructionBehaviour;
 }
示例#10
0
    void UpdateCurrentStructure(GameManager.InteractionMode currentState, GameManager.InteractionMode nextState)
    {
        if (nextState == GameManager.InteractionMode.NoSelection)
        {
            if (_currentStructurePlacement != null)
            {
                switch (currentState)
                {
                case GameManager.InteractionMode.TowerSelection:
                    _towerPool.ReturnInstance(_currentStructurePlacement);
                    _currentStructurePlacement = null;
                    _currentStructureBehaviour = null;
                    break;

                case GameManager.InteractionMode.WallSelection:
                    _wallPool.ReturnInstance(_currentStructurePlacement);
                    _currentStructurePlacement = null;
                    _currentStructureBehaviour = null;
                    break;
                }
            }
        }
        else
        {
            // Return old
            switch (currentState) // Important - there is a validation in GameManager Interaction setter that checks if the current and next are the same
            {
            case GameManager.InteractionMode.TowerSelection:
                if (nextState != GameManager.InteractionMode.ConstructionConfirmation)
                {
                    _towerPool.ReturnInstance(_currentStructurePlacement);
                }
                break;

            case GameManager.InteractionMode.WallSelection:
                if (nextState != GameManager.InteractionMode.ConstructionConfirmation)
                {
                    _wallPool.ReturnInstance(_currentStructurePlacement);
                }
                break;

            case GameManager.InteractionMode.ConstructionConfirmation:
                ReturnConstructionToPool(_currentStructureBehaviour.gameObject);
                _gameManager.Input.SetInGameLayout();
                break;

            case GameManager.InteractionMode.DestructionConfirmation:
                _gameManager.Input.SetInGameLayout();
                break;
            }

            // Get new
            switch (nextState)
            {
            case GameManager.InteractionMode.TowerSelection:
                SetBlueprintedCurrentConstrution(_towerPool.GetInstance());
                break;

            case GameManager.InteractionMode.WallSelection:
                SetBlueprintedCurrentConstrution(_wallPool.GetInstance());
                break;
            }
        }
        _mode = nextState;
    }