diff --git a/Assets/Editor/BuildConfig.cs b/Assets/Editor/BuildConfig.cs index 95aa78aac08d27c4c248e78015e2c9047d143024..3ab1d49a3245b7b7736a08ad2c40efa7eab7ee08 100644 --- a/Assets/Editor/BuildConfig.cs +++ b/Assets/Editor/BuildConfig.cs @@ -18,8 +18,6 @@ namespace OVGames.HelloSender.Editor /// <summary> Wrapper of <see cref="BuildPlayerOptions"/> with improved build path configuration. </summary> public sealed class BuildConfig { - private BuildPlayerOptions options = new BuildPlayerOptions(); - /// <summary> Gets or sets the location of the build directory, relative to the project root directory. </summary> public string DirectoryPath { get; set; } @@ -30,6 +28,9 @@ namespace OVGames.HelloSender.Editor /// <see cref="BuildPipeline.BuildPlayer(BuildPlayerOptions)"/> with the <see cref="BuildReport"/>. </summary> public Action<BuildReport> AfterBuild { get; set; } + /// <summary> The build options. </summary> + private BuildPlayerOptions options = new BuildPlayerOptions(); + /// <summary> Gets or sets the options for <see cref="BuildPipeline.BuildPlayer(BuildPlayerOptions)"/>. </summary> /// <remarks> <see cref="BuildPlayerOptions.locationPathName"/> is automatically set to /// <see cref="DirectoryPath"/> + <see cref="RelativeFilePath"/>. </remarks> diff --git a/Assets/Editor/BuildHooks.cs b/Assets/Editor/BuildHooks.cs index f0bd1bb80bb3ce24f7facc2802f7b2bedd6e4342..1af2d4040900d46413c786d0502c357d737722d8 100644 --- a/Assets/Editor/BuildHooks.cs +++ b/Assets/Editor/BuildHooks.cs @@ -13,8 +13,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; -using UnityEngine; using UnityEditor; +using UnityEngine; namespace OVGames.HelloSender.Editor { @@ -22,32 +22,32 @@ namespace OVGames.HelloSender.Editor public static class BuildHooks { /// <summary> Path to the builds, relative to the project root folder. </summary> - public const string BUILD_PATH = "Builds/"; + private const string BUILD_PATH = "Builds/"; /// <summary> Name of the build. /// </summary> - public const string FILENAME = "Hello Sender"; + private const string FILENAME = "Hello Sender"; /// <summary> The path of the scene to build, relative to the project root folder. </summary> - public static readonly string[] scenesPath = { "Assets/Scenes/main.unity" }; + private static readonly string[] ScenesPath = { "Assets/Scenes/main.unity" }; /// <summary> List of <see cref="BuildConfig"/> for supported <see cref="BuildTarget"/>. </summary> - public static readonly Dictionary<BuildTarget, BuildConfig> configs = new Dictionary<BuildTarget, BuildConfig>() - { - { - BuildTarget.StandaloneWindows64, - new BuildConfig() - { - DirectoryPath = BUILD_PATH + "Windows/", - RelativeFilePath = FILENAME + ".exe", - Options = new BuildPlayerOptions() - { - scenes = scenesPath, - target = BuildTarget.StandaloneWindows64 - }, - AfterBuild = buildReport => { } - } - } - }; + private static readonly Dictionary<BuildTarget, BuildConfig> Configs = new Dictionary<BuildTarget, BuildConfig> + { + { + BuildTarget.StandaloneWindows64, + new BuildConfig + { + DirectoryPath = BUILD_PATH + "Windows/", + RelativeFilePath = FILENAME + ".exe", + Options = new BuildPlayerOptions + { + scenes = ScenesPath, + target = BuildTarget.StandaloneWindows64 + }, + AfterBuild = buildReport => { } + } + } + }; /// <summary> Calls <see cref="BuildWindows"/>. </summary> [MenuItem("OVGames/Hello Sender/Build for all platforms", priority = 0)] @@ -68,10 +68,10 @@ namespace OVGames.HelloSender.Editor /// <summary> Build for the specified <see cref="BuildTarget"/>. </summary> /// <param name="target"> The <see cref="BuildTarget"/> to build. </param> /// <param name="andRun"> Automatically run or not the build. </param> - public static void Build(BuildTarget target = BuildTarget.StandaloneWindows64, bool andRun = false) + private static void Build(BuildTarget target = BuildTarget.StandaloneWindows64, bool andRun = false) { // Get configuration - if (!configs.TryGetValue(target, out var configuration)) + if (!Configs.TryGetValue(target, out var configuration)) { throw new ArgumentException($"The {target} platform is not supported.", nameof(target)); } diff --git a/Assets/Scripts/Controller.cs b/Assets/Scripts/Controller.cs index 0268f3aada3147ede8a5e7c8a619137ab0ee9fdd..47f43752c4ec24caf3e852c4076ad0c8df349586 100644 --- a/Assets/Scripts/Controller.cs +++ b/Assets/Scripts/Controller.cs @@ -14,49 +14,50 @@ using LSL4Unity; using LSL4Unity.OV; using UnityEngine; -/// <summary> Controller is used to send some value with LSL. </summary> -/// <seealso cref="UnityEngine.MonoBehaviour" /> -public class Controller : MonoBehaviour +namespace OVGames.HelloSender { - // Settings - [SerializeField] private string signalStream = "ovSignal"; - [SerializeField] private string markerStream = "ovMarker"; - [SerializeField] private int channelCount = 1; + /// <summary> Controller is used to send some value with LSL. </summary> + /// <seealso cref="UnityEngine.MonoBehaviour" /> + public class Controller : MonoBehaviour + { + // Settings + [SerializeField] private string signalStream = "ovSignal"; + [SerializeField] private string markerStream = "ovMarker"; + [SerializeField] private int channelCount = 1; - // Variables - private liblsl.StreamOutlet outletSignal, outletMarker; - private float[] samples; - private float lastTime = 0; - private Writer logFile; + // Variables + private liblsl.StreamOutlet outletSignal, outletMarker; + private float[] samples; + private float lastTime = 0; + private Writer logFile; - private const int STIMULATION = GDFStimulations.GDF_BEEP; + private const int STIMULATION = GDFStimulations.GDF_BEEP; - /// <summary> Start is called before the first frame update. </summary> - void Start() - { - samples = new float[channelCount]; - liblsl.StreamInfo infoSignal = new liblsl.StreamInfo(signalStream, "signal", channelCount, liblsl.IRREGULAR_RATE, liblsl.channel_format_t.cf_float32); - outletSignal = new liblsl.StreamOutlet(infoSignal); - Debug.Log( - $"Creating Stream : Name = {infoSignal.Name()}, Type = {infoSignal.Type()}, Channel Count = {infoSignal.ChannelCount()}, Format = {infoSignal.ChannelFormat()}"); - liblsl.StreamInfo infoMarker = new liblsl.StreamInfo(markerStream, "Marker", 1, liblsl.IRREGULAR_RATE, liblsl.channel_format_t.cf_int32); - outletMarker = new liblsl.StreamOutlet(infoMarker); - Debug.Log( - $"Creating Stream : Name = {infoMarker.Name()}, Type = {infoMarker.Type()}, Channel Count = {infoMarker.ChannelCount()}, Format = {infoMarker.ChannelFormat()}"); - logFile = new Writer(); - } + /// <summary> Start is called before the first frame update. </summary> + void Start() + { + samples = new float[channelCount]; + liblsl.StreamInfo info = new liblsl.StreamInfo(signalStream, "signal", channelCount /*, irregular, float32*/); + outletSignal = new liblsl.StreamOutlet(info); + Debug.Log($"Creating Stream : Name = {info.Name()}, Type = {info.Type()}, Channel Count = {info.ChannelCount()}, Format = {info.ChannelFormat()}"); + info = new liblsl.StreamInfo(markerStream, "Marker", 1, liblsl.IRREGULAR_RATE, liblsl.channel_format_t.cf_int32); + outletMarker = new liblsl.StreamOutlet(info); + Debug.Log($"Creating Stream : Name = {info.Name()}, Type = {info.Type()}, Channel Count = {info.ChannelCount()}, Format = {info.ChannelFormat()}"); + logFile = new Writer(); + } - /// <summary> Update is called once per frame. </summary> - void Update() - { - float t = Time.time; - for (int i = 0; i < channelCount; ++i) { samples[i] = (float) Math.Sin(t + i); } - outletSignal.PushSample(samples, liblsl.LocalClock()); - if (t - lastTime > 1) + /// <summary> Update is called once per frame. </summary> + void Update() { - lastTime = t; - outletMarker.PushSample(new[] { STIMULATION }, liblsl.LocalClock()); - logFile.WriteLine($"{STIMULATION} at {Time.time}"); + float t = Time.time; + for (int i = 0; i < channelCount; ++i) { samples[i] = (float) Math.Sin(t + i); } + outletSignal.PushSample(samples, liblsl.LocalClock()); + if (t - lastTime > 1) + { + lastTime = t; + outletMarker.PushSample(new[] { STIMULATION }, liblsl.LocalClock()); + logFile.WriteLine($"{STIMULATION} at {Time.time}"); + } } } } diff --git a/Assets/Scripts/Writer.cs b/Assets/Scripts/Writer.cs index 69cbc030fdb268d261bf02d1fd2d2006f026485e..4707e68ba728ed20fe094c867e68ea433ed9aa28 100644 --- a/Assets/Scripts/Writer.cs +++ b/Assets/Scripts/Writer.cs @@ -13,49 +13,51 @@ using System; using System.IO; using UnityEngine; - -public class Writer +namespace OVGames.HelloSender { - private readonly string path; - - // Start is called before the first frame update - public Writer(string filePath = "") + public class Writer { + private readonly string path; - path = string.IsNullOrEmpty(filePath) ? Application.persistentDataPath + $"/log{ DateTime.Now.Hour }h{ DateTime.Now.Minute }.txt" : filePath; + // Start is called before the first frame update + public Writer(string filePath = "") + { + path = string.IsNullOrEmpty(filePath) ? Application.persistentDataPath + $"/log{DateTime.Now.Hour}h{DateTime.Now.Minute}.txt" : filePath; - if (File.Exists(path)) + if (File.Exists(path)) + { + try + { + File.Delete(path); + Debug.Log($"File \"{path}\" is deleted."); + } + catch (Exception e) + { + Console.WriteLine(e); + Debug.Log($"Exception \"{e}\" is occured when deleting file."); + throw; + } + } + else { Debug.Log($"File \"{path}\" is free."); } + } + + public void WriteLine(string msg) { try { - File.Delete(path); - Debug.Log($"File \"{path}\" is deleted."); + using (StreamWriter sw = new StreamWriter(path, true)) + { + sw.WriteLine(msg); + sw.Close(); + } + Debug.Log($"Msg \"{msg}\" is saved."); } catch (Exception e) { Console.WriteLine(e); - Debug.Log($"Exception \"{e}\" is occured when deleting file."); + Debug.Log($"Exception \"{e}\" is occured when message is saving."); throw; } } - else { Debug.Log($"File \"{path}\" is free."); } - } - - public void WriteLine(string msg) - { - try - { - StreamWriter sw = new StreamWriter(path, true); - sw.WriteLine(msg); - sw.Close(); - Debug.Log($"Msg \"{msg}\" is saved."); - - } - catch (Exception e) - { - Console.WriteLine(e); - Debug.Log($"Exception \"{e}\" is occured when message is saving."); - throw; - } } }