Skip to content

Commit

Permalink
Setting にリネーム
Browse files Browse the repository at this point in the history
  • Loading branch information
nasshu2916 committed Oct 29, 2024
1 parent 5c90e5b commit 5ac483c
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Assets/ArtNet/Editor/DmxRecorder/DmxRecordWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void ShowDmxRecorder()

private void Initialize(VisualElement root)
{
_recorder.RecorderConfigs = RecorderConfigs.GetOrNewGlobalConfigs();
_recorder.RecorderSettings = RecorderSettings.GetOrNewGlobalSettings();

var tabContent = new VisualElement { name = "tabContent" };
root.Add(tabContent);
Expand Down
8 changes: 4 additions & 4 deletions Assets/ArtNet/Editor/DmxRecorder/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Recorder()
_receiver.OnReceivedPacket = OnReceivedPacket;
}
public RecordingStatus Status { get; private set; } = RecordingStatus.None;
public RecorderConfigs RecorderConfigs { get; set; }
public RecorderSettings RecorderSettings { get; set; }

public int GetRecordedCount() => _recordedDmx.Count;

Expand Down Expand Up @@ -124,7 +124,7 @@ private void StoreDmxPacket()
return;
}

switch (RecorderConfigs.RecordFormat)
switch (RecorderSettings.RecordFormat)
{
case RecodeFormat.Binary:
StoreBinary();
Expand All @@ -139,7 +139,7 @@ private void StoreDmxPacket()

private void StoreBinary()
{
var binaryConfig = RecorderConfigs.BinaryConfig;
var binaryConfig = RecorderSettings.BinarySetting;

if (!Directory.Exists(binaryConfig.Directory))
{
Expand All @@ -157,7 +157,7 @@ private void StoreBinary()

private void StoreAnimationClip()
{
var animationClipConfig = RecorderConfigs.AnimationClipConfig;
var animationClipConfig = RecorderSettings.AnimationClipSetting;
var timelineConverter = new TimelineConverter(_recordedDmx);
timelineConverter.SaveDmxTimelineClips(animationClipConfig.OutputAnimationClipAssetPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,46 @@ public enum RecodeFormat
AnimationClip = 1,
}

public class RecorderConfigs : ScriptableObject
public class RecorderSettings : ScriptableObject
{
[SerializeField] private RecodeFormat _recordFormat;

private string _savePath;

public RecodeFormat RecordFormat => _recordFormat;

public BinaryRecordConfig BinaryConfig { get; } = new();
public AnimationClipRecordConfig AnimationClipConfig { get; } = new();
public BinaryRecordSetting BinarySetting { get; } = new();
public AnimationClipRecordSetting AnimationClipSetting { get; } = new();

public static RecorderConfigs GetOrNewGlobalConfigs()
public static RecorderSettings GetOrNewGlobalSettings()
{
var globalPath = Path.Combine(Application.dataPath, "..", "Library", "ArtNet", "DmxRecorderConfigs.asset");
var globalPath = Path.Combine(Application.dataPath, "..", "Library", "ArtNet", "DmxRecorderSettings.asset");
return Load(globalPath);
}

private static RecorderConfigs Load(string path)
private static RecorderSettings Load(string path)
{
RecorderConfigs configs;
RecorderSettings settings;
try
{
var objs = InternalEditorUtility.LoadSerializedFileAndForget(path);
configs = objs.FirstOrDefault(o => o is RecorderConfigs) as RecorderConfigs;
settings = objs.FirstOrDefault(o => o is RecorderSettings) as RecorderSettings;
}
catch (Exception e)
{
Debug.LogError($"Failed to load RecorderConfigs: {e.Message}");
configs = null;
Debug.LogError($"Failed to load RecorderSettings: {e.Message}");
settings = null;
}

if (configs == null)
if (settings == null)
{
configs = CreateInstance<RecorderConfigs>();
// configs.hideFlags = HideFlags.HideAndDontSave;
configs.name = "DmxRecorderConfigs";
settings = CreateInstance<RecorderSettings>();
// Settings.hideFlags = HideFlags.HideAndDontSave;
settings.name = "DmxRecorderSettings";
}

configs._savePath = path;
return configs;
settings._savePath = path;
return settings;
}

public void Save()
Expand All @@ -72,7 +72,7 @@ public void Save()
}
catch (Exception e)
{
Debug.LogError($"Failed to save RecorderConfigs: {e.Message}");
Debug.LogError($"Failed to save RecorderSettings: {e.Message}");
}
}

Expand All @@ -86,18 +86,18 @@ public void ChangeRecordFormat(RecodeFormat format)
Save();
}

private IRecordConfig Config => RecordFormat switch
private IRecordSetting Setting => RecordFormat switch
{
RecodeFormat.Binary => BinaryConfig,
RecodeFormat.AnimationClip => AnimationClipConfig,
RecodeFormat.Binary => BinarySetting,
RecodeFormat.AnimationClip => AnimationClipSetting,
_ => throw new System.NotImplementedException()
};

public bool Validate() => ValidateErrors().Count == 0;
public List<string> ValidateErrors() => Config.ValidateErrors();
public List<string> ValidateErrors() => Setting.ValidateErrors();
}

public class BinaryRecordConfig : IRecordConfig
public class BinaryRecordSetting : IRecordSetting
{
private const string Extension = ".dmx";

Expand All @@ -119,7 +119,7 @@ public List<string> ValidateErrors()
private bool ValidateFileName() => !string.IsNullOrEmpty(FileName);
}

public class AnimationClipRecordConfig : IRecordConfig
public class AnimationClipRecordSetting : IRecordSetting
{
public string OutputAnimationClipAssetPath { get; set; } = "Assets/Recording";

Expand All @@ -129,7 +129,7 @@ public List<string> ValidateErrors()
}
}

