public void Update()
        {
            Chunk chunk = Engine.PositionToChunk(transform.position);

            if (chunk == null)
            {
                return;
            }

            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(gameObject, voxelInfo);
                }
                else // OnStay
                {
                    events.OnBlockStay(gameObject, voxelInfo);
                }
            }

            LastChunk = chunk;
            LastIndex = voxelIndex;

            Destroy(voxelObject);
        }
Exemple #2
0
        static void OnBlockPlace(VoxelInfo voxelInfo, GameObject voxelObject)
        {
            VoxelEvents ev = voxelObject.GetComponent <VoxelEvents>();

            if (ev != null)
            {
                ev.OnBlockPlace(voxelInfo);
            }
        }
Exemple #3
0
        static void OnBlockPlaceMultiplayer(VoxelInfo voxelInfo, GameObject voxelObject, NetworkPlayer sender)
        {
            VoxelEvents ev = voxelObject.GetComponent <VoxelEvents>();

            if (ev != null)
            {
                ev.OnBlockPlace(voxelInfo);
                ev.OnBlockPlaceMultiplayer(voxelInfo, sender);
            }
        }
        // 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);
        }
        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);
        }
Exemple #6
0
        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 = 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(voxelIndex) == false)
                {
                    events.OnBlockEnter(gameObject, voxelInfo);
                }

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

            lastChunk = chunk;

            Destroy(voxelObject);
        }