Beispiel #1
0
    public void InsertMapComponent(MapComponentDao mapComponent)
    {
        this.SelectButton(mapComponent.name);

        this.mapComponent = mapComponent;
        this.tile         = null;

        this.PrepareTemp(mapComponent.Instantiate().model);
    }
Beispiel #2
0
    public void InsertTile(TileDao tile)
    {
        this.SelectButton(tile.name);

        this.tile         = tile;
        this.mapComponent = null;

        this.PrepareTemp(tile.Instantiate().model);
    }
Beispiel #3
0
    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();
    }
Beispiel #5
0
    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);
    }
Beispiel #6
0
    public void LoadMap(string map = "")
    {
        Debug.Log("LoadMap()");

        string path = "";

        this.mapName = map;

        while (true && map == "")
        {
            path = EditorUtility.OpenFilePanel("Selecione um mapa", Application.dataPath + "/StreamingAssets/", "map");

            if (path.Equals(""))
            {
                return;
            }

            string[] extension = path.Split('.');

            string[] mapName = path.Split(new string[] { "/StreamingAssets/" }, StringSplitOptions.None);

            this.mapName = mapName[1];

            if (extension[extension.Length - 1].ToLower().Equals("map"))
            {
                break;
            }
            else
            {
                bool option = EditorUtility.DisplayDialog("Arquivo inválido!", "Selecione um arquivo que possua a extenção .map", "Tentar novamente", "Cancelar");

                if (!option)
                {
                    return;
                }
            }
        }

        this.CleanEditor();

        GameDataMap gdm = GameDataMap.Load(this.mapName);

        // Map
        this.map = JsonUtility.FromJson <Map>(gdm.map);

        // Map Tiles
        this.mapTileData = Json.Deserialize <int[]>(gdm.mapTile);

        //Map Components
        this.mapComponentsData = Json.Deserialize <int[]>(gdm.mapComponent);

        this.map.height = (this.map.directionReflected.Equals('N') || this.map.directionReflected.Equals('S') ? this.map.height / 2 : this.map.height);
        this.map.width  = (this.map.directionReflected.Equals('E') || this.map.directionReflected.Equals('W') ? this.map.width / 2 : this.map.width);

        this.height = this.map.height;
        this.width  = this.map.width;

        this.gameComponents.mapTile      = new int[this.map.height, this.map.width];
        this.gameComponents.mapComponent = new int[this.map.height, this.map.width];

        for (int i = 0; i < this.map.height; i++)
        {
            for (int j = 0; j < this.map.width; j++)
            {
                this.gameComponents.mapTile[i, j]      = this.mapTileData[i * this.map.width + j];
                this.gameComponents.mapComponent[i, j] = this.mapComponentsData[i * this.map.width + j];
            }
        }

        bool isReflected = this.map.isReflected;

        this.map.isReflected = false;

        this.map.Build(gameComponents);

        this.DrawMap();

        if (isReflected)
        {
            this.map.isReflected = true;
            this.map.height      = (this.map.directionReflected.Equals('N') || this.map.directionReflected.Equals('S') ? this.map.height * 2 : this.map.height);
            this.map.width       = (this.map.directionReflected.Equals('E') || this.map.directionReflected.Equals('W') ? this.map.width * 2 : this.map.width);;
        }

        this.buttonSave.SetActive(true);
    }