Example #1
0
 private void Start()
 {
     if (s_instance != null)
     {
         Debug.LogWarning("Only one instance allowed!");
     }
     s_instance = this;
 }
Example #2
0
 public void QuitBuilding()
 {
     if (m_tempBuildingObj != null)
     {
         m_tempBuildingComp = null;
         M_WorldUIManager.ShowSmallBuildButton(false);
         M_GameHelper.Destroy(m_tempBuildingObj);
         m_tempBuildingObj = null;
         M_MiscManager.ShowCancelButton(false);
         foreach (Tile tile in m_tilesHighlighted)
         {
             tile.Highlight(false);
         }
     }
 }
Example #3
0
    /// <summary> Function called when Building is supposed to be placed. </summary>
    private void OnBuildingBuildIconClick()
    {
        // check whether the place is not occupied.
        foreach (Tile tile in m_tilesHighlighted)
        {
            if (tile.IsOccupied())
            {
                return;
            }
        }

        UT_Pair <int, int> cost = M_BuildingManager.SGetBuildingCost(m_tempBuildingComp.GetData().id);

        // Apply cost to the resources
        M_InGameResourcesManager.SAddFood(-cost.first);
        M_InGameResourcesManager.SAddResearch(-cost.second);

        // Mark highlighted tiles as occupied
        foreach (Tile tile in m_tilesHighlighted)
        {
            tile.SetOccupied(true);
            tile.Highlight(false);
        }
        // set final building position
        Vector3 pos = m_currentMiddleTile.transform.position;

        pos.y = M_MapManager.SGetYDepthValue(pos.z);
        m_tempBuildingObj.transform.position = pos;
        // Move to the BUILDINGS group
        M_GameHelper.AddToGroup(m_tempBuildingObj, M_GameHelper.Group.BUILDINGS);

        m_tempBuildingComp.SetActionOnBuildingFinished(ActionOnBuildingFinished);
        // Start in-game building process
        m_tempBuildingComp.StartBuilding();


        m_onBuildingPlacedAction(m_tempBuildingComp);

        // reset values
        m_tempBuildingObj.GetComponent <IBuilding>().GetBuildButton().SetActive(false);
        m_tempBuildingObj   = null;
        m_tempBuildingComp  = null;
        m_currentMiddleTile = null;
        m_tilesHighlighted.Clear();
        M_MiscManager.ShowCancelButton(false);
    }
Example #4
0
    /// <summary>
    /// Starts building process.
    /// Building is supposed to be placed.
    /// </summary>
    public void StartBuilding(DAT_Building buildingData)
    {
        // prepare position (middle of a screen) and instantiate
        Vector3 pos = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, Camera.main.nearClipPlane));

        pos.y = M_MapManager.SGetHighYDepthValue(pos.z); // set appropriate depth value. (Building has to be above every other obj)
        // Instantiate new building in the TEMP group.
        m_tempBuildingObj  = buildingData.InstantiateBuilding(pos, M_GameHelper.Group.TEMP);
        m_tempBuildingComp = m_tempBuildingObj.GetComponent <IBuilding>();
        // Get build button and activate it.
        m_tempBuildingComp.GetBuildButton().GetComponent <Button>().onClick.AddListener(OnBuildingBuildIconClick);
        m_tempBuildingComp.GetBuildButton().SetActive(true);

        M_MiscManager.RemoveListenersCancelButton();
        M_MiscManager.AddListenerCancelButton(QuitBuilding);
        M_MiscManager.ShowCancelButton(true);
    }