示例#1
0
        public static VoxelInfo PositionToVoxelInfo(Vector3 position)
        {
            GameObject chunkObject = Engine.PositionToChunk(position);

            if (chunkObject != null)
            {
                Chunk chunk      = chunkObject.GetComponent <Chunk>();
                Index voxelIndex = chunk.PositionToVoxelIndex(position);
                return(new VoxelInfo(voxelIndex, chunk));
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        public void Update()
        {
            // 检测chunk存在
            GameObject chunkObject = Engine.PositionToChunk(transform.position);

            if (chunkObject == null)
            {
                return;
            }

            // 获取体素信息
            Chunk     chunk      = chunkObject.GetComponent <Chunk>();
            Index     voxelIndex = chunk.PositionToVoxelIndex(transform.position);
            VoxelInfo voxelInfo  = new VoxelInfo(voxelIndex, chunk);

            // 获取拷贝
            GameObject voxelObject = Instantiate(Engine.GetVoxelGameObject(voxelInfo.GetVoxel())) as GameObject;

            VoxelEvents events = voxelObject.GetComponent <VoxelEvents>();

            if (events != null)
            {
                //进入某体素
                if (chunk != LastChunk || voxelIndex.IsEqual(LastIndex) == false)
                {
                    events.OnBlockEnter(this.gameObject, voxelInfo);
                }
                //停留
                else
                {
                    events.OnBlockStay(this.gameObject, voxelInfo);
                }
            }

            LastChunk = chunk;
            LastIndex = voxelIndex;

            Destroy(voxelObject);
        }