Ejemplo n.º 1
0
    public override GameObject InstantiateBuilding(Vector3 pos, M_GameHelper.Group group)
    {
        UnityEngine.Object prefab = Resources.Load(PATH_PREFAB + prefabName);

        GameObject   obj      = (GameObject)GameObject.Instantiate(prefab, pos, Quaternion.identity);
        BuildingProd building = obj.GetComponent <BuildingProd>();

        building.SetData(this);

        M_GameHelper.AddToGroup(obj, group);
        return(obj);
    }
Ejemplo n.º 2
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);
    }
Ejemplo n.º 3
0
    private void Generate()
    {
        GameObject groupLevel = M_GameHelper.SGetGroup(M_GameHelper.Group.LEVEL);

        if (groupLevel == null)
        {
            Debug.LogWarning("Level group does not exist! Make sure that a Level gameobject is in the Hierarchy.");
            return;
        }
        else
        {
            // Delete current terrain.
            GameObject groupTerrain = M_GameHelper.SGetGroup(M_GameHelper.Group.TERRAIN);
            if (groupTerrain == null)
            {
                Debug.LogWarning("Terrain group does not exist! Make sure that a Terrain gameobject is in the Hierarchy.");
                return;
            }

            int count = groupTerrain.transform.childCount;
            for (int i = 0; i < count; i++)
            {
                M_GameHelper.DestroyImmediate(groupTerrain.transform.GetChild(0).gameObject);
            }
        }


        m_tiles = new GameObject[m_mapW * m_mapH];

        for (int i = 0; i < m_mapW; i++)
        {
            for (int j = 0; j < m_mapH; j++)
            {
                GameObject obj = null;

                // choose a sprite for a tile
                if (i % 2 == 1)
                {
                    obj = (GameObject)PrefabUtility.InstantiatePrefab(s_tilePrefab);
                }
                else
                {
                    obj = (GameObject)PrefabUtility.InstantiatePrefab(s_tilePrefab2);
                }
                // TileData setup
                obj.GetComponent <Tile>().i    = i;
                obj.GetComponent <Tile>().j    = j;
                obj.GetComponent <Tile>().data = new DAT_Tile(false);

                // Position and name setup
                Vector3 temp = new Vector3(i * m_tileW, 0, j * m_tileH);
                if (i % 2 == 1)
                {
                    temp.z -= m_tileH / 2;
                }

                obj.transform.position = temp;
                obj.name = "obj" + i + "_" + j;

                // Apply to structures
                M_GameHelper.AddToGroup(obj, M_GameHelper.Group.TERRAIN);
                m_tiles[j * m_mapW + i] = obj;
            }
        }



        if (groupLevel != null)
        {
            groupLevel.GetComponent <Level>().tiledMap = new DAT_TiledMap(m_mapW, m_mapH, m_tiles);
            EditorUtility.SetDirty(groupLevel.GetComponent <Level>());
        }
    }