{"__v":8,"_id":"550942e2368a5617004146d8","category":{"__v":5,"_id":"55094050961f17170070abbd","project":"543b9b0065bf840e00b473d5","version":"543b9b0065bf840e00b473d8","pages":["550942e2368a5617004146d8","550a3bca42fff40d00ae600c","550a42a342fff40d00ae6022","550a854f635c660d005280b8","554f0dfacbb3510d00a5738a"],"reference":false,"createdAt":"2015-03-18T09:07:28.587Z","from_sync":false,"order":2,"slug":"player-village","title":"Player Village"},"project":"543b9b0065bf840e00b473d5","user":"543b9aa865bf840e00b473d1","version":{"__v":11,"_id":"543b9b0065bf840e00b473d8","project":"543b9b0065bf840e00b473d5","createdAt":"2014-10-13T09:27:28.467Z","releaseDate":"2014-10-13T09:27:28.467Z","categories":["543b9b0065bf840e00b473d9","543b9ef065bf840e00b473e0","54890012f291f61400c02d36","54890902f291f61400c02d3e","54890c43f291f61400c02d44","54890d71c178b40b00aa3086","5508125c0c4d8c19008a5f83","55094050961f17170070abbd","550945111c38c50d006118ad","550a4c2e42fff40d00ae6049","55221c074801a40d00a77610"],"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"createdAt":"2015-03-18T09:18:26.417Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"GetBuildingsXML()\"\n}\n[/block]\nReads Buildings.xml\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"UpdatePrices()\"\n}\n[/block]\nUpdates price labels on building buttons\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"OnBuild0() -  OnBuild10()\"\n}\n[/block]\nReceives a NGUI button message to build\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"OnReselect0() -  OnReselect10()\"\n}\n[/block]\nReceives a 2D Toolkit button message to select an existing building; the button is in the middle of each building prefab and is invisible \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"SelectObject()\"\n}\n[/block]\n- After the grass/building prefabs are instantiated, they must be selected from the existing buildings on the map\n- Activates the BuildingSelectedPanel – the move/upgrade/place/cancel, at the bottom of the screen\n- Finds all existing buildings with the appropriate string tag (ex \"Forge\")\n- Finds all grass (both the grass and buildings are instantiated with the isSelected bool variable as true; this allows us to find them on the map, as being the new/latest ones)\n- Determines the exact grass patch and building\n- Activates the moving pad, moves everything to the right grid position and parents them appropriately \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"LoadBuilding()\"\n}\n[/block]\n- Occupies one dobbit\n- Pauses other input- the user starts moving the building with the arrows\n- Pivot correction true/false is used to center the building on the grid, if necessary\n- Instantiates the building + appropriate underlying grass patch\n- If the building produces resources, the productionRates is passed to Stats; this will be saved later, because SaveLoad does not read the building XML\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"VerifyConditions()\"\n}\n[/block]\n- Exceeds max number of buildings / enough gold/mana/free dobbits to build?\n- Pays the price to stats\n- Updates the Stats interface numbers\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"DecreaseStorage()\"\n}\n[/block]\n - When a building is reselected and destroyed, the gold/mana storage capacity decrease; not necessary for cancelled construction, since the storage capacity is incremented only when the construction is finished.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"CancelObject()\"\n}\n[/block]\n- Cancels new construction; refunds gold/mana to Stats; frees dobbit\n- Destroys existing building; decreases gold/mana storage capacity\n- Updates the interface\n- Destroys the associated grass patch (they are paired by the same building/grass index)\n- Deactivates MovingPad/StatsPanel\n- Deactivates the BuildingSelectedPanel – the move/upgrade/place/cancel, at the bottom of the screen\n- Deactivates Relay pauseInput\n- Decreases the existingBuildings array element seen in the saved text file: \n - The array looks like {0,0,5,0,0...} with 12 elements for 12 buildings types.\n - If you build 1 Academy for example which is array item #1 then, the code would be existingBuildings[0] +=1\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Buildings Group\"\n}\n[/block]\nUsed as parent for grouping all buildings after they are instantiated.\n\n**_MovingPad **\n\nThe 4 arrow platform used to move buildings; when a building is created/selected, it is activated and becomes parent for the building; the move messages are sent to BuildingCreator.cs\n\n**_StatsPad**\n\nThe small pop-up building displaying info for the building when it is selected.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://www.filepicker.io/api/file/iK5mZNlJSNafd3Q7GY3z\",\n        \"buildings.jpg\",\n        \"800\",\n        \"600\",\n        \"#6894ce\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Variables\"\n}\n[/block]\nEach of the other columns should become a the parameters to be added to the object class constructor.\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"*id*\",\n    \"0-1\": \"(string)\",\n    \"1-1\": \"(string)\",\n    \"0-2\": \"is the object id\",\n    \"1-2\": \"is the object name that will appear on screen if the object is selected\",\n    \"2-2\": \"the description of the object\",\n    \"3-2\": \"the type of the object\",\n    \"4-2\": \"the number of buildings that could be built or upgraded at the same time\\nOnly the first builder can be bought with soft currency, the other have to be bought spending crystals\",\n    \"1-0\": \"*name*\",\n    \"2-0\": \"*description*\",\n    \"2-1\": \"(string)\",\n    \"3-0\": \"*type*\",\n    \"3-1\": \"(type)\",\n    \"4-0\": \"*builder_pop*\",\n    \"4-1\": \"(int)\",\n    \"5-1\": \"(int)\",\n    \"6-1\": \"(float)\",\n    \"8-1\": \"(int)\",\n    \"9-1\": \"(int)\",\n    \"10-1\": \"(string)\",\n    \"11-1\": \"(int)\",\n    \"12-1\": \"(bool)\",\n    \"13-1\": \"(int)\",\n    \"14-1\": \"(store_type)\",\n    \"15-1\": \"(string)\",\n    \"16-1\": \"(int)\",\n    \"17-1\": \"(int)\",\n    \"18-1\": \"(string)\",\n    \"19-1\": \"(int)\",\n    \"20-1\": \"(int)\",\n    \"21-1\": \"(int)\",\n    \"22-1\": \"(int)\",\n    \"23-1\": \"(int)\",\n    \"24-1\": \"(int)\",\n    \"25-1\": \"(int)\",\n    \"26-1\": \"(string)\",\n    \"27-1\": \"(string)\",\n    \"5-0\": \"*pop_bonus*\",\n    \"5-2\": \"POPULATION BUILDINGS - the number to be added to the max population\",\n    \"6-2\": \"PRODUCTION BUILDINGS - the amount of the resource generated per second\",\n    \"7-1\": \"(int)\",\n    \"6-0\": \"*production_per_sec*\",\n    \"7-0\": \"*store_capacity*\",\n    \"8-0\": \"*max_cap*\",\n    \"9-0\": \"*pop_unit_weight*\",\n    \"10-0\": \"*time*\",\n    \"11-0\": \"*xp_award*\",\n    \"12-0\": \"*gold_based*\",\n    \"13-0\": \"*resource_cost*\",\n    \"14-0\": \"*store_category*\",\n    \"15-0\": \"*obj_prereq*\",\n    \"16-0\": \"*cap_x_prereq*\",\n    \"17-0\": \"*x_upgrade_lev_req*\",\n    \"18-0\": \"*x_upgrade_obj_req*\",\n    \"19-0\": \"*x_upgrade_cost*\",\n    \"20-0\": \"*x_upgrade_time*\",\n    \"21-0\": \"*x_upgrade_xp_award*\",\n    \"22-0\": \"*lev_x_store_capacity*\",\n    \"23-0\": \"*lev_x_production*\",\n    \"24-0\": \"*lev_x_pop_bonus*\",\n    \"25-0\": \"*grid_size*\",\n    \"26-0\": \"*object_graphic*\",\n    \"27-0\": \"*store_graphic*\",\n    \"27-2\": \"The graphic that appear on the UI store\",\n    \"26-2\": \"The graphic that appear on the screen\",\n    \"25-2\": \"BUILDINGS - every buildings is squared, so we have just one value. If the valus is 3 the building is 3x3. If for then 4x4 and so on.\",\n    \"24-2\": \"POPULATION BUILDINGS - the number to be added to the max population granted by the upgraded building (its not cumulative with the previous levels)\",\n    \"23-2\": \"PRODUCTION BUILDINGS - the amount of the resource generated per second of the upgraded building (its not cumulative with the previous levels)\",\n    \"22-2\": \"PRODUCTION & STORAGE BUILDINGS the store capacity of the upgraded building (its not cumulative with the previous levels)\",\n    \"21-2\": \"BUILDINGS - XP awarded for the upgrade of an object\",\n    \"20-2\": \"BUILDINGS - This is the amount of time (in minutes) that have to pass to upgrade the building\",\n    \"19-2\": \"BUILDINGS - This is the amount of resources to be spent to upgrade the building\",\n    \"18-2\": \"BUILDINGS - These are the objects required to upgrade a type of building (x is the level of the building)\",\n    \"17-2\": \"BUILDINGS - This is the level required to upgrade a type of building (x is the level of the building)\",\n    \"15-2\": \"The object that the player have to create before he can create this object\",\n    \"14-2\": \"The category where to put the object on the store\",\n    \"13-2\": \"The quantity of the resource to create the building\",\n    \"12-2\": \"To check which resource is needed to complete this kind of building\",\n    \"11-2\": \"XP awarded for the completion of an object\",\n    \"10-2\": \"the time (in minutes) needed to create the building\",\n    \"9-2\": \"UNITS - how many population slot occupies the unit\",\n    \"8-2\": \"BUILDINGS - max number of building allowed\",\n    \"7-2\": \"PRODUCTION & STORAGE BUILDINGS - the total amount of resource storage added by that building\",\n    \"16-2\": \"BUILDINGS - This is the level needed to create x building type (x is a number from 1 to 5.)\"\n  },\n  \"cols\": 3,\n  \"rows\": 28\n}\n[/block]","excerpt":"Information regarding the Unity C# script controlling buildings.","slug":"buildingcreatorcs","type":"basic","title":"BuildingCreator.cs"}

BuildingCreator.cs

Information regarding the Unity C# script controlling buildings.

[block:api-header] { "type": "basic", "title": "GetBuildingsXML()" } [/block] Reads Buildings.xml [block:api-header] { "type": "basic", "title": "UpdatePrices()" } [/block] Updates price labels on building buttons [block:api-header] { "type": "basic", "title": "OnBuild0() - OnBuild10()" } [/block] Receives a NGUI button message to build [block:api-header] { "type": "basic", "title": "OnReselect0() - OnReselect10()" } [/block] Receives a 2D Toolkit button message to select an existing building; the button is in the middle of each building prefab and is invisible [block:api-header] { "type": "basic", "title": "SelectObject()" } [/block] - After the grass/building prefabs are instantiated, they must be selected from the existing buildings on the map - Activates the BuildingSelectedPanel – the move/upgrade/place/cancel, at the bottom of the screen - Finds all existing buildings with the appropriate string tag (ex "Forge") - Finds all grass (both the grass and buildings are instantiated with the isSelected bool variable as true; this allows us to find them on the map, as being the new/latest ones) - Determines the exact grass patch and building - Activates the moving pad, moves everything to the right grid position and parents them appropriately [block:api-header] { "type": "basic", "title": "LoadBuilding()" } [/block] - Occupies one dobbit - Pauses other input- the user starts moving the building with the arrows - Pivot correction true/false is used to center the building on the grid, if necessary - Instantiates the building + appropriate underlying grass patch - If the building produces resources, the productionRates is passed to Stats; this will be saved later, because SaveLoad does not read the building XML [block:api-header] { "type": "basic", "title": "VerifyConditions()" } [/block] - Exceeds max number of buildings / enough gold/mana/free dobbits to build? - Pays the price to stats - Updates the Stats interface numbers [block:api-header] { "type": "basic", "title": "DecreaseStorage()" } [/block] - When a building is reselected and destroyed, the gold/mana storage capacity decrease; not necessary for cancelled construction, since the storage capacity is incremented only when the construction is finished. [block:api-header] { "type": "basic", "title": "CancelObject()" } [/block] - Cancels new construction; refunds gold/mana to Stats; frees dobbit - Destroys existing building; decreases gold/mana storage capacity - Updates the interface - Destroys the associated grass patch (they are paired by the same building/grass index) - Deactivates MovingPad/StatsPanel - Deactivates the BuildingSelectedPanel – the move/upgrade/place/cancel, at the bottom of the screen - Deactivates Relay pauseInput - Decreases the existingBuildings array element seen in the saved text file: - The array looks like {0,0,5,0,0...} with 12 elements for 12 buildings types. - If you build 1 Academy for example which is array item #1 then, the code would be existingBuildings[0] +=1 [block:api-header] { "type": "basic", "title": "Buildings Group" } [/block] Used as parent for grouping all buildings after they are instantiated. **_MovingPad ** The 4 arrow platform used to move buildings; when a building is created/selected, it is activated and becomes parent for the building; the move messages are sent to BuildingCreator.cs **_StatsPad** The small pop-up building displaying info for the building when it is selected. [block:image] { "images": [ { "image": [ "https://www.filepicker.io/api/file/iK5mZNlJSNafd3Q7GY3z", "buildings.jpg", "800", "600", "#6894ce", "" ] } ] } [/block] [block:api-header] { "type": "basic", "title": "Variables" } [/block] Each of the other columns should become a the parameters to be added to the object class constructor. [block:parameters] { "data": { "0-0": "*id*", "0-1": "(string)", "1-1": "(string)", "0-2": "is the object id", "1-2": "is the object name that will appear on screen if the object is selected", "2-2": "the description of the object", "3-2": "the type of the object", "4-2": "the number of buildings that could be built or upgraded at the same time\nOnly the first builder can be bought with soft currency, the other have to be bought spending crystals", "1-0": "*name*", "2-0": "*description*", "2-1": "(string)", "3-0": "*type*", "3-1": "(type)", "4-0": "*builder_pop*", "4-1": "(int)", "5-1": "(int)", "6-1": "(float)", "8-1": "(int)", "9-1": "(int)", "10-1": "(string)", "11-1": "(int)", "12-1": "(bool)", "13-1": "(int)", "14-1": "(store_type)", "15-1": "(string)", "16-1": "(int)", "17-1": "(int)", "18-1": "(string)", "19-1": "(int)", "20-1": "(int)", "21-1": "(int)", "22-1": "(int)", "23-1": "(int)", "24-1": "(int)", "25-1": "(int)", "26-1": "(string)", "27-1": "(string)", "5-0": "*pop_bonus*", "5-2": "POPULATION BUILDINGS - the number to be added to the max population", "6-2": "PRODUCTION BUILDINGS - the amount of the resource generated per second", "7-1": "(int)", "6-0": "*production_per_sec*", "7-0": "*store_capacity*", "8-0": "*max_cap*", "9-0": "*pop_unit_weight*", "10-0": "*time*", "11-0": "*xp_award*", "12-0": "*gold_based*", "13-0": "*resource_cost*", "14-0": "*store_category*", "15-0": "*obj_prereq*", "16-0": "*cap_x_prereq*", "17-0": "*x_upgrade_lev_req*", "18-0": "*x_upgrade_obj_req*", "19-0": "*x_upgrade_cost*", "20-0": "*x_upgrade_time*", "21-0": "*x_upgrade_xp_award*", "22-0": "*lev_x_store_capacity*", "23-0": "*lev_x_production*", "24-0": "*lev_x_pop_bonus*", "25-0": "*grid_size*", "26-0": "*object_graphic*", "27-0": "*store_graphic*", "27-2": "The graphic that appear on the UI store", "26-2": "The graphic that appear on the screen", "25-2": "BUILDINGS - every buildings is squared, so we have just one value. If the valus is 3 the building is 3x3. If for then 4x4 and so on.", "24-2": "POPULATION BUILDINGS - the number to be added to the max population granted by the upgraded building (its not cumulative with the previous levels)", "23-2": "PRODUCTION BUILDINGS - the amount of the resource generated per second of the upgraded building (its not cumulative with the previous levels)", "22-2": "PRODUCTION & STORAGE BUILDINGS the store capacity of the upgraded building (its not cumulative with the previous levels)", "21-2": "BUILDINGS - XP awarded for the upgrade of an object", "20-2": "BUILDINGS - This is the amount of time (in minutes) that have to pass to upgrade the building", "19-2": "BUILDINGS - This is the amount of resources to be spent to upgrade the building", "18-2": "BUILDINGS - These are the objects required to upgrade a type of building (x is the level of the building)", "17-2": "BUILDINGS - This is the level required to upgrade a type of building (x is the level of the building)", "15-2": "The object that the player have to create before he can create this object", "14-2": "The category where to put the object on the store", "13-2": "The quantity of the resource to create the building", "12-2": "To check which resource is needed to complete this kind of building", "11-2": "XP awarded for the completion of an object", "10-2": "the time (in minutes) needed to create the building", "9-2": "UNITS - how many population slot occupies the unit", "8-2": "BUILDINGS - max number of building allowed", "7-2": "PRODUCTION & STORAGE BUILDINGS - the total amount of resource storage added by that building", "16-2": "BUILDINGS - This is the level needed to create x building type (x is a number from 1 to 5.)" }, "cols": 3, "rows": 28 } [/block]