private void assignDownflow() { var job1 = new Assets.MapJobs.Job5AssignDownslope() { numTriangles = mesh.numTriangles, _halfedges = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._halfedges), t_elevation = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(t_elevation), order_t = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(order_t), t_downslope_s = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(t_downflow_s), }; job1.Execute(); }
public unsafe void setRiverGeometry(Float lg_min_flow, Float lg_river_width, Float spacing) { var MIN_FLOW = (Float)Math.Exp(lg_min_flow); var RIVER_WIDTH = (Float)Math.Exp(lg_river_width); var flow_out_s = new NativeArray <int>(mesh.numSides, Allocator.TempJob); var rivers_cnt = new NativeArray <int>(1, Allocator.TempJob); var job1 = new Job6SetFlowOutSide() { MIN_FLOW = MIN_FLOW, numSolidTriangles = mesh.numSolidTriangles, _halfedges = mesh._halfedges, t_downslope_s = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(t_downslope_s), s_flow = s_flow, flow_out_s = flow_out_s, result = rivers_cnt, }; job1.Execute(); var job2 = new Job6SetRiverGeomerty() { numRiverSizes = riverTex.NumSizes, MIN_FLOW = MIN_FLOW, RIVER_WIDTH = RIVER_WIDTH, spacing = spacing, _halfedges = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._halfedges), _triangles = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._triangles), _r_vertex = (Float2 *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._r_vertex), s_flow = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(s_flow), s_length = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh.s_length), flow_out_s = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(flow_out_s), t_downslope_s = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(t_downslope_s), river_uv = (Vector2 *)NativeArrayUnsafeUtility.GetUnsafePtr(riverTex.uv), vertex = (Vector3 *)NativeArrayUnsafeUtility.GetUnsafePtr(rivers_v3), uv = (Vector2 *)NativeArrayUnsafeUtility.GetUnsafePtr(rivers_uv), }; riverCount = rivers_cnt[0]; //Debug.Log($"rivers_cnt[0]:{rivers_cnt[0]}"); Parallel.For(0, riverCount, i => { job2.Execute(i); }); //for (int i = 0; i < rivers_cnt[0]; ++i) job2.Execute(i); flow_out_s.Dispose(); rivers_cnt.Dispose(); }
/// <summary> /// Writes a native array to the buffer. /// </summary> public static unsafe void WriteToStream <T>(this NativeArray <T> nativeArray, Buffer buffer) where T : struct { var numBytes = nativeArray.Length * UnsafeUtility.SizeOf <T>(); var byteArray = new byte[numBytes]; fixed(byte *dst = &byteArray[0]) { UnsafeUtility.MemCpy(dst, NativeArrayUnsafeUtility.GetUnsafePtr(nativeArray), byteArray.Length); } buffer.Write(byteArray); }
public unsafe void UnsafeUtility_MemSwap_DoesThrow_Overlapped() { using (var array0 = MakeTestArray(0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678)) { var mem = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(array0); var len = array0.Length * UnsafeUtility.SizeOf <int>(); Assert.DoesNotThrow(() => { UnsafeUtilityExtensions.MemSwap(mem + 10, mem, 10); }); Assert.Throws <InvalidOperationException>(() => { UnsafeUtilityExtensions.MemSwap(mem + 10, mem, len - 10); }); Assert.DoesNotThrow(() => { UnsafeUtilityExtensions.MemSwap(mem, mem + 10, 10); }); Assert.Throws <InvalidOperationException>(() => { UnsafeUtilityExtensions.MemSwap(mem, mem + 10, len - 10); }); } }
public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) { var srcComponentData = chunk.GetNativeArray(ComponentType); var sourcePtr = (byte *)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(srcComponentData); var sizeOfComponentType = UnsafeUtility.SizeOf <T>(); var destinationPtr = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(ComponentData) + sizeOfComponentType * entityOffset; var copySizeInBytes = UnsafeUtility.SizeOf <T>() * chunk.Count; UnsafeUtility.MemCpy(destinationPtr, sourcePtr, copySizeInBytes); }
/// <summary> /// Writes a native array to the binary writer. /// </summary> internal static unsafe void WriteToStream <T>(this NativeArray <T> nativeArray, BinaryWriter writer) where T : struct { var numBytes = nativeArray.Length * UnsafeUtility.SizeOf <T>(); var buffer = new byte[numBytes]; fixed(byte *dst = &buffer[0]) { UnsafeUtility.MemCpy(dst, NativeArrayUnsafeUtility.GetUnsafePtr(nativeArray), buffer.Length); } writer.Write(buffer); }
internal unsafe static void ExecuteInternal(ref JobChunkData <T> jobData, ref JobRanges ranges, int jobIndex) { var filteredChunks = (ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(jobData.PrefilterData); var entityIndices = (int *)(filteredChunks + ranges.TotalIterationCount); int chunkIndex, end; while (JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out chunkIndex, out end)) { var chunk = filteredChunks[chunkIndex]; var entityOffset = entityIndices[chunkIndex]; jobData.Data.Execute(chunk, chunkIndex, entityOffset); } }
public void CopyTo(int aSrcIndex, NativeArray <char> aDst, int aDstIndex, int aCount) { if (aSrcIndex < 0 || aCount < 0 || aDstIndex < 0 || aSrcIndex + aCount > m_Length || aDstIndex + aCount > aDst.Length) { throw new ArgumentOutOfRangeException(); } var aDstPtr = (char *)NativeArrayUnsafeUtility.GetUnsafePtr(aDst); aCount += aSrcIndex; while (aSrcIndex < aCount) { aDstPtr[aDstIndex++] = m_Ptr[aSrcIndex++]; } }
private void create(int seed, NativeArray <byte> buffer) { var p = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(buffer); p256 = p; perm = &p[256]; permMod12 = &perm[512]; buildPermutationTable(seed); for (int i = 0; i < 512; i++) { perm[i] = p256[i & 255]; permMod12[i] = (byte)(perm[i] % 12); } }
public unsafe void setMeshGeometry() { int numRegions = mesh.numRegions, numTriangles = mesh.numTriangles; var job = new Job7SetMeshGeomerty() { numRegions = numRegions, _r_vertex = (Float2 *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._r_vertex), _t_vertex = (Float2 *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._t_vertex), vertex = land_v3, }; Parallel.For(0, numRegions + numTriangles, i => { job.Execute(i); }); }
public unsafe void assignElevation(Float noisy_coastlines, Float hill_height, Float ocean_depth) { var job1 = new Job2AssignSolidTriangle() { elevation = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(elevation), paintSize = CANVAS_SIZE, noisy_coastlines = noisy_coastlines, t_noise4 = preNoise.t_noise4, t_noise5 = preNoise.t_noise5, t_noise6 = preNoise.t_noise6, t_vertex = mesh._t_vertex, t_elevation = t_elevation }; int mountain_slope = 20; var job2 = new Job2AssignTriangleElevation() { t_noise0 = preNoise.t_noise0, t_noise1 = preNoise.t_noise1, t_noise2 = preNoise.t_noise2, t_noise4 = preNoise.t_noise4, t_mountain_distance = t_mountain_distance, hill_height = hill_height, ocean_depth = ocean_depth, mountain_slope = mountain_slope, t_elevation = t_elevation }; var job3 = new Job3AssignRegionElevation() { _r_in_s = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._r_in_s), _halfedges = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._halfedges), t_elevation = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(t_elevation), r_elevation = r_elevation, }; Parallel.For(0, mesh.numSolidTriangles, i => { job1.Execute(i); }); Parallel.For(0, mesh.numTriangles, i => { job2.Execute(i); }); Parallel.For(0, mesh.numRegions, i => { job3.Execute(i); }); }
internal static unsafe void UpdateBounds(this SpriteSkin spriteSkin, NativeArray <byte> deformedVertices) { byte *deformedPosOffset = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(deformedVertices); var spriteVertexCount = spriteSkin.sprite.GetVertexCount(); var spriteVertexStreamSize = spriteSkin.sprite.GetVertexStreamSize(); NativeSlice <float3> deformedPositions = NativeSliceUnsafeUtility.ConvertExistingDataToNativeSlice <float3>(deformedPosOffset, spriteVertexStreamSize, spriteVertexCount); #if ENABLE_UNITY_COLLECTIONS_CHECKS var handle = CreateSafetyChecks <float3>(ref deformedPositions); #endif spriteSkin.bounds = CalculateSpriteSkinBounds(deformedPositions); #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSafetyChecks(handle); #endif InternalEngineBridge.SetLocalAABB(spriteSkin.spriteRenderer, spriteSkin.bounds); }
/// <summary> /// Copy <paramref name="colors" /> to a NativeArray. /// </summary> /// <remarks> /// In <paramref name="colors" />, pixels are laid out left to right, bottom to top, /// but in the returned array, left to right, top to bottom. /// </remarks> public static NativeArray <byte> FromPixels32(Color32[] colors, int width, int height, bool isFlipped = false, Allocator allocator = Allocator.Temp) { var pixelData = new NativeArray <byte>(colors.Length * 4, allocator, NativeArrayOptions.UninitializedMemory); unsafe { fixed(Color32 *src = colors) { byte *pDest = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(pixelData); if (isFlipped) { Color32 *pSrc = src + colors.Length - 1; for (var i = 0; i < colors.Length; i++) { *pDest++ = pSrc->r; *pDest++ = pSrc->g; *pDest++ = pSrc->b; *pDest++ = pSrc->a; pSrc--; } } else { Color32 *pSrc = src; for (var i = 0; i < height; i++) { Color32 *pRowSrc = pSrc + width * (height - 1 - i); for (var j = 0; j < width; j++) { *pDest++ = pRowSrc->r; *pDest++ = pRowSrc->g; *pDest++ = pRowSrc->b; *pDest++ = pRowSrc->a; pRowSrc++; } } } } } return(pixelData); }
private static void assignTriangleCenters(DualMesh mesh, NativeArray <double> r_xyz, NativeArray <double> t_xyz) { var numTriangles = mesh.numTriangles; var _r_xyz = (double *)NativeArrayUnsafeUtility.GetUnsafePtr(r_xyz); var _t_xyz = (double *)NativeArrayUnsafeUtility.GetUnsafePtr(t_xyz); Action <int> action = t => { int a = mesh.s_begin_r(3 * t + 0), b = mesh.s_begin_r(3 * t + 1), c = mesh.s_begin_r(3 * t + 2); CentroidOfTriangle(_r_xyz, a, b, c, _t_xyz, t); }; //for (var t = 0; t < numTriangles; t++) action(t); Parallel.For(0, numTriangles, action); }
private void assignFlow(Float flow = 0.5f) { var job2 = new Assets.MapJobs.Job5AssignFlow() { flow = flow, numTriangles = mesh.numTriangles, _halfedges = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(mesh._halfedges), t_elevation = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(t_elevation), order_t = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(order_t), t_downslope_s = (int *)NativeArrayUnsafeUtility.GetUnsafePtr(t_downflow_s), t_moisture = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(t_moisture), t_flow = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(t_flow), s_flow = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(s_flow), }; job2.Execute(); }
public unsafe void UnsafeUtility_MemSwap() { using (var array0 = MakeTestArray(0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678, 0x12345678)) using (var array1 = MakeTestArray(0x21436587, 0x21436587, 0x21436587, 0x21436587, 0x21436587, 0x21436587)) { UnsafeUtilityExtensions.MemSwap(NativeArrayUnsafeUtility.GetUnsafePtr(array0), NativeArrayUnsafeUtility.GetUnsafePtr(array1), array0.Length * UnsafeUtility.SizeOf <int>()); foreach (var b in array0) { Assert.AreEqual(0x21436587, b); } foreach (var b in array1) { Assert.AreEqual(0x12345678, b); } } }
// Quantize single or multiple vectors with the product quantizer unsafe void ComputeCode(float *x_ptr, byte *code_ptr) { float *distances = stackalloc float[ksub]; float *y_ptr = (float *)NativeArrayUnsafeUtility.GetUnsafePtr(centroids); for (int m = 0; m < M; m++) { int index = -1; float minimumDistance = float.MaxValue; int mdsub = m * dsub; int mksubdsub = m * ksub * dsub; for (int i = 0; i < ksub; ++i) { int idsub = i * dsub; float l2square = 0.0f; for (int j = 0; j < dsub; j++) { float d = x_ptr[mdsub + j] - y_ptr[mksubdsub + idsub + j]; l2square += d * d; } distances[i] = l2square; } // // Find best centroid // for (int i = 0; i < ksub; i++) { float distance = distances[i]; if (distance < minimumDistance) { minimumDistance = distance; index = i; } } code_ptr[m] = (byte)index; } }
internal unsafe static void CalculateBounds(this SpriteSkin spriteSkin) { Debug.Assert(spriteSkin.isValid); var sprite = spriteSkin.sprite; var deformVertexData = new NativeArray <byte>(sprite.GetVertexStreamSize() * sprite.GetVertexCount(), Allocator.Temp, NativeArrayOptions.UninitializedMemory); void *dataPtr = NativeArrayUnsafeUtility.GetUnsafePtr(deformVertexData); var deformedPosSlice = NativeSliceUnsafeUtility.ConvertExistingDataToNativeSlice <Vector3>(dataPtr, sprite.GetVertexStreamSize(), sprite.GetVertexCount()); #if ENABLE_UNITY_COLLECTIONS_CHECKS NativeSliceUnsafeUtility.SetAtomicSafetyHandle(ref deformedPosSlice, NativeArrayUnsafeUtility.GetAtomicSafetyHandle(deformVertexData)); #endif spriteSkin.Bake(ref deformVertexData); UpdateBounds(spriteSkin, deformVertexData); deformVertexData.Dispose(); }
public static unsafe BlobAssetReference <Collider> Create(float3 *vertices, int *indices, int numVertices, int numIndices, CollisionFilter?filter = null, Material?material = null) { var v = new NativeArray <float3>(numVertices, Allocator.Temp); var vptr = NativeArrayUnsafeUtility.GetUnsafePtr(v); UnsafeUtility.MemCpy(vptr, vertices, numVertices * sizeof(float3)); var i = new NativeArray <int>(numIndices, Allocator.Temp); var iptr = NativeArrayUnsafeUtility.GetUnsafePtr(i); UnsafeUtility.MemCpy(iptr, indices, numIndices * sizeof(int)); var collider = MeshCollider.Create(v, i); v.Dispose(); i.Dispose(); return(collider); }
public unsafe Texture2D LoadTextureData(GraphicsFormat gf) { Profiler.BeginSample("LoadTextureData"); byte *data; uint length; ktx_get_data(nativeReference, out data, out length); bool mipmap = numLevels > 1; Profiler.BeginSample("CreateTexture2D"); var texture = new Texture2D( (int)baseWidth, (int)baseHeight, gf, mipmap ? TextureCreationFlags.MipChain : TextureCreationFlags.None ); Profiler.EndSample(); if (mipmap) { Profiler.BeginSample("MipMapCopy"); var reorderedData = new NativeArray <byte>((int)length, Allocator.Temp); void *reorderedDataPtr = NativeArrayUnsafeUtility.GetUnsafePtr <byte>(reorderedData); ktx_copy_data_levels_reverted( nativeReference, reorderedDataPtr, (uint)reorderedData.Length ); texture.LoadRawTextureData(reorderedData); reorderedData.Dispose(); Profiler.EndSample(); } else { Profiler.BeginSample("LoadRawTextureData"); texture.LoadRawTextureData((IntPtr)data, (int)length); Profiler.EndSample(); } texture.Apply(false, true); Profiler.EndSample(); return(texture); }
void assignTriangleValues() { var mesh = this.mesh; var t_elevation = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(this.t_elevation); var t_moisture = (Float *)NativeArrayUnsafeUtility.GetUnsafePtr(this.t_moisture); var numTriangles = mesh.numTriangles; Action <int> action = t => { var s0 = 3 * t; int r1 = mesh.s_begin_r(s0), r2 = mesh.s_begin_r(s0 + 1), r3 = mesh.s_begin_r(s0 + 2); t_elevation[t] = 1f / 3 * (r_elevation[r1] + r_elevation[r2] + r_elevation[r3]); t_moisture[t] = 1f / 3 * (r_moisture[r1] + r_moisture[r2] + r_moisture[r3]); }; //for (var t = 0; t < numTriangles; t++) action(t); Parallel.For(0, numTriangles, action); }
public void Start() { Debug.Assert(Status != ReadStatus.Reading); Status = ReadStatus.Reading; if (Type == ReadType.Native) { NativeReadRequest = AsyncGPUReadback.Request(Texture, 0, ReadFormat); } else if (Type == ReadType.LinuxOpenGL) { Data = new NativeArray <byte>(Texture.width * Texture.height * BytesPerPixel, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); unsafe { var ptr = new System.IntPtr(NativeArrayUnsafeUtility.GetUnsafePtr(Data)); AsyncTextureReaderStart(LinuxId, ptr); GL.IssuePluginEvent(LinuxUpdate, LinuxId); } } }
protected override unsafe void OnUpdate() { var deltaTime = UnityEngine.Time.deltaTime; EntityManager.AddMatchingArchetypes(q2d, f2d); EntityManager.AddMatchingArchetypes(q3d, f3d); var positionType = EntityManager.GetArchetypeChunkComponentType <Position>(false); var speedType = EntityManager.GetArchetypeChunkComponentType <MoveSpeed>(true); var h2d = EntityManager.GetArchetypeChunkComponentType <Heading2D>(true); var h3d = EntityManager.GetArchetypeChunkComponentType <Heading3D>(true); using (var c2d = EntityManager.CreateArchetypeChunkArray(f2d, Allocator.Temp)) { for (int i = 0; i < c2d.Length; i++) { var h2dAccessor = c2d[i].GetNativeArray(h2d); var speedAccessor = c2d[i].GetNativeArray(speedType); var posAccessor = c2d[i].GetNativeArray(positionType); var ptr = (Position *)NativeArrayUnsafeUtility.GetUnsafePtr(posAccessor); for (int j = 0; j < posAccessor.Length; j++, ptr++) { var times = speedAccessor[j].Value * deltaTime; ptr->Value = new float3(ptr->Value.x + times * h2dAccessor[j].Value.x, ptr->Value.y, ptr->Value.z + times * h2dAccessor[j].Value.y); } } } using (var c3d = EntityManager.CreateArchetypeChunkArray(f3d, Allocator.Temp)) { for (int i = 0; i < c3d.Length; i++) { var h3dAccessor = c3d[i].GetNativeArray(h3d); var speedAccessor = c3d[i].GetNativeArray(speedType); var posAccessor = c3d[i].GetNativeArray(positionType); var ptr = (Position *)NativeArrayUnsafeUtility.GetUnsafePtr(posAccessor); for (int j = 0; j < posAccessor.Length; j++) { ptr->Value += speedAccessor[j].Value * deltaTime * h3dAccessor[j].Value; } } } }
internal unsafe static void Deform(Sprite sprite, Matrix4x4 rootInv, NativeSlice <Vector3> vertices, NativeSlice <Vector4> tangents, NativeSlice <BoneWeight> boneWeights, NativeArray <Matrix4x4> boneTransforms, NativeSlice <Matrix4x4> bindPoses, NativeArray <byte> deformableVertices) { var verticesFloat3 = vertices.SliceWithStride <float3>(); var tangentsFloat4 = tangents.SliceWithStride <float4>(); var bindPosesFloat4x4 = bindPoses.SliceWithStride <float4x4>(); var spriteVertexCount = sprite.GetVertexCount(); var spriteVertexStreamSize = sprite.GetVertexStreamSize(); var boneTransformsFloat4x4 = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <float4x4>(boneTransforms.GetUnsafePtr(), boneTransforms.Length, Allocator.None); byte *deformedPosOffset = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(deformableVertices); NativeSlice <float3> deformableVerticesFloat3 = NativeSliceUnsafeUtility.ConvertExistingDataToNativeSlice <float3>(deformedPosOffset, spriteVertexStreamSize, spriteVertexCount); NativeSlice <float4> deformableTangentsFloat4 = NativeSliceUnsafeUtility.ConvertExistingDataToNativeSlice <float4>(deformedPosOffset, spriteVertexStreamSize, 1); // Just Dummy. if (sprite.HasVertexAttribute(Rendering.VertexAttribute.Tangent)) { byte *deformedTanOffset = deformedPosOffset + sprite.GetVertexStreamOffset(Rendering.VertexAttribute.Tangent); deformableTangentsFloat4 = NativeSliceUnsafeUtility.ConvertExistingDataToNativeSlice <float4>(deformedTanOffset, spriteVertexStreamSize, spriteVertexCount); } #if ENABLE_UNITY_COLLECTIONS_CHECKS var handle1 = CreateSafetyChecks <float4x4>(ref boneTransformsFloat4x4); var handle2 = CreateSafetyChecks <float3>(ref deformableVerticesFloat3); var handle3 = CreateSafetyChecks <float4>(ref deformableTangentsFloat4); #endif if (sprite.HasVertexAttribute(Rendering.VertexAttribute.Tangent)) { Deform(rootInv, verticesFloat3, tangentsFloat4, boneWeights, boneTransformsFloat4x4, bindPosesFloat4x4, deformableVerticesFloat3, deformableTangentsFloat4); } else { Deform(rootInv, verticesFloat3, boneWeights, boneTransformsFloat4x4, bindPosesFloat4x4, deformableVerticesFloat3); } #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSafetyChecks(handle1); DisposeSafetyChecks(handle2); DisposeSafetyChecks(handle3); #endif }
protected override unsafe void OnUpdate() { float deltaTime = Time.deltaTime; manager.AddMatchingArchetypes(query, foundArchetypes); var RotationTypeRW = manager.GetArchetypeChunkComponentType <Rotation>(false); var DokabenRotationDataTypeRW = manager.GetArchetypeChunkComponentType <DokabenRotationData>(false); using (var chunks = manager.CreateArchetypeChunkArray(foundArchetypes, Allocator.TempJob)) { for (int i = 0; i < chunks.Length; ++i) { var rots = chunks[i].GetNativeArray(RotationTypeRW); if (rots.Length == 0) { continue; } var dokabens = chunks[i].GetNativeArray(DokabenRotationDataTypeRW); var rotPtr = (Rotation *)NativeArrayUnsafeUtility.GetUnsafePtr(rots); var dokabenPtr = (DokabenRotationData *)NativeArrayUnsafeUtility.GetUnsafePtr(dokabens); for (int j = 0; j < rots.Length; ++j, ++rotPtr, ++dokabenPtr) { if (dokabenPtr->DeltaTimeCounter < Constants.ParentTest.Interval) { dokabenPtr->DeltaTimeCounter += deltaTime; continue; } dokabenPtr->DeltaTimeCounter = 0; dokabenPtr->CurrentRot += dokabenPtr->CurrentAngle; rotPtr->Value = quaternion.AxisAngle(new float3(1, 0, 0), math.radians(dokabenPtr->CurrentRot)); ++dokabenPtr->FrameCounter; if (dokabenPtr->FrameCounter >= Constants.ParentTest.Framerate) { dokabenPtr->CurrentAngle = -dokabenPtr->CurrentAngle; dokabenPtr->FrameCounter = 0; } } } } }
private void assignTextureCoordinates() { var width = Mathf.Floor((textureSize - 2 * spacing) / (2 * numSizes + 3)) - spacing; var height = Mathf.Floor((textureSize - 2 * spacing) / (numSizes + 1)) - spacing; var pV = (Vector2 *)NativeArrayUnsafeUtility.GetUnsafePtr(vertex); var pU = (Vector2 *)NativeArrayUnsafeUtility.GetUnsafePtr(uv); var SizeMax = numSizes + 1; for (var row = 0; row < SizeMax; ++row) { for (var col = 0; col < SizeMax; ++col) { var baseX = spacing + (2 * spacing + 2 * width) * col; var baseY = spacing + (spacing + height) * row; var index = (row * SizeMax + col) * 6; setXY(baseX, baseY, width, height, &pV[index]); setUV(&pV[index], &pU[index]); } } }
public void AddComponentWithValidation(UnsafeMatchingArchetypePtrList archetypeList, EntityQueryFilter filter, ComponentType componentType, ComponentDependencyManager *dependencyManager) { AssertCanAddComponent(archetypeList, componentType); using (var chunks = ChunkIterationUtility.CreateArchetypeChunkArray(archetypeList, Collections.Allocator.TempJob, ref filter, dependencyManager)) { if (chunks.Length == 0) { return; } AssertCanAddComponent(chunks, componentType); //@TODO the fast path for a chunk that contains a single entity is only possible if the chunk doesn't have a Locked Entity Order //but we should still be allowed to add zero sized components to chunks with a Locked Entity Order, even ones that only contain a single entity /* * if ((chunks.Length == 1) && (chunks[0].Count == 1)) * { * var entityPtr = (Entity*) chunks[0].m_Chunk->Buffer; * StructuralChange.AddComponentEntity(EntityComponentStore, entityPtr, componentType.TypeIndex); * } * else * { */ AddComponent((ArchetypeChunk *)NativeArrayUnsafeUtility.GetUnsafePtr(chunks), chunks.Length, componentType); /* * } */ } }
protected override unsafe void OnUpdate() { EntityManager.AddMatchingArchetypes(qMover, fMover); var MoveSpeedTypeRW = EntityManager.GetArchetypeChunkComponentType <MoveSpeed>(false); var PositionTypeRO = EntityManager.GetArchetypeChunkComponentType <Position>(true); var EntityRO = EntityManager.GetArchetypeChunkEntityType(); using (var moverChunks = EntityManager.CreateArchetypeChunkArray(fMover, Allocator.Temp)) { for (int i = 0; i < moverChunks.Length; i++) { var entities = moverChunks[i].GetNativeArray(EntityRO); if (entities.Length == 0) { continue; } var speeds = moverChunks[i].GetNativeArray <MoveSpeed>(MoveSpeedTypeRW); var ptr = (MoveSpeed *)NativeArrayUnsafeUtility.GetUnsafePtr(speeds); var positions = moverChunks[i].GetNativeArray <Position>(PositionTypeRO); if (EntityManager.HasComponent <Controlable>(entities[0])) { for (int j = 0; j < positions.Length; ++j, ++ptr) { ptr->Value = playerSpeed[chips[((uint)positions[j].Value.x) + range.x * (uint)positions[j].Value.z].Value - 1]; } } else { for (int j = 0; j < positions.Length; ++j, ++ptr) { ptr->Value = enemySpeed[chips[((uint)positions[j].Value.x) + range.x * (uint)positions[j].Value.z].Value - 1]; } } } } }
public static NativeArray <byte> FromPixels32(Color32[] colors, Allocator allocator = Allocator.Temp) { var pixelData = new NativeArray <byte>(colors.Length * 3, allocator, NativeArrayOptions.UninitializedMemory); unsafe { fixed(Color32 *src = colors) { Color32 *pSrc = src; byte *pDest = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(pixelData); for (var i = 0; i < colors.Length; i++) { *pDest++ = pSrc->r; *pDest++ = pSrc->g; *pDest++ = pSrc->b; pSrc++; } } } return(pixelData); }
public WaveGOLSystem(NativeArray <MaterialData> writeMaterialData, Resolution resolution) { this._writeDataPrt = NativeArrayUnsafeUtility.GetUnsafePtr(writeMaterialData); this._resolution = resolution; }