public void InsertMapComponent(MapComponentDao mapComponent) { this.SelectButton(mapComponent.name); this.mapComponent = mapComponent; this.tile = null; this.PrepareTemp(mapComponent.Instantiate().model); }
public void InsertTile(TileDao tile) { this.SelectButton(tile.name); this.tile = tile; this.mapComponent = null; this.PrepareTemp(tile.Instantiate().model); }
public void DeleteMapComponent() { this.SelectButton("Empty"); this.mapComponent = null; this.tile = null; this.PrepareTemp(Resources.Load("tile_Help", typeof(GameObject)) as GameObject); this.temp.GetComponent <MeshRenderer>().sharedMaterial.color = Color.red; }
public void CreateGame() { // Tiles TileDao tile_Grass = new TileDao("Grass", "tile_Grass", true, true, 1.0f); TileDao tile_Water = new TileDao("Water", "tile_Water", false, false, 1.0f); TileDao tile_Bridge = new TileDao("Bridge", "tile_Bridge", true, false, 1.0f); // Base Material BaseMaterialDao baseMaterialGold = new BaseMaterialDao("Gold", "Images/material_Gold"); BaseMaterialDao baseMaterialMeat = new BaseMaterialDao("Meat", "Images/material_Meat"); // Material Source MaterialSourceDao mats_Gold = new MaterialSourceDao("Gold", "mats_Gold", 999999999999999999, baseMaterialGold); // Map Component MapComponentDao mc_Tree = new MapComponentDao("Tree", "mc_Tree"); // Buildings BuildingDao build_base = new BuildingDao("Base", "Images/build_Base", "build_Base", new Vector2(2.0f, 2.0f), 3000.0f, 0.0f, true, 3); BuildingDao build_quarter = new BuildingDao("Quarter", "Images/build_Quarter", "build_Quarter", new Vector2(1.0f, 1.0f), 1200.0f, 50.0f, false, 1); build_quarter.cost.Add(baseMaterialGold.id, 200); BuildingDao build_farm = new BuildingDao("Farm", "Images/material_Meat", "build_Farm", new Vector2(1.0f, 1.0f), 500.0f, 30.0f, false, 1, baseMaterialMeat, 1); build_farm.cost.Add(baseMaterialGold.id, 75); BuildingDao build_mine = new BuildingDao("Mine", "Images/build_Mine", "build_Mine", new Vector2(1.0f, 1.0f), 500.0f, 30.0f, false, 1, baseMaterialGold, 1); build_mine.cost.Add(baseMaterialMeat.id, 100); build_mine.requireds.Add(mats_Gold.name); // Warrior Unit CombatDao infantry_unit = new CombatDao("Infantry", "Images/unit_Warrior", "unit_Warrior", 3.0f, 0.0f, 1.0f, 50.0f, 1.0f, 1.0f, new CombatType(), 22.0f, 2); infantry_unit.cost.Add(baseMaterialMeat.id, 35); infantry_unit.cost.Add(baseMaterialGold.id, 25); // Archer Unit CombatDao archer_unit = new CombatDao("Archer", "Images/unit_Archer", "unit_Archer", 4.0f, 0.0f, 0.9f, 30.0f, 4.0f, 1.0f, new CombatType(), 30.0f, 2); archer_unit.cost.Add(baseMaterialMeat.id, 25); archer_unit.cost.Add(baseMaterialGold.id, 45); // Archer Unit CombatDao cavalry_unit = new CombatDao("Cavalry", "Images/unit_Knight", "unit_Knight", 10.0f, 0.0f, 1.5f, 100.0f, 1.0f, 1.0f, new CombatType(), 35.0f, 2); cavalry_unit.cost.Add(baseMaterialMeat.id, 60); cavalry_unit.cost.Add(baseMaterialGold.id, 75); // Worker Unit WorkerDao unit_worker = new WorkerDao("Worker", "Images/unit_Worker", "unit_Worker", 1.0f, 0.0f, 1.0f, 45.0f, 5, 1.0f, 1.0f, 1.0f, 10.0f, 2); unit_worker.cost.Add(baseMaterialMeat.id, 10); unit_worker.buildings.Add(build_quarter.id); unit_worker.buildings.Add(build_farm.id); unit_worker.buildings.Add(build_mine.id); // Add in tiles list tiles.Add(tile_Grass.id, tile_Grass); tiles.Add(tile_Water.id, tile_Water); tiles.Add(tile_Bridge.id, tile_Bridge); // Add in baseMaterial list baseMaterials.Add(baseMaterialGold.id, baseMaterialGold); baseMaterials.Add(baseMaterialMeat.id, baseMaterialMeat); // Add in materialSource list mapComponents.Add(mats_Gold.id, mats_Gold); mapComponents.Add(mc_Tree.id, mc_Tree); // Add in buildings list buildings.Add(build_base.id, build_base); buildings.Add(build_quarter.id, build_quarter); buildings.Add(build_farm.id, build_farm); buildings.Add(build_mine.id, build_mine); // Add in unit list units.Add(infantry_unit.id, infantry_unit); units.Add(archer_unit.id, archer_unit); units.Add(cavalry_unit.id, cavalry_unit); units.Add(unit_worker.id, unit_worker); // Add in unit list of build_base build_base.units.Add(unit_worker.id); build_quarter.units.Add(infantry_unit.id); build_quarter.units.Add(archer_unit.id); build_quarter.units.Add(cavalry_unit.id); SaveGame(); }
void Start() { // Buttons this.buttonNew = GameObject.Find("Canvas/Menu/ButtonNew"); this.buttonLoad = GameObject.Find("Canvas/Menu/ButtonLoad"); this.buttonSave = GameObject.Find("Canvas/Menu/ButtonSave"); this.buttonSave.SetActive(false); this.mouseDown = false; this.tile = null; this.mapComponent = null; this.temp = null; this.timeCounter = 0; this.gameComponents = new GameComponents(); this.gameComponents.map = null; this.gameComponents.mapTile = null; this.gameComponents.mapComponent = null; this.components = GameObject.Find("components");; // ScrollView this.tilesView = GameObject.Find("tilesView"); this.mapComponentsView = GameObject.Find("mapComponentsView"); GameObject button, model, tilesContent, mapComponentsContent; tilesContent = GameObject.Find("tilesView/Viewport/Content"); mapComponentsContent = GameObject.Find("mapComponentsView/Viewport/Content"); tilesContent.GetComponent <RectTransform>().sizeDelta = new Vector2(20 + 120 * this.gameComponents.tiles.Count, 0.0f); mapComponentsContent.GetComponent <RectTransform>().sizeDelta = new Vector2(20 + 120 * this.gameComponents.mapComponents.Count, 0.0f); int count = 0; List <string> options = new List <string>(); foreach (TileDao tile in this.gameComponents.tiles.Values) { options.Add(tile.name); button = new GameObject(); button.name = "Button" + tile.name; button.transform.SetParent(tilesContent.transform); button.AddComponent <Button>(); button.AddComponent <Image>(); button.GetComponent <RectTransform>().anchorMin = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().anchorMax = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().pivot = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f); button.GetComponent <RectTransform>().localPosition = new Vector3(20.0f + 120 * count, -10.0f, 0.0f); UnityEngine.Events.UnityAction action = () => { InsertTile(tile); }; button.GetComponent <Button>().onClick.AddListener(action); model = GameObject.Instantiate(tile.Instantiate().model); model.transform.SetParent(button.transform); model.AddComponent <RectTransform>(); model.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f); model.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f); model.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); model.GetComponent <RectTransform>().localScale = new Vector3(95.0f, 95.0f, 1.0f); model.GetComponent <RectTransform>().localPosition = new Vector3(50.0f, 0.0f, 0.0f); count++; } count = 0; button = new GameObject(); button.name = "ButtonEmpty"; button.transform.SetParent(mapComponentsContent.transform); button.AddComponent <Button>(); button.AddComponent <Image>(); button.GetComponent <RectTransform>().anchorMin = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().anchorMax = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().pivot = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f); button.GetComponent <RectTransform>().localPosition = new Vector3(20.0f + 120 * count, -10.0f, 0.0f); button.GetComponent <Button>().onClick.AddListener(DeleteMapComponent); GameObject text = new GameObject("empty", typeof(Text)); text.gameObject.transform.SetParent(button.transform); text.GetComponent <RectTransform>().sizeDelta = new Vector2(320.0f, 200.0f); text.GetComponent <RectTransform>().anchorMin = new Vector2(0.0f, 0.0f); text.GetComponent <RectTransform>().anchorMax = new Vector2(1.0f, 1.0f); text.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f); text.GetComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.0f, 0.0f); text.GetComponent <RectTransform>().offsetMin = new Vector2(0.0f, 0.0f); text.GetComponent <RectTransform>().offsetMax = new Vector2(0.0f, 0.0f); text.GetComponent <Text>().font = Font.CreateDynamicFontFromOSFont("Arial", 14); text.GetComponent <Text>().fontSize = 30; text.GetComponent <Text>().fontStyle = FontStyle.Bold; text.GetComponent <Text>().color = Color.red; text.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; text.GetComponent <Text>().text = "X"; count++; foreach (MapComponentDao mapComponent in this.gameComponents.mapComponents.Values) { button = new GameObject(); button.name = "Button" + mapComponent.name; button.transform.SetParent(mapComponentsContent.transform); button.AddComponent <Button>(); button.AddComponent <Image>(); button.GetComponent <RectTransform>().anchorMin = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().anchorMax = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().pivot = new Vector2(0.0f, 0.5f); button.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f); button.GetComponent <RectTransform>().localPosition = new Vector3(20.0f + 120 * count, -10.0f, 0.0f); UnityEngine.Events.UnityAction action = () => { InsertMapComponent(mapComponent); }; button.GetComponent <Button>().onClick.AddListener(action); model = GameObject.Instantiate(mapComponent.Instantiate().model); model.transform.SetParent(button.transform); model.AddComponent <RectTransform>(); model.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f); model.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f); model.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); model.GetComponent <RectTransform>().localScale = new Vector3(95.0f, 95.0f, 1.0f); model.GetComponent <RectTransform>().localPosition = new Vector3(50.0f, -30.0f, 0.0f); count++; } GameObject.Find("Canvas/PanelNewMap/Form/TileDefault/DropdownTiles").GetComponent <Dropdown>().AddOptions(options); // NewMap this.PanelNewMap = GameObject.Find("Canvas/PanelNewMap"); this.PanelNewMap.SetActive(false); this.mapComponentsView.SetActive(false); }
void Update() { if (Input.GetAxis("Mouse ScrollWheel") > 0) { if (this.components.transform.position.z > 100) { this.components.transform.Translate(0.0f, 0.0f, -50.0f); } } if (Input.GetAxis("Mouse ScrollWheel") < 0) { if (this.components.transform.position.z < 300) { this.components.transform.Translate(0.0f, 0.0f, 50.0f); } } if (Input.GetMouseButtonDown(0)) { this.mouseDown = true; } if (Input.GetMouseButtonUp(0)) { this.mouseDown = false; } if (this.temp != null) { if ((this.tile != null || this.mapComponent != null || (this.tile == null && this.mapComponent == null && this.temp != null)) && Input.mousePosition.x > 264 && Input.mousePosition.y > 204) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { string objName = hit.transform.name; string[] coord = objName.Split('_'); GameObject obj = GameObject.Find(objName); this.temp.SetActive(true); this.temp.transform.position = new Vector3(obj.transform.position.x, obj.transform.position.y, obj.transform.position.z - 0.1f); if (this.mouseDown) { GameObject newComponent = null; if (this.tile != null || this.mapComponent != null) { newComponent = GameObject.Instantiate(this.temp); newComponent.GetComponent <BoxCollider>().enabled = false; newComponent.transform.SetParent(this.components.transform); newComponent.transform.position = new Vector3(obj.transform.position.x, obj.transform.position.y, obj.transform.position.z); } int width = ((this.map.directionReflected == 'E' || this.map.directionReflected == 'W') ? this.map.width / 2 : this.map.width); if (this.tile != null) { if (this.tile.isWalkable || (!this.tile.isWalkable && GameObject.Find("component_" + coord[1] + "_" + coord[2]) == null)) { GameObject.DestroyImmediate(GameObject.Find(objName)); newComponent.transform.name = objName; newComponent.GetComponent <BoxCollider>().enabled = true; this.mapTileData[int.Parse(coord[1]) * width + int.Parse(coord[2])] = this.tile.id; } else { Destroy(newComponent); } } else if (this.mapComponent != null) { TileDao tile = this.gameComponents.tiles[this.mapTileData[int.Parse(coord[1]) * this.map.width + int.Parse(coord[2])]]; if (tile.isWalkable) { //Debug.Log("Editando MapComponent"); GameObject.DestroyImmediate(GameObject.Find("component_" + coord[1] + "_" + coord[2])); newComponent.transform.name = "component_" + coord[1] + "_" + coord[2]; newComponent.transform.position = new Vector3(newComponent.transform.position.x, newComponent.transform.position.y, newComponent.transform.position.z - 0.5f); this.mapComponentsData[int.Parse(coord[1]) * width + int.Parse(coord[2])] = this.mapComponent.id + 1; } else { Destroy(newComponent); } } else { //Debug.Log("Deleta MapComponent"); GameObject.DestroyImmediate(GameObject.Find("component_" + coord[1] + "_" + coord[2])); this.mapComponentsData[int.Parse(coord[1]) * width + int.Parse(coord[2])] = 0; } } } } else { this.temp.SetActive(false); } } timeCounter += Time.deltaTime; // Camera if (timeCounter >= cameraDelay) { if (Input.GetKey("left") && Camera.main.transform.position.x > this.xIni) { Camera.main.transform.Translate(new Vector3(-(this.scale + this.spaceCell), 0.0f, 0.0f)); } if (Input.GetKey("right") && Camera.main.transform.position.x < this.xFin) { Camera.main.transform.Translate(new Vector3((this.scale + this.spaceCell), 0.0f, 0.0f)); } if (Input.GetKey("up") && Camera.main.transform.position.y < this.yIni) { Camera.main.transform.Translate(new Vector3(0.0f, (this.scale + this.spaceCell), 0.0f)); } if (Input.GetKey("down") && Camera.main.transform.position.y > this.yFin) { Camera.main.transform.Translate(new Vector3(0.0f, -(this.scale + this.spaceCell), 0.0f)); } timeCounter -= cameraDelay; } if (timeCounter >= cameraDelay) { timeCounter -= cameraDelay; } }