Ejemplo n.º 1
0
        public void Create()
        {
            ChunkPosition.x = (byte)Mathf.RoundToInt(transform.position.x / 16);
            ChunkPosition.y = (byte)Mathf.RoundToInt(transform.position.y / 16);
            ChunkPosition.z = (byte)Mathf.RoundToInt(transform.position.z / 16);

            BlockDatabase = new Block[4096];

            for (int x = 0; x < 16; x++)
            {
                for(int z = 0; z < 16; z++)
                {
                    for(int y = 0; y < 16; y++)
                    {
                        Block b = new Block();
                        b.ParentChunk = this;
                        b.Position = new Internal.ChunkVector(x, y, z);
                        b.BlockType = y < 10 ? (byte)1 : (byte)0;
                        BlockDatabase[x + 16 * (y + 16 * z)] = b;                    
                    }
                }
            }

            Debug.Log(BlockDatabase.Length);

            GlobalUpdate();
            Fuse(MeshBuffer.ToArray());
            MeshBuffer.Clear();
        }
Ejemplo n.º 2
0
        public void Bridge(MajorChunkVector majorFromVector, Block fromBlock)
        {
            Debug.Log("Self Chunk: " + transform.name);
            Vector3 difference = new Vector3(ChunkPosition.x - majorFromVector.x, ChunkPosition.y - majorFromVector.y, ChunkPosition.z - majorFromVector.z);
            ChunkVector pos = new ChunkVector(Math.Abs(difference.x) >= 0.01 ? 15 - fromBlock.Position.x : fromBlock.Position.x, Math.Abs(difference.y) >= 0.01 ? 15 - fromBlock.Position.y : fromBlock.Position.y, Math.Abs(difference.z) >= 0.01 ? 15 - fromBlock.Position.z : fromBlock.Position.z);

            BlockDatabase[pos.To4096Index].BridgeUpdate(difference, fromBlock);

            Debug.Log("Bridge update! " + pos.x + "(" + fromBlock.Position.x + "), " + pos.y + "(" + fromBlock.Position.y + "), " + pos.z + "(" + fromBlock.Position.z + ")");
            Fuse(MeshBuffer.ToArray(), false);
            MeshBuffer.Clear();
        }
Ejemplo n.º 3
0
 private void OnBlockTouched(Block block)
 {
     scorehandler.OnBlockTouch();
 }
Ejemplo n.º 4
0
        public void BridgeUpdate(Vector3 Direction, Block OtherBlock)
        {
            AccurateVector3 oldPos = ParentChunk.GetWorldPositionOfBlock(OtherBlock.Position, true);
            AccurateVector3 newPos = ParentChunk.GetWorldPositionOfBlock(Position, true);
            AccurateVector3 offset = new AccurateVector3(newPos.x + -(decimal)(Direction.x / 2), newPos.y + -(decimal)(Direction.y / 2), newPos.z + -(decimal)(Direction.z / 2));
            if (BlockType != 0)
            {              
                GameObject go = GameObject.Instantiate(ParentChunk.Prefab, offset.ToVector3(), Quaternion.Euler(Vector3.zero)) as GameObject;
                go.transform.LookAt(oldPos.ToVector3());
                ParentChunk.MeshBuffer.Add(go.GetComponent<MeshFilter>());
                Debug.Log("Parent chunk: " + ParentChunk.transform.name);
            }
            else
            {
                RaycastHit hit;
                int layerMask = LayerMask.GetMask("GroundMesh");
                Physics.Raycast(new Ray(newPos.ToVector3(), -(Direction / 1.8f)), out hit, 2f, layerMask);
                if (hit.transform)
                {
                    Debug.Log("HIT: " + hit.transform.name);
                    hit.transform.GetComponent<Chunk>().RemoveFace(OtherBlock.ParentChunk.GetComponent<MeshCollider>(), OtherBlock.ParentChunk.GetComponent<MeshFilter>(), hit.triangleIndex);
                }

                Debug.DrawRay(newPos.ToVector3(), -(Direction / 1.8f), Color.green, 30f);
                Debug.DrawRay(newPos.ToVector3(), -(Direction / 1.8f) * 2, Color.blue, 5f);
            }
        }