mirror of
https://github.com/Project-Redacted/Highscores-Server.git
synced 2025-05-23 11:54:52 +00:00
Add example Unity Project
This commit is contained in:
parent
fda7ff28dd
commit
e3acdb9d6b
7122 changed files with 505543 additions and 2 deletions
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
[Serializable]
|
||||
[NotKeyable]
|
||||
class AudioClipProperties : PlayableBehaviour
|
||||
{
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float volume = 1.0f;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d60a406ab64c434e9d731914e11a51e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
[Serializable]
|
||||
class AudioMixerProperties : PlayableBehaviour
|
||||
{
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float volume = 1.0f;
|
||||
|
||||
[Range(-1.0f, 1.0f)]
|
||||
public float stereoPan = 0.0f;
|
||||
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float spatialBlend = 0.0f;
|
||||
|
||||
public override void PrepareFrame(Playable playable, FrameData info)
|
||||
{
|
||||
if (!playable.IsValid() || !playable.IsPlayableOfType<AudioMixerPlayable>())
|
||||
return;
|
||||
|
||||
var inputCount = playable.GetInputCount();
|
||||
|
||||
for (int i = 0; i < inputCount; ++i)
|
||||
{
|
||||
if (playable.GetInputWeight(i) > 0.0f)
|
||||
{
|
||||
var input = playable.GetInput(i);
|
||||
|
||||
if (input.IsValid() && input.IsPlayableOfType<AudioClipPlayable>())
|
||||
{
|
||||
var audioClipPlayable = (AudioClipPlayable)input;
|
||||
var audioClipProperties = input.GetHandle().GetObject<AudioClipProperties>();
|
||||
|
||||
audioClipPlayable.SetVolume(Mathf.Clamp01(volume * audioClipProperties.volume));
|
||||
audioClipPlayable.SetStereoPan(Mathf.Clamp(stereoPan, -1.0f, 1.0f));
|
||||
audioClipPlayable.SetSpatialBlend(Mathf.Clamp01(spatialBlend));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d8c4a920f001ca64680ed6fdb52d1753
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Audio;
|
||||
#if UNITY_EDITOR
|
||||
using System.ComponentModel;
|
||||
#endif
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
/// <summary>
|
||||
/// PlayableAsset wrapper for an AudioClip in Timeline.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
#if UNITY_EDITOR
|
||||
[DisplayName("Audio Clip")]
|
||||
#endif
|
||||
public class AudioPlayableAsset : PlayableAsset, ITimelineClipAsset
|
||||
{
|
||||
[SerializeField] AudioClip m_Clip;
|
||||
#pragma warning disable 649 //Field is never assigned to and will always have its default value
|
||||
[SerializeField] bool m_Loop;
|
||||
[SerializeField, HideInInspector] float m_bufferingTime = 0.1f;
|
||||
[SerializeField] AudioClipProperties m_ClipProperties = new AudioClipProperties();
|
||||
|
||||
// the amount of time to give the clip to load prior to it's start time
|
||||
internal float bufferingTime
|
||||
{
|
||||
get { return m_bufferingTime; }
|
||||
set { m_bufferingTime = value; }
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Playable m_LiveClipPlayable = Playable.Null;
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The audio clip to be played
|
||||
/// </summary>
|
||||
public AudioClip clip
|
||||
{
|
||||
get { return m_Clip; }
|
||||
set { m_Clip = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the audio clip loops.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Use this to loop the audio clip when the duration of the timeline clip exceeds that of the audio clip.
|
||||
/// </remarks>
|
||||
public bool loop
|
||||
{
|
||||
get { return m_Loop; }
|
||||
set { m_Loop = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the duration required to play the audio clip exactly once
|
||||
/// </summary>
|
||||
public override double duration
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Clip == null)
|
||||
return base.duration;
|
||||
|
||||
// use this instead of length to avoid rounding precision errors,
|
||||
return (double)m_Clip.samples / m_Clip.frequency;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a description of the PlayableOutputs that may be created for this asset.
|
||||
/// </summary>
|
||||
public override IEnumerable<PlayableBinding> outputs
|
||||
{
|
||||
get { yield return AudioPlayableBinding.Create(name, this); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the root of a Playable subgraph to play the audio clip.
|
||||
/// </summary>
|
||||
/// <param name="graph">PlayableGraph that will own the playable</param>
|
||||
/// <param name="go">The GameObject that triggered the graph build</param>
|
||||
/// <returns>The root playable of the subgraph</returns>
|
||||
public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
|
||||
{
|
||||
if (m_Clip == null)
|
||||
return Playable.Null;
|
||||
|
||||
var audioClipPlayable = AudioClipPlayable.Create(graph, m_Clip, m_Loop);
|
||||
audioClipPlayable.GetHandle().SetScriptInstance(m_ClipProperties.Clone());
|
||||
|
||||
#if UNITY_EDITOR
|
||||
m_LiveClipPlayable = audioClipPlayable;
|
||||
#endif
|
||||
|
||||
return audioClipPlayable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the capabilities of TimelineClips that contain an AudioPlayableAsset
|
||||
/// </summary>
|
||||
public ClipCaps clipCaps
|
||||
{
|
||||
get
|
||||
{
|
||||
return ClipCaps.ClipIn |
|
||||
ClipCaps.SpeedMultiplier |
|
||||
ClipCaps.Blending |
|
||||
(m_Loop ? ClipCaps.Looping : ClipCaps.None);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal void LiveLink()
|
||||
{
|
||||
if (!m_LiveClipPlayable.IsValid())
|
||||
return;
|
||||
|
||||
var audioMixerProperties = m_LiveClipPlayable.GetHandle().GetObject<AudioClipProperties>();
|
||||
|
||||
if (audioMixerProperties == null)
|
||||
return;
|
||||
|
||||
audioMixerProperties.volume = m_ClipProperties.volume;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f10dd60657c6004587f237a7e90f8e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
/// <summary>
|
||||
/// A Timeline track that can play AudioClips.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[TrackClipType(typeof(AudioPlayableAsset), false)]
|
||||
[TrackBindingType(typeof(AudioSource))]
|
||||
[ExcludeFromPreset]
|
||||
public class AudioTrack : TrackAsset
|
||||
{
|
||||
[SerializeField]
|
||||
AudioMixerProperties m_TrackProperties = new AudioMixerProperties();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Playable m_LiveMixerPlayable = Playable.Null;
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Create an TimelineClip for playing an AudioClip on this track.
|
||||
/// </summary>
|
||||
/// <param name="clip">The audio clip to play</param>
|
||||
/// <returns>A TimelineClip with an AudioPlayableAsset asset.</returns>
|
||||
public TimelineClip CreateClip(AudioClip clip)
|
||||
{
|
||||
if (clip == null)
|
||||
return null;
|
||||
|
||||
var newClip = CreateDefaultClip();
|
||||
|
||||
var audioAsset = newClip.asset as AudioPlayableAsset;
|
||||
if (audioAsset != null)
|
||||
audioAsset.clip = clip;
|
||||
|
||||
newClip.duration = clip.length;
|
||||
newClip.displayName = clip.name;
|
||||
|
||||
return newClip;
|
||||
}
|
||||
|
||||
internal override Playable CompileClips(PlayableGraph graph, GameObject go, IList<TimelineClip> timelineClips, IntervalTree<RuntimeElement> tree)
|
||||
{
|
||||
var clipBlender = AudioMixerPlayable.Create(graph, timelineClips.Count);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone());
|
||||
m_LiveMixerPlayable = clipBlender;
|
||||
#else
|
||||
if (hasCurves)
|
||||
clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone());
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < timelineClips.Count; i++)
|
||||
{
|
||||
var c = timelineClips[i];
|
||||
var asset = c.asset as PlayableAsset;
|
||||
if (asset == null)
|
||||
continue;
|
||||
|
||||
var buffer = 0.1f;
|
||||
var audioAsset = c.asset as AudioPlayableAsset;
|
||||
if (audioAsset != null)
|
||||
buffer = audioAsset.bufferingTime;
|
||||
|
||||
var source = asset.CreatePlayable(graph, go);
|
||||
if (!source.IsValid())
|
||||
continue;
|
||||
|
||||
if (source.IsPlayableOfType<AudioClipPlayable>())
|
||||
{
|
||||
// Enforce initial values on all clips
|
||||
var audioClipPlayable = (AudioClipPlayable)source;
|
||||
var audioClipProperties = audioClipPlayable.GetHandle().GetObject<AudioClipProperties>();
|
||||
|
||||
audioClipPlayable.SetVolume(Mathf.Clamp01(m_TrackProperties.volume * audioClipProperties.volume));
|
||||
audioClipPlayable.SetStereoPan(Mathf.Clamp(m_TrackProperties.stereoPan, -1.0f, 1.0f));
|
||||
audioClipPlayable.SetSpatialBlend(Mathf.Clamp01(m_TrackProperties.spatialBlend));
|
||||
}
|
||||
|
||||
tree.Add(new ScheduleRuntimeClip(c, source, clipBlender, buffer));
|
||||
graph.Connect(source, 0, clipBlender, i);
|
||||
source.SetSpeed(c.timeScale);
|
||||
source.SetDuration(c.extrapolatedDuration);
|
||||
clipBlender.SetInputWeight(source, 1.0f);
|
||||
}
|
||||
|
||||
ConfigureTrackAnimation(tree, go, clipBlender);
|
||||
|
||||
return clipBlender;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<PlayableBinding> outputs
|
||||
{
|
||||
get { yield return AudioPlayableBinding.Create(name, this); }
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal void LiveLink()
|
||||
{
|
||||
if (!m_LiveMixerPlayable.IsValid())
|
||||
return;
|
||||
|
||||
var audioMixerProperties = m_LiveMixerPlayable.GetHandle().GetObject<AudioMixerProperties>();
|
||||
|
||||
if (audioMixerProperties == null)
|
||||
return;
|
||||
|
||||
audioMixerProperties.volume = m_TrackProperties.volume;
|
||||
audioMixerProperties.stereoPan = m_TrackProperties.stereoPan;
|
||||
audioMixerProperties.spatialBlend = m_TrackProperties.spatialBlend;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
m_TrackProperties.volume = Mathf.Clamp01(m_TrackProperties.volume);
|
||||
m_TrackProperties.stereoPan = Mathf.Clamp(m_TrackProperties.stereoPan, -1.0f, 1.0f);
|
||||
m_TrackProperties.spatialBlend = Mathf.Clamp01(m_TrackProperties.spatialBlend);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8b22792c3b570444eb18cb78c2af3a74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue