Unity-jump-proj
This commit is contained in:
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Timeline;
|
||||
#if !UNITY_2020_2_OR_NEWER
|
||||
using L10n = UnityEditor.Timeline.L10n;
|
||||
#endif
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(AudioClipProperties))]
|
||||
class AudioClipPropertiesDrawer : PropertyDrawer
|
||||
{
|
||||
[UsedImplicitly] // Also used by tests
|
||||
internal static class Styles
|
||||
{
|
||||
public const string VolumeControl = "AudioClipPropertiesDrawer.volume";
|
||||
|
||||
const string k_Indent = " ";
|
||||
public const string valuesFormatter = "0.###";
|
||||
public static string mixedPropertiesInfo = L10n.Tr("The final {3} is {0}\n") +
|
||||
L10n.Tr("Calculated from:\n") +
|
||||
k_Indent + L10n.Tr("Clip: {1}\n") +
|
||||
k_Indent + L10n.Tr("Track: {2}");
|
||||
|
||||
public static string audioSourceContribution = k_Indent + L10n.Tr("AudioSource: {0}");
|
||||
}
|
||||
|
||||
static StringBuilder s_MixInfoBuilder = new StringBuilder();
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var volumeProp = property.FindPropertyRelative("volume");
|
||||
|
||||
GUI.SetNextControlName(Styles.VolumeControl);
|
||||
EditorGUI.Slider(position, volumeProp, 0.0f, 1.0f, AudioSourceInspector.Styles.volumeLabel);
|
||||
|
||||
if (TimelineEditor.inspectedDirector == null)
|
||||
// Nothing more to do in asset mode
|
||||
return;
|
||||
|
||||
var clip = SelectionManager.SelectedClips().FirstOrDefault(c => c.asset == property.serializedObject.targetObject);
|
||||
|
||||
if (clip == null || clip.GetParentTrack() == null)
|
||||
return;
|
||||
|
||||
var clipVolume = volumeProp.floatValue;
|
||||
var trackVolume = new SerializedObject(clip.GetParentTrack()).FindProperty("m_TrackProperties.volume").floatValue;
|
||||
var binding = TimelineEditor.inspectedDirector.GetGenericBinding(clip.GetParentTrack()) as AudioSource;
|
||||
|
||||
if (Math.Abs(clipVolume) < float.Epsilon &&
|
||||
Math.Abs(trackVolume) < float.Epsilon &&
|
||||
(binding == null || Math.Abs(binding.volume) < float.Epsilon))
|
||||
return;
|
||||
|
||||
if (Math.Abs(clipVolume - 1) < float.Epsilon &&
|
||||
Math.Abs(trackVolume - 1) < float.Epsilon &&
|
||||
(binding == null || Math.Abs(binding.volume - 1) < float.Epsilon))
|
||||
return;
|
||||
|
||||
s_MixInfoBuilder.Length = 0;
|
||||
|
||||
var audioSourceVolume = binding == null ? 1.0f : binding.volume;
|
||||
|
||||
s_MixInfoBuilder.AppendFormat(
|
||||
Styles.mixedPropertiesInfo,
|
||||
(clipVolume * trackVolume * audioSourceVolume).ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
clipVolume.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
trackVolume.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
AudioSourceInspector.Styles.volumeLabel.text);
|
||||
|
||||
if (binding != null)
|
||||
s_MixInfoBuilder.Append("\n")
|
||||
.AppendFormat(Styles.audioSourceContribution,
|
||||
audioSourceVolume.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture));
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.HelpBox(new GUIContent(s_MixInfoBuilder.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b6cac4a98010394791c66942a33caf4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,104 @@
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace UnityEditor.Timeline
|
||||
{
|
||||
[CustomTimelineEditor(typeof(AudioPlayableAsset)), UsedImplicitly]
|
||||
class AudioPlayableAssetEditor : ClipEditor
|
||||
{
|
||||
readonly string k_NoClipAssignedError = L10n.Tr("No audio clip assigned");
|
||||
readonly Dictionary<TimelineClip, WaveformPreview> m_PersistentPreviews = new Dictionary<TimelineClip, WaveformPreview>();
|
||||
ColorSpace m_ColorSpace = ColorSpace.Uninitialized;
|
||||
|
||||
public override ClipDrawOptions GetClipOptions(TimelineClip clip)
|
||||
{
|
||||
var clipOptions = base.GetClipOptions(clip);
|
||||
var audioAsset = clip.asset as AudioPlayableAsset;
|
||||
if (audioAsset != null && audioAsset.clip == null)
|
||||
clipOptions.errorText = k_NoClipAssignedError;
|
||||
return clipOptions;
|
||||
}
|
||||
|
||||
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
|
||||
{
|
||||
if (!TimelineWindow.instance.state.showAudioWaveform)
|
||||
return;
|
||||
|
||||
var rect = region.position;
|
||||
if (rect.width <= 0)
|
||||
return;
|
||||
|
||||
var audioClip = clip.asset as AudioClip;
|
||||
if (audioClip == null)
|
||||
{
|
||||
var audioPlayableAsset = clip.asset as AudioPlayableAsset;
|
||||
if (audioPlayableAsset != null)
|
||||
audioClip = audioPlayableAsset.clip;
|
||||
}
|
||||
|
||||
if (audioClip == null)
|
||||
return;
|
||||
|
||||
var quantizedRect = new Rect(Mathf.Ceil(rect.x), Mathf.Ceil(rect.y), Mathf.Ceil(rect.width), Mathf.Ceil(rect.height));
|
||||
|
||||
WaveformPreview preview = GetOrCreateWaveformPreview(clip, audioClip, quantizedRect, region.startTime, region.endTime);
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
DrawWaveformPreview(preview, quantizedRect);
|
||||
}
|
||||
|
||||
public WaveformPreview GetOrCreateWaveformPreview(TimelineClip clip, AudioClip audioClip, Rect rect, double startTime, double endTime)
|
||||
{
|
||||
if (QualitySettings.activeColorSpace != m_ColorSpace)
|
||||
{
|
||||
m_ColorSpace = QualitySettings.activeColorSpace;
|
||||
m_PersistentPreviews.Clear();
|
||||
}
|
||||
|
||||
bool previewExists = m_PersistentPreviews.TryGetValue(clip, out WaveformPreview preview);
|
||||
bool audioClipHasChanged = preview != null && audioClip != preview.presentedObject;
|
||||
if (!previewExists || audioClipHasChanged)
|
||||
{
|
||||
if (AssetDatabase.Contains(audioClip))
|
||||
preview = CreateWaveformPreview(audioClip, rect);
|
||||
m_PersistentPreviews[clip] = preview;
|
||||
}
|
||||
|
||||
if (preview == null)
|
||||
return null;
|
||||
|
||||
preview.looping = clip.SupportsLooping();
|
||||
preview.SetTimeInfo(startTime, endTime - startTime);
|
||||
preview.OptimizeForSize(rect.size);
|
||||
return preview;
|
||||
}
|
||||
|
||||
public static void DrawWaveformPreview(WaveformPreview preview, Rect rect)
|
||||
{
|
||||
if (preview != null)
|
||||
{
|
||||
preview.ApplyModifications();
|
||||
preview.Render(rect);
|
||||
}
|
||||
}
|
||||
|
||||
static WaveformPreview CreateWaveformPreview(AudioClip audioClip, Rect quantizedRect)
|
||||
{
|
||||
WaveformPreview preview = WaveformPreviewFactory.Create((int)quantizedRect.width, audioClip);
|
||||
Color waveColour = GammaCorrect(DirectorStyles.Instance.customSkin.colorAudioWaveform);
|
||||
Color transparent = waveColour;
|
||||
transparent.a = 0;
|
||||
preview.backgroundColor = transparent;
|
||||
preview.waveColor = waveColour;
|
||||
preview.SetChannelMode(WaveformPreview.ChannelMode.MonoSum);
|
||||
preview.updated += () => TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
|
||||
return preview;
|
||||
}
|
||||
|
||||
static Color GammaCorrect(Color color)
|
||||
{
|
||||
return (QualitySettings.activeColorSpace == ColorSpace.Linear) ? color.gamma : color;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74374298effb78d47b85450f7f724cef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,27 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Timeline;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
[CustomEditor(typeof(AudioPlayableAsset))]
|
||||
class AudioPlayableAssetInspector : BasicAssetInspector
|
||||
{
|
||||
public override void OnPlayableAssetChangedInInspector()
|
||||
{
|
||||
// At this point, we are guaranteed that the Timeline window is focused on
|
||||
// the correct asset and that a single clip is selected (see ClipInspector)
|
||||
|
||||
if (TimelineEditor.inspectedDirector == null)
|
||||
// Do nothing if in asset mode
|
||||
return;
|
||||
|
||||
var asset = (AudioPlayableAsset)target;
|
||||
|
||||
if (TimelineEditor.inspectedDirector.state == PlayState.Playing)
|
||||
asset.LiveLink();
|
||||
else
|
||||
TimelineEditor.Refresh(RefreshReason.ContentsModified);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23884ce4c1de32846adafea2d53a4cee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Timeline;
|
||||
using UnityEngine.Playables;
|
||||
#if !UNITY_2020_2_OR_NEWER
|
||||
using L10n = UnityEditor.Timeline.L10n;
|
||||
#endif
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
[CustomEditor(typeof(AudioTrack))]
|
||||
[CanEditMultipleObjects]
|
||||
class AudioTrackInspector : TrackAssetInspector
|
||||
{
|
||||
[UsedImplicitly] // Also used by tests
|
||||
internal static class Styles
|
||||
{
|
||||
public const string VolumeControl = "AudioTrackInspector.volume";
|
||||
public const string StereoPanControl = "AudioTrackInspector.stereoPan";
|
||||
public const string SpatialBlendControl = "AudioTrackInspector.spatialBlend";
|
||||
|
||||
const string k_Indent = " ";
|
||||
public const string valuesFormatter = "0.###";
|
||||
public const string mixInfoSectionSeparator = "\n\n";
|
||||
public static string mixedPropertiesInfo = L10n.Tr("The final {3} is {0}\n") +
|
||||
L10n.Tr("Calculated from:\n") +
|
||||
k_Indent + L10n.Tr("Track: {1}\n") +
|
||||
k_Indent + L10n.Tr("AudioSource: {2}");
|
||||
}
|
||||
|
||||
static StringBuilder s_MixInfoBuilder = new StringBuilder();
|
||||
|
||||
SerializedProperty m_VolumeProperty;
|
||||
SerializedProperty m_StereoPanProperty;
|
||||
SerializedProperty m_SpatialBlendProperty;
|
||||
PlayableDirector m_Director;
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
if (((AudioTrack)target).timelineAsset == TimelineEditor.inspectedAsset)
|
||||
m_Director = TimelineEditor.inspectedDirector;
|
||||
|
||||
m_VolumeProperty = serializedObject.FindProperty("m_TrackProperties.volume");
|
||||
m_StereoPanProperty = serializedObject.FindProperty("m_TrackProperties.stereoPan");
|
||||
m_SpatialBlendProperty = serializedObject.FindProperty("m_TrackProperties.spatialBlend");
|
||||
}
|
||||
|
||||
protected override void DrawTrackProperties()
|
||||
{
|
||||
// Volume
|
||||
GUI.SetNextControlName(Styles.VolumeControl);
|
||||
EditorGUILayout.Slider(m_VolumeProperty, 0.0f, 1.0f, AudioSourceInspector.Styles.volumeLabel);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
// Stereo Pan
|
||||
GUI.SetNextControlName(Styles.StereoPanControl);
|
||||
EditorGUIUtility.sliderLabels.SetLabels(AudioSourceInspector.Styles.panLeftLabel, AudioSourceInspector.Styles.panRightLabel);
|
||||
EditorGUILayout.Slider(m_StereoPanProperty, -1.0f, 1.0f, AudioSourceInspector.Styles.panStereoLabel);
|
||||
EditorGUIUtility.sliderLabels.SetLabels(null, null);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
// Spatial Blend
|
||||
using (new EditorGUI.DisabledScope(ShouldDisableSpatialBlend()))
|
||||
{
|
||||
GUI.SetNextControlName(Styles.SpatialBlendControl);
|
||||
EditorGUIUtility.sliderLabels.SetLabels(AudioSourceInspector.Styles.spatialLeftLabel, AudioSourceInspector.Styles.spatialRightLabel);
|
||||
EditorGUILayout.Slider(m_SpatialBlendProperty, 0.0f, 1.0f, AudioSourceInspector.Styles.spatialBlendLabel);
|
||||
EditorGUIUtility.sliderLabels.SetLabels(null, null);
|
||||
}
|
||||
|
||||
DrawMixInfoSection();
|
||||
}
|
||||
|
||||
void DrawMixInfoSection()
|
||||
{
|
||||
if (m_Director == null || targets.Length > 1)
|
||||
return;
|
||||
|
||||
var binding = m_Director.GetGenericBinding(target) as AudioSource;
|
||||
if (binding == null)
|
||||
return;
|
||||
|
||||
var audioSourceVolume = binding.volume;
|
||||
var audioSourcePan = binding.panStereo;
|
||||
var audioSourceBlend = binding.spatialBlend;
|
||||
|
||||
var trackVolume = m_VolumeProperty.floatValue;
|
||||
var trackPan = m_StereoPanProperty.floatValue;
|
||||
var trackBlend = m_SpatialBlendProperty.floatValue;
|
||||
|
||||
// Skip sections when result is obvious
|
||||
|
||||
var skipVolumeInfo = Math.Abs(audioSourceVolume) < float.Epsilon && Math.Abs(trackVolume) < float.Epsilon || // All muted
|
||||
Math.Abs(audioSourceVolume - 1) < float.Epsilon && Math.Abs(trackVolume - 1) < float.Epsilon; // All max volume
|
||||
|
||||
var skipPanInfo = Math.Abs(audioSourcePan) < float.Epsilon && Math.Abs(trackPan) < float.Epsilon || // All centered
|
||||
Math.Abs(audioSourcePan - 1) < float.Epsilon && Math.Abs(trackPan - 1) < float.Epsilon || // All right
|
||||
Math.Abs(audioSourcePan - (-1.0f)) < float.Epsilon && Math.Abs(trackPan - (-1.0f)) < float.Epsilon; // All left
|
||||
|
||||
var skipBlendInfo = Math.Abs(audioSourceBlend) < float.Epsilon && Math.Abs(trackBlend) < float.Epsilon || // All 2D
|
||||
Math.Abs(audioSourceBlend - 1) < float.Epsilon && Math.Abs(trackBlend - 1) < float.Epsilon; // All 3D
|
||||
|
||||
if (skipVolumeInfo && skipPanInfo && skipBlendInfo)
|
||||
return;
|
||||
|
||||
s_MixInfoBuilder.Length = 0;
|
||||
|
||||
if (!skipVolumeInfo)
|
||||
s_MixInfoBuilder.AppendFormat(
|
||||
Styles.mixedPropertiesInfo,
|
||||
(audioSourceVolume * trackVolume).ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
trackVolume.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
audioSourceVolume.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
AudioSourceInspector.Styles.volumeLabel.text);
|
||||
|
||||
if (!skipVolumeInfo && !skipPanInfo)
|
||||
s_MixInfoBuilder.Append(Styles.mixInfoSectionSeparator);
|
||||
|
||||
if (!skipPanInfo)
|
||||
s_MixInfoBuilder.AppendFormat(
|
||||
Styles.mixedPropertiesInfo,
|
||||
Mathf.Clamp(audioSourcePan + trackPan, -1.0f, 1.0f).ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
trackPan.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
audioSourcePan.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
AudioSourceInspector.Styles.panStereoLabel.text);
|
||||
|
||||
if ((!skipVolumeInfo || !skipPanInfo) && !skipBlendInfo)
|
||||
s_MixInfoBuilder.Append(Styles.mixInfoSectionSeparator);
|
||||
|
||||
if (!skipBlendInfo)
|
||||
s_MixInfoBuilder.AppendFormat(
|
||||
Styles.mixedPropertiesInfo,
|
||||
Mathf.Clamp01(audioSourceBlend + trackBlend).ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
trackBlend.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
audioSourceBlend.ToString(Styles.valuesFormatter, CultureInfo.InvariantCulture),
|
||||
AudioSourceInspector.Styles.spatialBlendLabel.text);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.HelpBox(new GUIContent(s_MixInfoBuilder.ToString()));
|
||||
}
|
||||
|
||||
protected override void ApplyChanges()
|
||||
{
|
||||
var track = (AudioTrack)target;
|
||||
|
||||
if (TimelineEditor.inspectedAsset != track.timelineAsset || TimelineEditor.inspectedDirector == null)
|
||||
return;
|
||||
|
||||
if (TimelineEditor.inspectedDirector.state == PlayState.Playing)
|
||||
track.LiveLink();
|
||||
else
|
||||
TimelineEditor.Refresh(RefreshReason.ContentsModified);
|
||||
}
|
||||
|
||||
bool ShouldDisableSpatialBlend()
|
||||
{
|
||||
return m_Director == null ||
|
||||
targets.Any(selectedTrack => m_Director.GetGenericBinding(selectedTrack) == null);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57acdaad593b8d143b8fb5052a09d7d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user