public void Update()
        {
            // check if chunk is not null
            GameObject chunkObject = Engine.PositionToChunk (transform.position);
            if (chunkObject == null) return;

            // get the voxelInfo from the transform's position
            Chunk chunk = chunkObject.GetComponent<Chunk>();
            Index voxelIndex = chunk.PositionToVoxelIndex (transform.position);
            VoxelInfo voxelInfo = new VoxelInfo (voxelIndex, chunk);

            // create a local copy of the collision voxel so we can call functions on it
            GameObject voxelObject = Instantiate ( Engine.GetVoxelGameObject (voxelInfo.GetVoxel()) ) as GameObject;

            VoxelEvents events = voxelObject.GetComponent<VoxelEvents>();
            if (events != null ) {

            // OnEnter
            if ( chunk != LastChunk || voxelIndex.IsEqual(LastIndex) == false) {
                events.OnBlockEnter (this.gameObject, voxelInfo);
            }

            // OnStay
            else {
                events.OnBlockStay(this.gameObject, voxelInfo);
            }
            }

            LastChunk = chunk;
            LastIndex = voxelIndex;

            Destroy(voxelObject);
        }
Exemplo n.º 2
0
        public override void OnBlockDestroy( VoxelInfo voxelInfo )
        {
            // if the block above is tall grass, destroy it
            Index indexAbove = new Index (voxelInfo.index.x, voxelInfo.index.y+1, voxelInfo.index.z);

            if ( voxelInfo.chunk.GetVoxel(indexAbove) == 8 ) {
            voxelInfo.chunk.SetVoxel(indexAbove, 0, true);
            }
        }
Exemplo n.º 3
0
        public override void OnBlockPlace( VoxelInfo voxelInfo )
        {
            // if the block below is grass, change it to dirt
            Index indexBelow = new Index (voxelInfo.index.x, voxelInfo.index.y-1, voxelInfo.index.z);

            if ( voxelInfo.GetVoxelType ().VTransparency == Transparency.solid
            && voxelInfo.chunk.GetVoxel(indexBelow) == 2) {
            voxelInfo.chunk.SetVoxel(indexBelow, 1, true);
            }
        }
Exemplo n.º 4
0
 public override void OnLook( VoxelInfo voxelInfo )
 {
     // move the selected block ui to the block that's being looked at (convert the index of the hit voxel to absolute world position)
     GameObject blockSelection = GameObject.Find ("selected block graphics");
     if (blockSelection != null) {
     blockSelection.transform.position = voxelInfo.chunk.VoxelIndexToPosition (voxelInfo.index);
     blockSelection.GetComponent<Renderer>().enabled = true;
     blockSelection.transform.rotation = voxelInfo.chunk.transform.rotation;
     }
 }
Exemplo n.º 5
0
        // multiplayer
        public static void DestroyBlockMultiplayer( VoxelInfo voxelInfo, NetworkPlayer sender )
        {
            // received from server, don't use directly

            GameObject voxelObject = Instantiate ( Engine.GetVoxelGameObject (voxelInfo.GetVoxel()) ) as GameObject;
            VoxelEvents events = voxelObject.GetComponent<VoxelEvents>();
            if (events != null) {
            events.OnBlockDestroy(voxelInfo);
            events.OnBlockDestroyMultiplayer(voxelInfo, sender);
            }
            voxelInfo.chunk.SetVoxel (voxelInfo.index, 0, true);
            Destroy(voxelObject);
        }
Exemplo n.º 6
0
        public static void ChangeBlockMultiplayer( VoxelInfo voxelInfo, ushort data, NetworkPlayer sender )
        {
            // received from server, don't use directly

            voxelInfo.chunk.SetVoxel (voxelInfo.index, data, true);

            GameObject voxelObject = Instantiate ( Engine.GetVoxelGameObject (data) ) as GameObject;
            VoxelEvents events = voxelObject.GetComponent<VoxelEvents>();
            if (events != null) {
            events.OnBlockChange(voxelInfo);
            events.OnBlockChangeMultiplayer(voxelInfo, sender);
            }
            Destroy (voxelObject);
        }
Exemplo n.º 7
0
        public void SendChangeBlock( VoxelInfo info, ushort data )
        {
            // convert to ints
            int chunkx = info.chunk.ChunkIndex.x;
            int chunky = info.chunk.ChunkIndex.y;
            int chunkz = info.chunk.ChunkIndex.z;

            // send to server
            if (Network.isServer) {
            GetComponent<UniblocksServer>().ServerChangeBlock (Network.player, info.index.x, info.index.y, info.index.z, chunkx,chunky,chunkz, (int)data);
            }
            else {
            GetComponent<NetworkView>().RPC ("ServerChangeBlock", RPCMode.Server, Network.player, info.index.x, info.index.y, info.index.z, chunkx,chunky,chunkz, (int)data);
            }
        }
