Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c4cb4f5e authored by MONSEIGNE Thibaut's avatar MONSEIGNE Thibaut
Browse files

:bug: Improve Code Smells

parent 9025ffff
No related branches found
No related tags found
No related merge requests found
Pipeline #139930 passed
......@@ -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>
......
......@@ -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));
}
......
......@@ -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}");
}
}
}
}
......@@ -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;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment