Пример #1
0
 // Start is called before the first frame update
 public void Initialize()
 {
     GridController.Initialize(MapGenerator.Size, MapGenerator.Size);
     MapGenerator.GenerateMap();
     VillageController.Initialize();
     TimeController.Initialize();
     ConstructionController.Initialize();
     AreaOrderController.Initialize();
 }
Пример #2
0
    public void Start()
    {
        ViewManagerSingleton.Instance.InstantiateAView("Canvas/GameView");

        ConController = ViewManagerSingleton.CurrentView.AddComponent <ConstructionController>();
        ConController.Initialize();

        Button RollDiceButton = ViewManagerSingleton.CurrentView.transform.Find("PlayerInfo/RollDiceButton").GetComponent <Button>();

        RollDiceButton.onClick.AddListener(RollDice);

        DiceRolled += DiceHasBeenRolled;

        CurrentGameState = GameState.RollDice;

        for (int i = 0; i < 4; i++)
        {
            if (i == 0)
            {
                Players.Add(new PlayerData(PlayerData.PlayerColors.BLUE, true));
            }
            if (i == 1)
            {
                Players.Add(new PlayerData(PlayerData.PlayerColors.RED, true));
            }
            if (i == 2)
            {
                Players.Add(new PlayerData(PlayerData.PlayerColors.PURPLE, true));
            }
            if (i == 3)
            {
                Players.Add(new PlayerData(PlayerData.PlayerColors.YELLOW, true));
            }
        }

        // real tmp work here
        UserPlayer = Players[0];
        Players[0].CurrentPlayer = true;
    }