Exemplo n.º 8
0
        public void ReceiveChangeBlock( NetworkPlayer sender, int x, int y, int z, int chunkx, int chunky, int chunkz, int data )
        {
            // receives a change sent by other client or server

            GameObject chunkObject = ChunkManager.GetChunk (chunkx,chunky,chunkz);
            if (chunkObject != null) {

            // convert back to VoxelInfo
            Index voxelIndex = new Index (x,y,z);
            VoxelInfo info = new VoxelInfo (voxelIndex, chunkObject.GetComponent<Chunk>());

            // apply change
            Voxel.ChangeBlockMultiplayer (info, (ushort)data, sender);
            }
        }
Exemplo n.º 9
0
        public override void OnMouseDown( int mouseButton, VoxelInfo voxelInfo )
        {
            if ( mouseButton == 0 ) { // destroy a block with LMB
            Voxel.DestroyBlock (voxelInfo);
            }
            else if ( mouseButton == 1 ) { // place a block with RMB

            if ( voxelInfo.GetVoxel() == 8 ) { // if we're looking at a tall grass block, replace it with the held block
                Voxel.PlaceBlock (voxelInfo, ExampleInventory.HeldBlock);
            }
            else { // else put the block next to the one we're looking at
                VoxelInfo newInfo = new VoxelInfo (voxelInfo.adjacentIndex, voxelInfo.chunk); // use adjacentIndex to place the block
                Voxel.PlaceBlock (newInfo, ExampleInventory.HeldBlock);
            }
            }
        }
Exemplo n.º 10
0
        public override void OnBlockPlace( VoxelInfo voxelInfo )
        {
            // switch to dirt if the block above isn't 0
            Index adjacentIndex = voxelInfo.chunk.GetAdjacentIndex (voxelInfo.index, Direction.up);
            if ( voxelInfo.chunk.GetVoxel(adjacentIndex) != 0 ) {
            voxelInfo.chunk.SetVoxel(voxelInfo.index, 1, true);
            }

            // if the block below is grass, change it to dirt
            Index indexBelow = new Index (voxelInfo.index.x, voxelInfo.index.y-1, voxelInfo.index.z);

            if ( voxelInfo.GetVoxelType ().VTransparency == Transparency.solid
            && voxelInfo.chunk.GetVoxel(indexBelow) == 2) {
            voxelInfo.chunk.SetVoxel(indexBelow, 1, true);
            }
        }
Exemplo n.º 11
0
        public static void DestroyBlock( VoxelInfo voxelInfo )
        {
            // multiplayer - send change to server
            if (Engine.EnableMultiplayer) {
            Engine.UniblocksNetwork.GetComponent<UniblocksClient>().SendPlaceBlock ( voxelInfo, 0 );
            }

            // single player - apply change locally
            else {
            GameObject voxelObject = Instantiate ( Engine.GetVoxelGameObject (voxelInfo.GetVoxel()) ) as GameObject;
            if (voxelObject.GetComponent<VoxelEvents>() != null) {
                voxelObject.GetComponent<VoxelEvents>().OnBlockDestroy(voxelInfo);
            }
            voxelInfo.chunk.SetVoxel (voxelInfo.index, 0, true);
            Destroy (voxelObject);
            }
        }
Exemplo n.º 12
0
        public override void OnMouseDown(int mouseButton, VoxelInfo voxelInfo)
        {
            if (mouseButton == 0) {
            Voxel.DestroyBlock (voxelInfo);	// destroy with left click
            }

            else if (mouseButton == 1) { // open/close with right click

            if (voxelInfo.GetVoxel() == 70) { // if open door
                Voxel.ChangeBlock (voxelInfo, 7); // set to closed
            }

            else if (voxelInfo.GetVoxel() == 7) { // if closed door
                Voxel.ChangeBlock (voxelInfo, 70); // set to open
            }

            }
        }
Exemplo n.º 13
0
        public static void ChangeBlock( VoxelInfo voxelInfo, ushort data )
        {
            // multiplayer - send change to server
            if (Engine.EnableMultiplayer) {
            Engine.UniblocksNetwork.GetComponent<UniblocksClient>().SendChangeBlock ( voxelInfo, data );
            }

            // single player - apply change locally
            else {
            voxelInfo.chunk.SetVoxel (voxelInfo.index, data, true);

            GameObject voxelObject = Instantiate ( Engine.GetVoxelGameObject (data) ) as GameObject;
            if (voxelObject.GetComponent<VoxelEvents>() != null) {
                voxelObject.GetComponent<VoxelEvents>().OnBlockChange(voxelInfo);
            }
            Destroy (voxelObject);
            }
        }
