Пример #1
0
        public T this [int index]
        {
            get
            {
                CheckReadAccess(index);

                T result = default(T);

                int chunkIndex  = ms_CachedLayout.ChunkIndex(index);
                int chunkOffset = ms_CachedLayout.ChunkOffset(index);

                int fieldCount = ms_CachedLayout.FieldCount;

                uint *bp     = (uint *)(m_Base + StructLayoutData4.ChunkSizeBytes * ms_CachedLayout.FieldCount * chunkIndex + StructLayoutData4.ElementSize * chunkOffset);
                uint *target = (uint *)UnsafeUtility.AddressOf(ref result);

                for (int field = 0; field < fieldCount; ++field)
                {
                    var fieldInfo = ms_CachedLayout.GetFieldInfo(field);
                    target[fieldInfo.Offset / 4] = *bp;
                    bp += StructLayoutData4.ElementsPerChunk;
                }

                return(result);
            }

            set
            {
                CheckWriteAccess(index);

                int chunkIndex  = ms_CachedLayout.ChunkIndex(index);
                int chunkOffset = ms_CachedLayout.ChunkOffset(index);

                int fieldCount = ms_CachedLayout.FieldCount;

                uint *bp     = (uint *)UnsafeUtility.AddressOf(ref value);
                uint *target = (uint *)(m_Base + StructLayoutData4.ChunkSizeBytes * ms_CachedLayout.FieldCount * chunkIndex + StructLayoutData4.ElementSize * chunkOffset);

                for (int field = 0; field < fieldCount; ++field)
                {
                    var fieldInfo = ms_CachedLayout.GetFieldInfo(field);
                    *target = bp[fieldInfo.Offset / 4];
                    target += StructLayoutData4.ElementsPerChunk;
                }
            }
        }
Пример #2
0
        public T this [int index]
        {
            get
            {
                CheckReadAccess(index);

                T     result = default(T);
                uint *target = (uint *)UnsafeUtility.AddressOf(ref result);

                int fieldCount = ms_CachedLayout.FieldCount;
                int stride     = m_Length;

                uint *bp = (uint *)(m_Base + 4 * index);
                for (int field = 0; field < fieldCount; ++field)
                {
                    var fieldInfo = ms_CachedLayout.GetFieldInfo(field);
                    target[fieldInfo.Offset / 4] = *bp;
                    bp += stride;
                }

                return(result);
            }

            set
            {
                CheckWriteAccess(index);

                int fieldCount = ms_CachedLayout.FieldCount;

                int stride = m_Length;

                uint *bp     = (uint *)UnsafeUtility.AddressOf(ref value);
                uint *target = (uint *)(m_Base + 4 * index);

                for (int field = 0; field < fieldCount; ++field)
                {
                    var fieldInfo = ms_CachedLayout.GetFieldInfo(field);
                    *target = bp[fieldInfo.Offset / 4];
                    target += stride;
                }
            }
        }