示例#1
0
 public static void SStartBuilding(DAT_Building buildingData)
 {
     if (s_instance != null)
     {
         s_instance.StartBuilding(buildingData);
     }
 }
示例#2
0
 public void Setup(DAT_Building data)
 {
     /*
      * this.data = data;
      * this.backupData = data;
      *
      * reqFood.text = data.requiredFood.ToString();
      * reqResearch.text = data.requiredResearchPoints.ToString();
      * costFactor.text = data.costFactor.ToString();
      *
      * suppFood.text = data.foodPerDay.ToString();
      * suppResearch.text = data.researchPerDay.ToString();
      *
      * buildTime.text = data.buildingTime.ToString(); */
 }
示例#3
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);
    }
示例#4
0
    public void Setup(DAT_Building data)
    {
        buildingData      = data;
        buildingName.text = data.name;

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

        requiredFood     = cost.first;
        requiredResearch = cost.second;

        if (data != null && requiredFood <= M_InGameResourcesManager.GetFood() && requiredResearch <= M_InGameResourcesManager.GetResearchPoints())
        {
            buildButton.interactable = true;
            buildButton.image.color  = Color.green;
        }
        else
        {
            buildButton.interactable = false;
            buildButton.image.color  = Color.red;
        }
    }
示例#5
0
 public static void SShowBuildingInfo(DAT_Building data)
 {
     /*
      * if (s_instance != null)
      * {
      *  s_instance.descBuildingWare.text = data.wareType.ToString();
      *  s_instance.descBuildingName.text = data.name;
      *  s_instance.descBuildingFood.text = data.foodPerDay.ToString();
      *  s_instance.descBuildingResearch.text = data.researchPerDay.ToString();
      *
      *  List<GameObject> rows = new List<GameObject>();
      *  int i = 0;
      *  foreach (DAT_BuildingTemplate.BuildDependency dep in data.dependencies)
      *  {
      *      GameObject temp = Instantiate(s_instance.descDepRowPrefab);
      *
      *
      *      temp.GetComponent<UI_RowDependency>().Setup(M_BuildingManager.SGetDatBuilding(dep.buildingRequired).name, dep.requiredMood);
      *
      *      if (i % 2 == 0)
      *      {
      *          temp.GetComponent<Image>().color = s_instance.elemBgColorA;
      *      }
      *      else
      *      {
      *          temp.GetComponent<Image>().color = s_instance.elemBgColorB;
      *      }
      *      i++;
      *      rows.Add(temp);
      *  }
      *  GUIUtils.AddElementsToCleanYScrollContainer(s_instance.descDepContainer, rows);
      *
      *
      *
      *  s_instance.buildingDesc.SetActive(true);
      * }*/
 }
