public void FromNativeArray() { var array = new NativeArray <int>(4, Allocator.Temp) { [0] = 0, [1] = 1, [2] = 2, [3] = 3 }; var distinct = array.Distinct(); Assert.IsFalse(distinct.CanFastCount()); var enumerator = distinct.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(0, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(1, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(2, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(3, enumerator.Current); Assert.IsFalse(enumerator.MoveNext()); enumerator.Dispose(); array[3] = 0; enumerator = distinct.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(0, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(1, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(2, enumerator.Current); Assert.IsFalse(enumerator.MoveNext()); enumerator.Dispose(); array[3] = 0; array[2] = 1; array[1] = 2; array[0] = 3; enumerator = distinct.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(3, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(2, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(1, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(0, enumerator.Current); Assert.IsFalse(enumerator.MoveNext()); enumerator.Dispose(); array.Dispose(); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { using (var context = new BlobAssetComputationContext <SequentialHelenHayesSettings, SequentialPositionsBlobAsset>(conversionSystem.BlobAssetStore, 1, Allocator.Temp)) { var hash = new Hash128((uint)FilePath.GetHashCode(), 0, 0, 0); context.AssociateBlobAssetWithUnityObject(hash, gameObject); if (context.NeedToComputeBlobAsset(hash)) { var indexes = new NativeArray <int>(Constants.PositionCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); indexes[Constants.FrontHeadIndex] = FrontHeadIndex; indexes[Constants.TopHeadIndex] = TopHeadIndex; indexes[Constants.RearHeadIndex] = RearHeadIndex; indexes[Constants.RightOffsetIndex] = RightOffsetIndex; indexes[Constants.VSacralIndex] = VSacralIndex; indexes[Constants.LeftShoulderIndex] = LeftShoulderIndex; indexes[Constants.LeftElbowIndex] = LeftElbowIndex; indexes[Constants.LeftWristIndex] = LeftWristIndex; indexes[Constants.RightShoulderIndex] = RightShoulderIndex; indexes[Constants.RightElbowIndex] = RightElbowIndex; indexes[Constants.RightWristIndex] = RightWristIndex; indexes[Constants.LeftAsisIndex] = LeftAsisIndex; indexes[Constants.LeftTightIndex] = LeftTightIndex; indexes[Constants.LeftKneeIndex] = LeftKneeIndex; indexes[Constants.LeftKneeMedIndex] = LeftKneeMedIndex; indexes[Constants.LeftShankIndex] = LeftShankIndex; indexes[Constants.LeftAnkleIndex] = LeftAnkleIndex; indexes[Constants.LeftAnkleMedIndex] = LeftAnkleMedIndex; indexes[Constants.LeftHeelIndex] = LeftHeelIndex; indexes[Constants.LeftToeIndex] = LeftToeIndex; indexes[Constants.RightAsisIndex] = RightAsisIndex; indexes[Constants.RightTightIndex] = RightTightIndex; indexes[Constants.RightKneeIndex] = RightKneeIndex; indexes[Constants.RightKneeMedIndex] = RightKneeMedIndex; indexes[Constants.RightShankIndex] = RightShankIndex; indexes[Constants.RightAnkleIndex] = RightAnkleIndex; indexes[Constants.RightAnkleMedIndex] = RightAnkleMedIndex; indexes[Constants.RightHeelIndex] = RightHeelIndex; indexes[Constants.RightToeIndex] = RightToeIndex; Assert.AreEqual(29, indexes.Distinct().Count()); var readToEnd = File.ReadAllLines(Path.Combine(Application.streamingAssetsPath, FilePath)); var headSkip = (HasHeader ? 1 : 0); var dataLength = readToEnd.Length - headSkip; var positions = new NativeArray <float3>(dataLength * Constants.PositionCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); for (var i = 0; i < dataLength; ++i) { var data = Array.ConvertAll(readToEnd[i + headSkip].Split(','), (string s) => { if (float.TryParse(s, out var f)) { return(f); } else { return(float.NaN); } }); for (var j = 0; j < Constants.PositionCount; ++j) { // Convert coordinate system, and 0.001f means milli metre to metre positions[i * Constants.PositionCount + j] = new float3(data[j * 3], data[j * 3 + 2], data[j * 3 + 1]) * 0.001f; } } context.AddBlobAssetToCompute(hash, new SequentialHelenHayesSettings()); var job = new SequentialHelenHayesJob(positions, indexes); job.Schedule().Complete(); context.AddComputedBlobAsset(hash, job.BlobAssets[0]); job.BlobAssets.Dispose(); } context.GetBlobAsset(hash, out var blob); dstManager.AddComponentData(entity, new SequentialHelenHayesData { BlobData = blob }); } }