-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create an editor tool for audio
- Loading branch information
Showing
12 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
Assets/AudioSystem/Scripts/Editor/AudioCueEventChannelSOEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System.Collections; | ||
using Long18.AudioSystem.Data; | ||
using UnityEditor; | ||
using UnityEditor.UIElements; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace Long18Editor.AudioSystem | ||
{ | ||
[CustomEditor(typeof(AudioCueEventChannelSO))] | ||
public class AudioCueEventChannelSOEditor : Editor | ||
{ | ||
private const int FRAMES_TO_WAIT = 360; | ||
|
||
[SerializeField] private VisualTreeAsset _visualTreeAsset; | ||
|
||
private AudioCueEventChannelSO Target => target as AudioCueEventChannelSO; | ||
|
||
private VisualElement _bgmElement; | ||
private VisualElement _sfxElement; | ||
private ObjectField _bgmData; | ||
private ObjectField _sfxData; | ||
private IntegerField _sfxRandomCount; | ||
private Toggle _isPlayRequest; | ||
private Toggle _isSfx; | ||
private Toggle _isAuto; | ||
private Button _playButton; | ||
|
||
private bool _isSfxRequest; | ||
|
||
public override VisualElement CreateInspectorGUI() | ||
{ | ||
var root = new VisualElement(); | ||
|
||
InspectorElement.FillDefaultInspector(root, serializedObject, this); | ||
|
||
_visualTreeAsset.CloneTree(root); | ||
|
||
_bgmElement = root.Q<VisualElement>("bgm-element"); | ||
_sfxElement = root.Q<VisualElement>("sfx-element"); | ||
|
||
_bgmData = root.Q<ObjectField>("bgm-data"); | ||
_sfxData = root.Q<ObjectField>("sfx-data"); | ||
|
||
_sfxRandomCount = root.Q<IntegerField>("sfx-random-value"); | ||
|
||
_isPlayRequest = root.Q<Toggle>("audio-request"); | ||
_isSfx = root.Q<Toggle>("is-sfx"); | ||
_isAuto = root.Q<Toggle>("is-random"); | ||
|
||
_playButton = root.Q<Button>("play-audio-button"); | ||
|
||
_isSfx.RegisterValueChangedCallback(ValidAudioDataInterfaceCallback); | ||
_bgmData.RegisterValueChangedCallback(ValidAudioButtonInterfaceCallback); | ||
_sfxData.RegisterValueChangedCallback(ValidAudioButtonInterfaceCallback); | ||
|
||
_playButton.clicked += PlayAudio; | ||
_playButton.SetEnabled(_bgmData.value != null || _sfxData.value != null); | ||
|
||
return root; | ||
} | ||
|
||
private void ValidAudioButtonInterfaceCallback(ChangeEvent<Object> evt) | ||
{ | ||
bool isValid = evt.newValue != null || _sfxData.value != null; | ||
_playButton.SetEnabled(isValid); | ||
} | ||
|
||
private void ValidAudioDataInterfaceCallback(ChangeEvent<bool> evt) | ||
{ | ||
_isSfxRequest = evt.newValue; | ||
_bgmElement.style.display = _isSfxRequest ? DisplayStyle.None : DisplayStyle.Flex; | ||
_sfxElement.style.display = _isSfxRequest ? DisplayStyle.Flex : DisplayStyle.None; | ||
} | ||
|
||
private void PlayAudio() | ||
{ | ||
AudioCueSO value = _bgmData.value as AudioCueSO; | ||
bool request = _isPlayRequest.value; | ||
|
||
if (_isSfxRequest) value = _sfxData.value as AudioCueSO; | ||
if (!_isAuto.value) | ||
{ | ||
Target.PlayAudio(value, request); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < _sfxRandomCount.value; i++) | ||
{ | ||
int framesToWait = FRAMES_TO_WAIT; | ||
while (framesToWait >= 0) | ||
{ | ||
framesToWait--; | ||
EditorApplication.QueuePlayerLoopUpdate(); | ||
} | ||
|
||
Target.PlayAudio(value, request); | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Assets/AudioSystem/Scripts/Editor/AudioCueEventChannelSOEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Long18.AudioSystem.Data; | ||
using UnityEditor; | ||
using UnityEditor.UIElements; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace Long18Editor.AudioSystem | ||
{ | ||
[CustomEditor(typeof(AudioCueSO), true)] | ||
public class AudioCueSOEditor : Editor | ||
{ | ||
[SerializeField] private VisualTreeAsset _visualTreeAsset; | ||
|
||
private AudioCueSO Target => target as AudioCueSO; | ||
private Button _button; | ||
|
||
public override VisualElement CreateInspectorGUI() | ||
{ | ||
var root = new VisualElement(); | ||
|
||
InspectorElement.FillDefaultInspector(root, serializedObject, this); | ||
|
||
_visualTreeAsset.CloneTree(root); | ||
|
||
_button = root.Q<Button>("play-audio-button"); | ||
_button.SetEnabled(Target.GetClips().Length > 0); | ||
|
||
// TODO: Remove after function implementation | ||
_button.SetEnabled(false); | ||
|
||
_button.clicked += PlayAudio; | ||
|
||
return root; | ||
} | ||
|
||
private void PlayAudio() | ||
{ | ||
// TODO: Play audio with out event channel | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Assets/AudioSystem/Scripts/Editor/AudioCueSOEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
Assets/AudioSystem/Scripts/Editor/Template/AudioCueEventChannelSOEditor.uxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True"> | ||
<ui:VisualElement name="VisualElement" style="margin-top: 0; margin-bottom: 10px;" /> | ||
<ui:Label tabindex="-1" text="Tool Editor" display-tooltip-when-elided="true" style="font-size: 24px; -unity-font-style: bold; -unity-text-align: upper-center;" /> | ||
<ui:Label tabindex="-1" text="Event Audio" display-tooltip-when-elided="true" style="font-size: 12px; -unity-font-style: bold; -unity-text-align: upper-center; margin-top: -3px; margin-bottom: 5px; color: rgb(152, 152, 152);" /> | ||
<ui:Toggle label="Request To Play" tooltip="Check true to play, false to pause" name="audio-request" value="true" /> | ||
<ui:Toggle label="Is SFX" name="is-sfx" value="false" /> | ||
<ui:Foldout text="Data" name="foldout"> | ||
<ui:VisualElement name="bgm-element" style="flex-grow: 1;"> | ||
<uie:ObjectField label="Audio To Play" name="bgm-data" type="Long18.AudioSystem.Data.AudioCueSO, Long18.AudioSystem" /> | ||
</ui:VisualElement> | ||
<ui:VisualElement name="sfx-element" style="flex-grow: 1; display: none;"> | ||
<uie:ObjectField label="Audio To Play" name="sfx-data" type="Long18.AudioSystem.Data.AudioCueSO, Long18.AudioSystem" /> | ||
<ui:IntegerField label="Random Time" value="1" name="sfx-random-value" tooltip="Number of audio want to play" /> | ||
<ui:Toggle label="Loop" name="is-random" /> | ||
</ui:VisualElement> | ||
</ui:Foldout> | ||
<ui:Button text="Play Audio" parse-escape-sequences="true" display-tooltip-when-elided="true" name="play-audio-button" style="align-items: center; justify-content: center; align-self: center;" /> | ||
</ui:UXML> |
3 changes: 3 additions & 0 deletions
3
Assets/AudioSystem/Scripts/Editor/Template/AudioCueEventChannelSOEditor.uxml.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
Assets/AudioSystem/Scripts/Editor/Template/AudioCueSOEditor.uxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True"> | ||
<ui:VisualElement name="VisualElement" style="margin-top: 0; margin-bottom: 10px;" /> | ||
<ui:Label tabindex="-1" text="Tool Editor" display-tooltip-when-elided="true" style="font-size: 24px; -unity-font-style: bold; -unity-text-align: upper-center;" /> | ||
<ui:Label tabindex="-1" text="Audio" display-tooltip-when-elided="true" style="font-size: 12px; -unity-font-style: bold; -unity-text-align: upper-center; margin-top: -3px; margin-bottom: 5px; color: rgb(152, 152, 152);" /> | ||
<ui:Button text="Play Audio" parse-escape-sequences="true" display-tooltip-when-elided="true" name="play-audio-button" style="align-items: center; justify-content: center; align-self: center;" /> | ||
</ui:UXML> |
3 changes: 3 additions & 0 deletions
3
Assets/AudioSystem/Scripts/Editor/Template/AudioCueSOEditor.uxml.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.