Exemplo n.º 14
0
 public virtual void OnBlockPlaceMultiplayer( VoxelInfo voxelInfo, NetworkPlayer sender )
 {
 }
Exemplo n.º 15
0
 public virtual void OnBlockPlace( VoxelInfo voxelInfo )
 {
 }
Exemplo n.º 16
0
 public virtual void OnBlockEnter( GameObject enteringObject, VoxelInfo voxelInfo )
 {
 }
Exemplo n.º 17
0
 public virtual void OnBlockDestroy( VoxelInfo voxelInfo )
 {
 }
Exemplo n.º 18
0
 public virtual void OnBlockDestroy(VoxelInfo voxelInfo)
 {
 }
Exemplo n.º 19
0
 public virtual void OnBlockChangeMultiplayer(VoxelInfo voxelInfo, NetworkPlayer sender)
 {
 }
Exemplo n.º 20
0
 public virtual void OnMouseUp( int mouseButton, VoxelInfo voxelInfo )
 {
 }
Exemplo n.º 21
0
 public static Vector3 VoxelInfoToPosition( VoxelInfo voxelInfo )
 {
     return voxelInfo.chunk.GetComponent<Chunk>().VoxelIndexToPosition (voxelInfo.index);
 }
Exemplo n.º 22
0
 public virtual void OnLook(VoxelInfo voxelInfo)
 {
 }
Exemplo n.º 23
0
        public void SendPlaceBlock( VoxelInfo info, ushort data )
        {
            // sends a voxel change to the server, which then redistributes it to other clients

            // convert to ints
            int chunkx = info.chunk.ChunkIndex.x;
            int chunky = info.chunk.ChunkIndex.y;
            int chunkz = info.chunk.ChunkIndex.z;

            // send to server
            if (Network.isServer) {
            GetComponent<UniblocksServer>().ServerPlaceBlock (Network.player, info.index.x, info.index.y, info.index.z, chunkx,chunky,chunkz, (int)data);
            }
            else {
            GetComponent<NetworkView>().RPC ("ServerPlaceBlock", RPCMode.Server, Network.player, info.index.x, info.index.y, info.index.z, chunkx,chunky,chunkz, (int)data);
            }
        }
Exemplo n.º 24
0
 public virtual void OnBlockStay(GameObject stayingObject, VoxelInfo voxelInfo)
 {
 }
Exemplo n.º 25
0
 public virtual void OnBlockEnter(GameObject enteringObject, VoxelInfo voxelInfo)
 {
 }
Exemplo n.º 26
0
 public virtual void OnBlockStay( GameObject stayingObject, VoxelInfo voxelInfo )
 {
 }
Exemplo n.º 27
0
 public override void OnBlockEnter( GameObject enteringObject, VoxelInfo voxelInfo )
 {
     Debug.Log ("OnBlockEnter at " + voxelInfo.chunk.ChunkIndex.ToString() + " / " + voxelInfo.index.ToString());
 }
Exemplo n.º 28
0
 public virtual void OnLook( VoxelInfo voxelInfo )
 {
 }
Exemplo n.º 29
0
 public virtual void OnBlockDestroyMultiplayer(VoxelInfo voxelInfo, NetworkPlayer sender)
 {
 }
Exemplo n.º 30
0
 public override void OnBlockEnter(GameObject enteringObject, VoxelInfo voxelInfo)
 {
     Debug.Log("OnBlockEnter at " + voxelInfo.chunk.ChunkIndex.ToString() + " / " + voxelInfo.index.ToString());
 }
Exemplo n.º 31
0
 public virtual void OnBlockChange(VoxelInfo voxelInfo)
 {
 }
Exemplo n.º 32
0
 public static Vector3 VoxelInfoToPosition(VoxelInfo voxelInfo)
 {
     return(voxelInfo.chunk.GetComponent <Chunk>().VoxelIndexToPosition(voxelInfo.index));
 }
Exemplo n.º 33
0
 public virtual void OnMouseHold(int mouseButton, VoxelInfo voxelInfo)
 {
 }
Exemplo n.º 34
0
 public virtual void OnBlockChange( VoxelInfo voxelInfo )
 {
 }
Exemplo n.º 35
0
 public virtual void OnBlockPlace(VoxelInfo voxelInfo)
 {
 }