示例#6
0
    public static DAT_BuildingTemplates Parse(string filename)
    {
        List <DAT_BuildingHouse> buildingsHouse = new List <DAT_BuildingHouse>();
        List <DAT_BuildingProd>  buildingsProd  = new List <DAT_BuildingProd>();

        // load assets from "/Resources"
        TextAsset xmlAsset = Resources.Load <TextAsset>(filename);

        // Parse into xml document
        XDocument doc = XDocument.Parse(xmlAsset.text);
        // Get all elements inside building/Sheet1 tag
        IEnumerable <XElement> elems = doc.Element("building").Element("Sheet1").Elements();

        List <BuildingDependency> dependencies = new List <BuildingDependency>();

        foreach (XElement e in elems)
        {
            int                       id           = 0;
            BuildingType              type         = BuildingType.PRODUCTION;
            string                    name         = "Building";
            string                    desc         = "Here goes a description.";
            string                    prefabName   = "store";
            DAT_Ware.Type             ware         = DAT_Ware.Type.NOTHING;
            int                       prodFood     = 0;
            int                       prodResearch = 0;
            int                       suppSettlers = 0;
            int                       costFood     = 0;
            int                       costResearch = 0;
            float                     costFactor   = 1f;
            int                       buildTime    = 2;
            bool                      available    = false;
            List <BuildingDependency> tempDeps     = new List <BuildingDependency>();

            foreach (XElement prop in e.Elements())
            {
                if (prop.Name.ToString().Equals(TAG_ID))
                {
                    id = Int32.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_BUILDING_TYPE))
                {
                    string bType = prop.Value.ToUpper();
                    if (bType.Equals("HOUSE"))
                    {
                        type = BuildingType.HOUSE;
                    }
                    else if (bType.Equals("PRODUCTION"))
                    {
                        type = BuildingType.PRODUCTION;
                    }
                    else
                    {
                        type = BuildingType.PRODUCTION;
                    }
                }
                else if (prop.Name.ToString().Equals(TAG_NAME))
                {
                    name = prop.Value;
                }
                else if (prop.Name.ToString().Equals(TAG_DESC))
                {
                    desc = prop.Value;
                }
                else if (prop.Name.ToString().Equals(TAG_PREFAB))
                {
                    prefabName = prop.Value;
                }
                else if (prop.Name.ToString().Equals(TAG_WARE_TYPE))
                {
                    ware = DAT_Ware.ToType(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_PROD_FOOD))
                {
                    prodFood = Int32.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_PROD_RESEARCH))
                {
                    prodResearch = Int32.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_COST_FOOD))
                {
                    costFood = Int32.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_COST_RESEARCH))
                {
                    costResearch = Int32.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_COST_FACTOR))
                {
                    costFactor = float.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_BUILD_TIME))
                {
                    buildTime = Int32.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_AVAILABLE))
                {
                    available = Boolean.Parse(prop.Value);
                }
                else if (prop.Name.ToString().Equals(TAG_SUPP_SETTLERS))
                {
                    suppSettlers = Int32.Parse(prop.Value);
                }
                else // dependency
                {
                    string tag = prop.Name.ToString();
                    int    r;
                    if (!Int32.TryParse(prop.Value, out r))
                    {
                        continue;
                    }


                    // <dep{0}>
                    if (tag.StartsWith("dep") && !tag.EndsWith("val"))
                    {
                        int  depId = Int32.Parse(tag.Substring(3));
                        bool found = false;
                        for (int i = 0; i < tempDeps.Count; i++)
                        {
                            if (depId - 1 == i)
                            {
                                tempDeps[i].fromBuilding = Int32.Parse(prop.Value);
                                tempDeps[i].toBuilding   = id;
                                found = true;
                                break;
                            }
                        }
                        // if temp dependency wasn't created
                        if (!found)
                        {
                            tempDeps.Add(new BuildingDependency(Int32.Parse(prop.Value), id, 0));
                        }
                    }

                    // <dep{0}val>
                    if (tag.StartsWith("dep") && tag.EndsWith("val"))
                    {
                        int  depId = Int32.Parse(tag.Substring(3, tag.Length - 6));
                        bool found = false;
                        for (int i = 0; i < tempDeps.Count; i++)
                        {
                            if (depId - 1 == i)
                            {
                                tempDeps[i].reqMood = Int32.Parse(prop.Value);
                                found = true;
                                break;
                            }
                        }
                        // if temp dependency wasn't created
                        if (!found)
                        {
                            tempDeps.Add(new BuildingDependency(0, 0, Int32.Parse(prop.Value)));
                        }
                    }
                }
            }

            foreach (BuildingDependency dep in tempDeps)
            {
                dependencies.Add(dep);
            }



            switch (type)
            {
            case BuildingType.HOUSE:
            {
                DAT_BuildingHouse newBuilding = new DAT_BuildingHouse();
                newBuilding.id               = id;
                newBuilding.name             = name;
                newBuilding.desc             = desc;
                newBuilding.prefabName       = prefabName;
                newBuilding.costFood         = costFood;
                newBuilding.costResearch     = costResearch;
                newBuilding.costFactor       = costFactor;
                newBuilding.buildingTime     = buildTime;
                newBuilding.availableOnStart = available;
                newBuilding.settlersSupplied = suppSettlers;
                newBuilding.dependencies     = new List <DAT_Building.BuildDependency>();

                buildingsHouse.Add(newBuilding);
            }
            break;

            case BuildingType.PRODUCTION:
            {
                DAT_BuildingProd newBuilding = new DAT_BuildingProd();
                newBuilding.id               = id;
                newBuilding.name             = name;
                newBuilding.desc             = desc;
                newBuilding.prefabName       = prefabName;
                newBuilding.costFood         = costFood;
                newBuilding.costResearch     = costResearch;
                newBuilding.costFactor       = costFactor;
                newBuilding.buildingTime     = buildTime;
                newBuilding.availableOnStart = available;
                newBuilding.dependencies     = new List <DAT_Building.BuildDependency>();

                newBuilding.producedFood     = prodFood;
                newBuilding.producedResearch = prodResearch;
                newBuilding.producedWare     = ware;

                buildingsProd.Add(newBuilding);
            }
            break;
            }
        }

        foreach (BuildingDependency dep in dependencies)
        {
            DAT_Building temp = null;
            foreach (DAT_Building building in buildingsProd)
            {
                if (building.id == dep.fromBuilding)
                {
                    temp = building;
                    break;
                }
            }
            foreach (DAT_Building building in buildingsHouse)
            {
                if (building.id == dep.fromBuilding)
                {
                    temp = building;
                    break;
                }
            }
            if (temp == null)
            {
                Debug.Log("Incorrect dependency definition.");
                break;
            }

            DAT_Building.BuildDependency buildDependency = new DAT_Building.BuildDependency();
            buildDependency.unlocksBuilding = dep.toBuilding;
            buildDependency.requiredMood    = dep.reqMood;
            temp.dependencies.Add(buildDependency);
        }


        DAT_BuildingTemplates buildings = ScriptableObject.CreateInstance <DAT_BuildingTemplates>();

        buildings.house      = buildingsHouse;
        buildings.production = buildingsProd;

        return(buildings);
    }
示例#7
0
 /// <summary> Starts building process.
 /// Building is supposed to be placed.</summary>
 private void StartBuilding(DAT_Building buildingData)
 {
     m_buildSystem.StartBuilding(buildingData);
 }