add scripts

This commit is contained in:
Chikashi Miyama 2019-07-06 16:26:14 +02:00
parent 0f4cb17325
commit 25670a2cc4
5 changed files with 66 additions and 3 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 04a977321344e1843b4dfdcc5379bc17
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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()

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 15f0a7f631334db4b8eb3f40470f6739
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 686884c543f60d8478b36eecc0532d11
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: