diff --git a/UnityProject/Assets/Scripts/PdConnection.meta b/UnityProject/Assets/Scripts/PdConnection.meta new file mode 100644 index 0000000..0a6da65 --- /dev/null +++ b/UnityProject/Assets/Scripts/PdConnection.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 04a977321344e1843b4dfdcc5379bc17 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs b/UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs index 9abf421..a68d652 100644 --- a/UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs +++ b/UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs @@ -5,13 +5,24 @@ namespace PdConnection { public class PdBuffer : IDisposable { + public float[] Data { get; } + private readonly MemoryMappedFile memoryMappedFile_; private readonly MemoryMappedViewAccessor viewAccessor_; - - public PdBuffer() + + public PdBuffer(string name, int size) { - memoryMappedFile_ = MemoryMappedFile.OpenExisting("shared_memory"); + memoryMappedFile_ = MemoryMappedFile.OpenExisting(name); + if (memoryMappedFile_ == null) + throw new ArgumentException("no such shared memory"); + viewAccessor_ = memoryMappedFile_.CreateViewAccessor(); + Data = new float[size]; + } + + public void Update() + { + viewAccessor_.ReadArray(0, Data, 0, Data.Length); } public void Dispose() diff --git a/UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs.meta b/UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs.meta new file mode 100644 index 0000000..9c6c36d --- /dev/null +++ b/UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 15f0a7f631334db4b8eb3f40470f6739 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs b/UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs new file mode 100644 index 0000000..c051312 --- /dev/null +++ b/UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace PdConnection +{ + + public class PdBufferTest : MonoBehaviour + { + void Start() + { + var pdBuf = new PdBuffer("testarray", 100); + pdBuf.Update(); + foreach(var val in pdBuf.Data) + Debug.Log(val); + } + + + } + + +} diff --git a/UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs.meta b/UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs.meta new file mode 100644 index 0000000..ceb6dbf --- /dev/null +++ b/UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 686884c543f60d8478b36eecc0532d11 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: