add scripts
This commit is contained in:
parent
0f4cb17325
commit
25670a2cc4
5 changed files with 66 additions and 3 deletions
8
UnityProject/Assets/Scripts/PdConnection.meta
Normal file
8
UnityProject/Assets/Scripts/PdConnection.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 04a977321344e1843b4dfdcc5379bc17
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -5,13 +5,24 @@ namespace PdConnection
|
||||||
{
|
{
|
||||||
public class PdBuffer : IDisposable
|
public class PdBuffer : IDisposable
|
||||||
{
|
{
|
||||||
|
public float[] Data { get; }
|
||||||
|
|
||||||
private readonly MemoryMappedFile memoryMappedFile_;
|
private readonly MemoryMappedFile memoryMappedFile_;
|
||||||
private readonly MemoryMappedViewAccessor viewAccessor_;
|
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();
|
viewAccessor_ = memoryMappedFile_.CreateViewAccessor();
|
||||||
|
Data = new float[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
viewAccessor_.ReadArray(0, Data, 0, Data.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|
11
UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs.meta
Normal file
11
UnityProject/Assets/Scripts/PdConnection/PdBuffer.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 15f0a7f631334db4b8eb3f40470f6739
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
22
UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs
Normal file
22
UnityProject/Assets/Scripts/PdConnection/PdBufferTest.cs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 686884c543f60d8478b36eecc0532d11
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in a new issue