Пример #3
0
    private void BrushToolUpdate(Vector3Int tilePointing, Vector3 pointing)
    {
        // enable and disable element depending on pointer (only if needed)
        if (lastTilePointing != tilePointing)
        {
            MapModifier.TileGameObject pointedTile = modifier.GetObjectsAtTile(tilePointing);
            if (pointedTile != lastPointedTile)
            {
                if (targetLayer.layerType == ConstructionLayer.LayerType.Terrain)
                {
                    if (lastPointedTile != null && lastPointedTile.terrain)
                    {
                        lastPointedTile.terrain.SetActive(true);
                    }
                    if (pointedTile != null && pointedTile.terrain)
                    {
                        pointedTile.terrain.SetActive(false);
                    }
                }
            }
            lastPointedTile = pointedTile;
        }
        lastTilePointing = tilePointing;

        // if ponter is valid (we are on something with a brush)
        if (lastPointedTile != null)
        {
            // simple preview stuff
            preview.transform.position = pointing + new Vector3(2f * (brush.data.tileSize.x - 1), 0, 2f * (brush.data.tileSize.y - 1));
            if (Input.GetKeyDown(rotationLeft))
            {
                preview.transform.eulerAngles += new Vector3(0, 90, 0);
            }
            else if (Input.GetKeyDown(rotationRight))
            {
                preview.transform.eulerAngles -= new Vector3(0, 90, 0);
            }

            string            message = "";
            List <GameObject> hovered = GetPointedObjects(preview.transform.position, ref message);

            currentPreviewMaterial.color    = hovered.Count == 0 ? previewOk : previewInvalid;
            constructionUI.description.text = message;

            if (Input.GetMouseButtonDown(0))
            {
                clickDownTilePointing = tilePointing;
            }
            if (!enableMultiConstruction)
            {
                clickDownTilePointing = tilePointing;
            }

            // multi placement preview
            if (Input.GetMouseButton(0) && brush.data.tile != null)
            {
                int multiplacementCount = 0;
                for (int i = Mathf.Min(tilePointing.x, clickDownTilePointing.x); i <= Mathf.Max(tilePointing.x, clickDownTilePointing.x) && multiplacementCount < maximumMultiplacement; i++)
                {
                    for (int j = Mathf.Min(tilePointing.y, clickDownTilePointing.y); j <= Mathf.Max(tilePointing.y, clickDownTilePointing.y) && multiplacementCount < maximumMultiplacement; j++)
                    {
                        Vector3Int cell = new Vector3Int(i, j, tilePointing.z);
                        if (cell == tilePointing)
                        {
                            continue;
                        }

                        Vector3 p       = modifier.GetTileCenter(cell);
                        bool    blocked = HoveringObjects(p);

                        multiPreviewRenderers[multiplacementCount].gameObject.SetActive(true);
                        multiPreviewRenderers[multiplacementCount].transform.position   = p;
                        multiPreviewRenderers[multiplacementCount].transform.rotation   = preview.transform.rotation;
                        multiPreviewRenderers[multiplacementCount].transform.localScale = preview.transform.localScale;
                        multiPreviewRenderers[multiplacementCount].material.color       = blocked ? previewInvalid : previewOk;

                        multiplacementCount++;
                    }
                }

                for (int i = multiplacementCount; i < multiPreviewRenderers.Count; i++)
                {
                    multiPreviewRenderers[i].gameObject.SetActive(false);
                }
            }


            // construction placement
            if (Input.GetMouseButtonUp(0) && (hovered.Count == 0 || tilePointing != clickDownTilePointing))
            {
                // directly place building (free and no timing)
                if (instantConstruct || brush.data.incrementSpeed >= 1f)
                {
                    if (brush.data.tile != null)
                    {
                        Quaternion finalRotation = Quaternion.Euler(brush.data.placementEulerOffset - new Vector3(0, 0, preview.transform.eulerAngles.y));
                        Matrix4x4  matrix        = Matrix4x4.TRS(Vector3.zero, finalRotation, Vector3.one);

                        int multiplacementCount = 0;
                        for (int i = Mathf.Min(tilePointing.x, clickDownTilePointing.x); i <= Mathf.Max(tilePointing.x, clickDownTilePointing.x) && multiplacementCount < maximumMultiplacement; i++)
                        {
                            for (int j = Mathf.Min(tilePointing.y, clickDownTilePointing.y); j <= Mathf.Max(tilePointing.y, clickDownTilePointing.y) && multiplacementCount < maximumMultiplacement; j++)
                            {
                                Vector3Int cell = new Vector3Int(i, j, tilePointing.z);
                                modifier.OverrideTile(brush.data.tile, matrix, cell, false);
                                multiplacementCount++;
                            }
                        }
                    }
                    else
                    {
                        GameObject element = Instantiate(brush.data.prefab);
                        element.name = brush.data.prefab.name;
                        element.transform.position    = preview.transform.position;
                        element.transform.eulerAngles = new Vector3(0, preview.transform.eulerAngles.y, 0);
                        element.transform.localScale  = Vector3.one;
                        modifier.grid.AddGameObject(element, brush.data.layer, true, false);

                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing, true);
                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 0, 0), true);
                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(0, 1, 0), true);
                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 1, 0), true);
                    }
                }

                // place a construction interaction on the building in order to properly construct it
                else
                {
                    if (brush.data.tile != null)
                    {
                        int multiplacementCount = 0;
                        for (int i = Mathf.Min(tilePointing.x, clickDownTilePointing.x); i <= Mathf.Max(tilePointing.x, clickDownTilePointing.x) && multiplacementCount < maximumMultiplacement; i++)
                        {
                            for (int j = Mathf.Min(tilePointing.y, clickDownTilePointing.y); j <= Mathf.Max(tilePointing.y, clickDownTilePointing.y) && multiplacementCount < maximumMultiplacement; j++)
                            {
                                Vector3Int cell = new Vector3Int(i, j, tilePointing.z);
                                Vector3    p    = modifier.GetTileCenter(cell);
                                if (HoveringObjects(p))
                                {
                                    continue;
                                }

                                GameObject prefab = Instantiate(constructionTilePrefab);
                                prefab.name = brush.data.tile.name + "Construction";
                                prefab.transform.position    = p;
                                prefab.transform.eulerAngles = new Vector3(0, preview.transform.eulerAngles.y, 0);
                                prefab.transform.localScale  = Vector3.one;

                                modifier.grid.AddGameObject(prefab, brush.data.layer, false, false);
                                modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, cell, true);

                                // override interactor
                                Transform previousInteractor = prefab.transform.Find("interactor");
                                if (previousInteractor != null)
                                {
                                    Destroy(previousInteractor.gameObject);
                                }

                                ConstructionController interactor = Instantiate <ConstructionController>(constructionInteractor);
                                interactor.transform.parent        = prefab.transform;
                                interactor.gameObject.name         = "interactor";
                                interactor.transform.localPosition = Vector3.zero;
                                interactor.transform.localRotation = Quaternion.identity;
                                interactor.transform.localScale    = Vector3.one;
                                interactor.orientation             = preview.transform.eulerAngles.y;

                                interactor.data = brush.data;
                                interactor.Initialize();

                                multiplacementCount++;
                            }
                        }
                    }
                    else
                    {
                        GameObject prefab = Instantiate(brush.data.prefab);
                        prefab.name = brush.data.prefab.name + "Construction";
                        prefab.transform.position    = preview.transform.position;
                        prefab.transform.eulerAngles = new Vector3(0, preview.transform.eulerAngles.y, 0);
                        prefab.transform.localScale  = Vector3.one;

                        modifier.grid.AddGameObject(prefab, brush.data.layer, false, false);
                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing, true);
                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 0, 0), true);
                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(0, 1, 0), true);
                        modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 1, 0), true);

                        // override interactor
                        Transform previousInteractor = prefab.transform.Find("interactor");
                        if (previousInteractor != null)
                        {
                            Destroy(previousInteractor.gameObject);
                        }

                        ConstructionController interactor = Instantiate <ConstructionController>(constructionInteractor);
                        interactor.transform.parent        = prefab.transform;
                        interactor.gameObject.name         = "interactor";
                        interactor.transform.localPosition = Vector3.zero;
                        interactor.transform.localRotation = Quaternion.identity;
                        interactor.transform.localScale    = Vector3.one;
                        interactor.orientation             = preview.transform.eulerAngles.y;

                        interactor.data = brush.data;
                        interactor.Initialize();
                    }
                }
            }

            // clear multi view
            if (Input.GetMouseButtonUp(0))
            {
                foreach (MeshRenderer mr in multiPreviewRenderers)
                {
                    mr.gameObject.SetActive(false);
                }
            }
        }
    }