Ejemplo n.º 1
0
 // gets called when this cube is being destroyed
 // Refreshes other surrounding cubes
 private void AdjustNeighbours()
 {
     for (int i = 0; i < 6; i++)
     {
         Vector3 neighbourCube = transform.position + directions[i];
         if (cubeParent == null)
         {
             print("getting parent"); cubeParent = GetComponentInParent <ChunkGenerator>();
         }
         CubeEditor temporaryCubeEditor = cubeParent.GetCubeEditorByVector(neighbourCube);
         if (temporaryCubeEditor == null)
         {
             continue;
         }
         if (temporaryCubeEditor.childTable.ContainsKey(-directions[i]))
         {
             temporaryCubeEditor.childTable[-directions[i]].gameObject.SetActive(true);
         }
         else
         {
             temporaryCubeEditor = cubeParent.GetEditorFromNeighbourChunk(neighbourCube);
             if (temporaryCubeEditor == null)
             {
                 continue;
             }
             if (temporaryCubeEditor.childTable.ContainsKey(-directions[i]))
             {
                 temporaryCubeEditor.HideTransformByVector(-directions[i]);
             }
         }
     }
 }
Ejemplo n.º 2
0
 // Getter for CubeEditor by it's position
 public CubeEditor GetCubeEditorByVector(Vector3 cubeEditorPos)
 {
     if (cubeEditorTable.ContainsKey(cubeEditorPos))
     {
         return(cubeEditorTable[cubeEditorPos]);
     }
     else
     {
         for (int i = 0; i < 4; i++)
         {
             Vector3        neighbourChunkPos = transform.position + directions[i];
             ChunkGenerator neighbourChunk    = worldManager.GetChunkGeneratorByVector(neighbourChunkPos);
             if (neighbourChunk == null)
             {
                 continue;
             }
             cubeEditorPos = TransformCubeToNeighbourPos(cubeEditorPos);
             if (!neighbourChunk.cubeEditorTable.ContainsKey(cubeEditorPos))
             {
                 continue;
             }
             CubeEditor neighbourCube = neighbourChunk.cubeEditorTable[cubeEditorPos];
             return(neighbourCube);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
 // removes cube
 public void RemoveCube(CubeEditor cubeEditor)
 {
     Destroy(cubeEditor.gameObject);
     if (cubeEditorTable.ContainsKey(cubeEditor.transform.position))
     {
         cubeEditorTable.Remove(cubeEditor.transform.position);
     }
 }
Ejemplo n.º 4
0
    // creates Cube, requires cube's position and type
    public void CreateCube(CubeEditor cubeEditor, Vector3 cubePos, CubeType cubeType)
    {
        CubeEditor currentCubeEditor = Instantiate(basicCubePrefab, cubePos, Quaternion.identity, transform);

        currentCubeEditor.UpdateName();
        currentCubeEditor.SetCubeParent(this);
        currentCubeEditor.SetCubeType(cubeType);

        if (!cubeEditorTable.ContainsKey(currentCubeEditor.transform.position))
        {
            cubeEditorTable.Add(currentCubeEditor.transform.position, currentCubeEditor);
        }
    }
Ejemplo n.º 5
0
 // If cube does not have a neighbour in the same chunk, this method gets called to check if CubeEditor does have a neighbour in other chunk
 public CubeEditor GetEditorFromNeighbourChunk(Vector3 neighbourPos)
 {
     for (int i = 0; i < 4; i++)
     {
         Vector3 neighbourChunkPos = transform.position + directions[i];
         if (worldManager == null)
         {
             print("getting parent"); worldManager = GetComponentInParent <WorldManager>();
         }
         ChunkGenerator neighbourChunk = worldManager.GetChunkGeneratorByVector(neighbourChunkPos);
         if (neighbourChunk == null)
         {
             continue;
         }
         neighbourPos = TransformCubeToNeighbourPos(neighbourPos);
         if (!neighbourChunk.cubeEditorTable.ContainsKey(neighbourPos))
         {
             continue;
         }
         CubeEditor neighbourCube = neighbourChunk.cubeEditorTable[neighbourPos];
         return(neighbourCube);
     }
     return(null);
 }