public interface IRecordConfig
public interface IRecordSetting
{
public List<string> ValidateErrors();
}
Expand Down
38 changes: 19 additions & 19 deletions Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void InitializeControlPanel(VisualElement root)
playButton.Add(stopButtonImage);
playButton.clicked += () =>
{
if (!_recorder.RecorderConfigs.Validate()) return;
if (!_recorder.RecorderSettings.Validate()) return;
if (_recorder.Status == RecordingStatus.None)
{
SetEnabledTextField(false);
Expand Down Expand Up @@ -130,8 +130,8 @@ private void InitializeRecordingConfig(VisualElement root)
// 出力ファイルのフォーマット選択
var outputFormatGroup = root.Q<RadioButtonGroup>("outputFormatGroup");
outputFormatGroup.choices = new[] { "Binary", "AnimationClip" };
outputFormatGroup.value = (int) _recorder.RecorderConfigs.RecordFormat;
ChangeOutputFormat(_recorder.RecorderConfigs.RecordFormat);
outputFormatGroup.value = (int) _recorder.RecorderSettings.RecordFormat;
ChangeOutputFormat(_recorder.RecorderSettings.RecordFormat);

outputFormatGroup.RegisterValueChangedCallback(evt =>
{
Expand All @@ -145,21 +145,21 @@ private void InitializeRecordingConfig(VisualElement root)

// 出力ファイル名の設定
_outputFileNameField = root.Q<TextField>("outputFileNameField");
_outputFileNameField.value = _recorder.RecorderConfigs.BinaryConfig.FileName;
_outputFileNameField.value = _recorder.RecorderSettings.BinarySetting.FileName;
_outputFileNameField.RegisterValueChangedCallback(evt =>
{
var fileName = evt.newValue;
_recorder.RecorderConfigs.BinaryConfig.FileName = fileName;
_recorder.RecorderSettings.BinarySetting.FileName = fileName;
UpdateOutputFilePath();
});

// 出力ディレクトリの設定
_outputDirectoryField = root.Q<TextField>("outputDirectoryField");
_outputDirectoryField.value = _recorder.RecorderConfigs.BinaryConfig.Directory;
_outputDirectoryField.value = _recorder.RecorderSettings.BinarySetting.Directory;
_outputDirectoryField.RegisterValueChangedCallback(evt =>
{
var directory = evt.newValue;
_recorder.RecorderConfigs.BinaryConfig.Directory = directory;
_recorder.RecorderSettings.BinarySetting.Directory = directory;
UpdateOutputFilePath();
});
_selectDirectoryButton = root.Q<Button>("selectFolderButton");
Expand All @@ -172,23 +172,23 @@ private void InitializeRecordingConfig(VisualElement root)
{
var selectedDirectory =
EditorUtility.OpenFolderPanel(title: "Output Folder",
folder: _recorder.RecorderConfigs.BinaryConfig.Directory,
folder: _recorder.RecorderSettings.BinarySetting.Directory,
defaultName: "");

if (string.IsNullOrEmpty(selectedDirectory)) return;

_recorder.RecorderConfigs.BinaryConfig.Directory = selectedDirectory;
_recorder.RecorderSettings.BinarySetting.Directory = selectedDirectory;
_outputDirectoryField.value = selectedDirectory;
UpdateOutputFilePath();
};

// Animation Config
var outputAssetDirectoryField = root.Q<TextField>("outputAssetDirectoryField");
outputAssetDirectoryField.value = _recorder.RecorderConfigs.AnimationClipConfig.OutputAnimationClipAssetPath;
outputAssetDirectoryField.value = _recorder.RecorderSettings.AnimationClipSetting.OutputAnimationClipAssetPath;
outputAssetDirectoryField.RegisterValueChangedCallback(evt =>
{
var directory = evt.newValue;
_recorder.RecorderConfigs.AnimationClipConfig.OutputAnimationClipAssetPath = directory;
_recorder.RecorderSettings.AnimationClipSetting.OutputAnimationClipAssetPath = directory;
});


Expand All @@ -202,7 +202,7 @@ private void InitializeRecordingConfig(VisualElement root)
);
openOutputFolderButton.clicked += () =>
{
Process.Start(_recorder.RecorderConfigs.BinaryConfig.Directory);
Process.Start(_recorder.RecorderSettings.BinarySetting.Directory);
};

_errorMessageArea = root.Q<VisualElement>("errorMessageArea");
Expand All @@ -219,14 +219,14 @@ private void InitializeRecordingConfig(VisualElement root)

private void SaveConfig()
{
if (_recorder.RecorderConfigs != null)
if (_recorder.RecorderSettings != null)
{
_recorder.RecorderConfigs.Save();
_recorder.RecorderSettings.Save();
}

if (_sender.SenderConfigs != null)
if (_sender.SenderSettings != null)
{
_sender.SenderConfigs.Save();
_sender.SenderSettings.Save();
}
}

Expand All @@ -246,20 +246,20 @@ private void ChangeOutputFormat(RecodeFormat format)
throw new ArgumentOutOfRangeException(nameof(format), format, null);
}

_recorder.RecorderConfigs.ChangeRecordFormat(format);
_recorder.RecorderSettings.ChangeRecordFormat(format);
}

private void UpdateOutputFilePath()
{
var path = _recorder.RecorderConfigs.BinaryConfig.OutputPath;
var path = _recorder.RecorderSettings.BinarySetting.OutputPath;
_outputFilePathLabel.text = path;
_outputWarningIcon.style.display = System.IO.File.Exists(path) ? DisplayStyle.Flex : DisplayStyle.None;
UpdateErrorMessage();
}

private void UpdateErrorMessage()
{
var errors = _recorder.RecorderConfigs.ValidateErrors();
var errors = _recorder.RecorderSettings.ValidateErrors();
if (errors.Count > 0)
{
_errorMessageLabel.text = string.Join("\n", errors);
Expand Down
12 changes: 6 additions & 6 deletions Assets/ArtNet/Editor/DmxRecorder/Sender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Sender()

private bool IsRunning => _task is { IsCanceled: false, IsCompleted: false };

public SenderConfigs SenderConfigs { get; set; }
public SenderSettings SenderSettings { get; set; }
private List<(int time, DmxPacket packet)> DmxPackets { get; set; } = new();

public bool IsPlaying { get; private set; }
Expand All @@ -44,7 +44,7 @@ public void Load(string path)
{
if (!File.Exists(path)) return;

SenderConfigs.LoadFilePath = path;
SenderSettings.LoadFilePath = path;
var data = File.ReadAllBytes(path);
DmxPackets = RecordData.Deserialize(data).OrderBy(x => x.time).ToList();
MaxTime = DmxPackets.Max(x => x.time);
Expand Down Expand Up @@ -75,7 +75,7 @@ private void Update(int deltaTime)
var isReset = false;
if (LastTime > MaxTime)
{
if (!SenderConfigs.IsLoop)
if (!SenderSettings.IsLoop)
{
ChangedPlaying?.Invoke(false);
}
Expand All @@ -98,7 +98,7 @@ private void Update(int deltaTime)
private void SendDmx(DmxPacket packet)
{
var universe = packet.Universe;
if (!SenderConfigs.IsRecordSequence)
if (!SenderSettings.IsRecordSequence)
{
var sequence = _sequenceMap.GetValueOrDefault(universe, (byte) 0);
sequence = sequence == byte.MaxValue ? (byte) 0 : (byte) (sequence + 1);
Expand All @@ -111,7 +111,7 @@ private void SendDmx(DmxPacket packet)
}

var data = packet.ToByteArray();
_udpSender.Send(data, SenderConfigs.Ip);
_udpSender.Send(data, SenderSettings.Ip);
}

private void IsPlayingChanged(bool isPlaying)
Expand Down Expand Up @@ -169,7 +169,7 @@ private async Task DmxSendTaskAsync(CancellationToken token)

private int CalcAddTime(int time)
{
var addTime = time * SenderConfigs.Speed;
var addTime = time * SenderSettings.Speed;
var addTimeInt = (int) addTime;
if (addTime - addTimeInt > new Random().NextDouble()) addTimeInt++;

Expand Down
Loading

0 comments on commit 5ac483c

Please sign in to comment.