Ejemplo n.º 1
0
    private void SpawnChunk(HexChunk chunk)
    {
        //chunk.InitializeChunk()

        List <Hex> hexKeys = new List <Hex>(chunk.grid.Keys);

        foreach (Hex key in hexKeys)
        {
            Hex hex = key;

            if (hex != null)
            {
                if (chunk.grid.ContainsKey(key))
                {
                    HexObject hexObject = chunk.grid[key];

                    if (hexObject != null)
                    {
                        hexObject.meshFilter            = hexObject.gameObject.AddComponent <MeshFilter>();
                        hexObject.meshFilter.sharedMesh = GridManager.I.pointyHexagonMesh.mesh;

                        hexObject.meshCollider = hexObject.gameObject.AddComponent <MeshCollider>();
                        hexObject.meshRenderer = hexObject.gameObject.AddComponent <MeshRenderer>();

                        hexObject.GetComponent <Renderer>().sharedMaterial = LoadFromHexMaterials(hexObject.hex.hexType);
                    }
                }
            }
        }

        chunk.chunkState = HexChunk.ChunkState_e.SPAWNED;
    }
Ejemplo n.º 2
0
    private void SyncCurrentMaterial(HexObject hexObject)
    {
        Material material = hexObject.GetComponent <Renderer>().material;

        if (material != null)
        {
            string sMaterialName = material.name;
            hexObject.hex.hexType = GetHexMaterialType(sMaterialName);
        }
    }
Ejemplo n.º 3
0
 public void ClickDown(HexObject piece)
 {
     if (typeof(Marker) == piece.GetType())
     {
         // Add the rock to the board and place object
         RockObject tmp;
         if (selectedItem != null)
         {
             if (selectedItem.TryGetComponent <RockObject>(out tmp))
             {
                 model.GetBlockedPositions().Add(piece.GetHexPosition());
                 selectedItem.SetHexPosition(piece);
                 selectedItem.gameObject.SetActive(true);
                 selectedItem = null;
                 markersPool.ClearAll();
             }
         }
         else if (selectedUIPiece != null)
         {
             model.GetNotPlacedPieces().Remove(selectedUIPiece.piece);
             model.GetPlacedPieces().Add((piece.x, piece.y, piece.z), selectedUIPiece.piece);
             panels[0].RemovePiece(selectedUIPiece);
             panels[1].RemovePiece(selectedUIPiece);
             markersPool.ClearAll();
             GameObject instance = piecesPool.GetInstance(true);
             instance.GetComponent <PieceObject>().Initialize(selectedUIPiece.piece, ClickDown);
             instance.GetComponent <PieceObject>().SetHexPosition(piece);
             selectedUIPiece = null;
         }
     }
     else if (typeof(RockObject) == piece.GetType())
     {
         markersPool.ClearAll();
         selectedItem = piece;
     }
     else if (typeof(PieceObject) == piece.GetType())
     {
         if (selectedItem != null)
         {
             // Add a chain to the piece
             if (selectedItem.GetComponent <ChainObject>() != null)
             {
                 ((PieceObject)piece).piece.blocked = true;
                 selectedItem.SetHexPosition(piece);
                 selectedItem.gameObject.SetActive(true);
                 selectedItem = null;
                 return;
             }
         }
         // Select piece
         selectedItem = piece;
     }
 }