Unity-jump-proj

This commit is contained in:
2024-09-09 11:07:16 +03:00
parent 2c29906bbf
commit fd96a5627d
13707 changed files with 866380 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7625d4d2f6ecdff4eaa7485257585f53
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
{
"name": "Timeline.Samples.Video.Editor",
"references": [
"GUID:f06555f75b070af458a003d92f9efb00",
"GUID:02f771204943f4a40949438e873e3eff",
"GUID:1b3591fbe8ae54d40b7e51a41d987b5c"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e42c9be5a2cd22f44bd16a41a92745e5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,33 @@
using UnityEditor;
using UnityEditor.Timeline;
using UnityEngine;
using UnityEngine.Timeline;
namespace Timeline.Samples
{
// Editor used by the TimelineEditor to customize the view of a VideoPlayableAsset
[CustomTimelineEditor(typeof(VideoPlayableAsset))]
public class VideoAssetClipEditor : ClipEditor
{
// Called by the Timeline Editor to draw the background of the timeline clip
// when the clip has a VideoPlayableAsset attached
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
{
VideoPlayableAsset videoAsset = clip.asset as VideoPlayableAsset;
if (videoAsset != null && videoAsset.videoClip != null)
{
// Load the preview or the thumbnail for the video
Texture texturePreview = AssetPreview.GetAssetPreview(videoAsset.videoClip);
if (texturePreview == null)
texturePreview = AssetPreview.GetMiniThumbnail(videoAsset.videoClip);
if (texturePreview != null)
{
Rect rect = region.position;
rect.width = texturePreview.width * rect.height / texturePreview.height;
GUI.DrawTexture(rect, texturePreview, ScaleMode.StretchToFill);
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0581bc7142d0a18408d067aa7ff193b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
{
"name": "Timeline.Samples.Video",
"references": [
"GUID:f06555f75b070af458a003d92f9efb00"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1b3591fbe8ae54d40b7e51a41d987b5c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,131 @@
using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using UnityEngine.Video;
namespace Timeline.Samples
{
// Editor representation of a Clip to play video in Timeline.
[Serializable]
public class VideoPlayableAsset : PlayableAsset, ITimelineClipAsset
{
public enum RenderMode
{
CameraFarPlane,
CameraNearPlane
};
[Tooltip("The video clip to play.")]
public VideoClip videoClip;
[Tooltip("Mutes the audio from the video")]
public bool mute;
[Tooltip("Loops the video.")]
public bool loop = true;
[Tooltip("The amount of time before the video begins to start preloading the video stream.")]
public double preloadTime = 0.3;
[Tooltip("The aspect ratio of the video to playback.")]
public VideoAspectRatio aspectRatio = VideoAspectRatio.FitHorizontally;
[Tooltip("Where the video content will be drawn.")]
public RenderMode renderMode = RenderMode.CameraFarPlane;
[Tooltip("Specifies which camera to render to. If unassigned, the main camera will be used.")]
public ExposedReference<Camera> targetCamera;
[Tooltip("Specifies an optional audio source to output to.")]
public ExposedReference<AudioSource> audioSource;
// These are set by the track prior to CreatePlayable being called and are used by the VideoSchedulePlayableBehaviour
// to schedule preloading of the video clip
public double clipInTime { get; set; }
public double startTime { get; set; }
// Creates the playable that represents the instance that plays this clip.
// Here a hidden VideoPlayer is being created for the PlayableBehaviour to use
// to control playback. The PlayableBehaviour is responsible for deleting the player.
public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
{
Camera camera = targetCamera.Resolve(graph.GetResolver());
if (camera == null)
camera = Camera.main;
// If we are unable to create a player, return a playable with no behaviour attached.
VideoPlayer player = CreateVideoPlayer(camera, audioSource.Resolve(graph.GetResolver()));
if (player == null)
return Playable.Create(graph);
ScriptPlayable<VideoPlayableBehaviour> playable =
ScriptPlayable<VideoPlayableBehaviour>.Create(graph);
VideoPlayableBehaviour playableBehaviour = playable.GetBehaviour();
playableBehaviour.videoPlayer = player;
playableBehaviour.preloadTime = preloadTime;
playableBehaviour.clipInTime = clipInTime;
playableBehaviour.startTime = startTime;
return playable;
}
// The playable assets duration is used to specify the initial or default duration of the clip in Timeline.
public override double duration
{
get
{
if (videoClip == null)
return base.duration;
return videoClip.length;
}
}
// Implementation of ITimelineClipAsset. This specifies the capabilities of this timeline clip inside the editor.
// For video clips, we are using built-in support for clip-in, speed, blending and looping.
public ClipCaps clipCaps
{
get
{
var caps = ClipCaps.Blending | ClipCaps.ClipIn | ClipCaps.SpeedMultiplier;
if (loop)
caps |= ClipCaps.Looping;
return caps;
}
}
VideoPlayer CreateVideoPlayer(Camera camera, AudioSource targetAudioSource)
{
if (videoClip == null)
return null;
GameObject gameObject = new GameObject(videoClip.name) { hideFlags = HideFlags.HideAndDontSave };
VideoPlayer videoPlayer = gameObject.AddComponent<VideoPlayer>();
videoPlayer.playOnAwake = false;
videoPlayer.source = VideoSource.VideoClip;
videoPlayer.clip = videoClip;
videoPlayer.waitForFirstFrame = false;
videoPlayer.skipOnDrop = true;
videoPlayer.targetCamera = camera;
videoPlayer.renderMode = renderMode == RenderMode.CameraFarPlane ? VideoRenderMode.CameraFarPlane : VideoRenderMode.CameraNearPlane;
videoPlayer.aspectRatio = aspectRatio;
videoPlayer.isLooping = loop;
videoPlayer.audioOutputMode = VideoAudioOutputMode.Direct;
if (mute)
{
videoPlayer.audioOutputMode = VideoAudioOutputMode.None;
}
else if (targetAudioSource != null)
{
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
for (ushort i = 0; i < videoPlayer.clip.audioTrackCount; ++i)
videoPlayer.SetTargetAudioSource(i, targetAudioSource);
}
return videoPlayer;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0aa7b417d0746a84c88a777d90047e19
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,121 @@
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Video;
namespace Timeline.Samples
{
// The runtime instance of a video clip player in Timeline.
public sealed class VideoPlayableBehaviour : PlayableBehaviour
{
public VideoPlayer videoPlayer;
public double preloadTime;
public double clipInTime;
public double startTime;
private bool preparing;
// Called by the mixer (VideoSchedulerPlayableBehaviour) when this is nearly active to
// give the video time to load.
public void PrepareVideo()
{
if (videoPlayer == null || videoPlayer.isPrepared || preparing)
return;
videoPlayer.targetCameraAlpha = 0.0f;
videoPlayer.time = clipInTime;
videoPlayer.Prepare();
preparing = true;
}
// Called each frame the clip is active.
//
public override void PrepareFrame(Playable playable, FrameData info)
{
if (videoPlayer == null)
return;
// Pause or Play the video to match whether the graph is being scrubbed or playing
// If we need to hold the last frame, this will treat the last frame as a pause
bool shouldBePlaying = info.evaluationType == FrameData.EvaluationType.Playback;
if (!videoPlayer.isLooping && playable.GetTime() >= videoPlayer.clip.length)
shouldBePlaying = false;
if (shouldBePlaying)
{
// this will use the timeline time to prevent drift
videoPlayer.timeReference = VideoTimeReference.ExternalTime;
if (!videoPlayer.isPlaying)
videoPlayer.Play();
videoPlayer.externalReferenceTime = playable.GetTime() / videoPlayer.playbackSpeed;
}
else
{
videoPlayer.timeReference = VideoTimeReference.Freerun;
if (!videoPlayer.isPaused)
videoPlayer.Pause();
SyncVideoToPlayable(playable);
}
// use the accumulated blend value to set the alpha and the audio volume
videoPlayer.targetCameraAlpha = info.effectiveWeight;
if (videoPlayer.audioOutputMode == VideoAudioOutputMode.Direct)
{
for (ushort i = 0; i < videoPlayer.clip.audioTrackCount; ++i)
videoPlayer.SetDirectAudioVolume(i, info.effectiveWeight);
}
}
// Called when the clip becomes active.
public override void OnBehaviourPlay(Playable playable, FrameData info)
{
if (videoPlayer == null)
return;
SyncVideoToPlayable(playable);
videoPlayer.playbackSpeed = Mathf.Clamp(info.effectiveSpeed, 1 / 10f, 10f);
videoPlayer.Play();
preparing = false;
}
// Called when the clip becomes inactive OR the timeline is 'paused'
public override void OnBehaviourPause(Playable playable, FrameData info)
{
if (videoPlayer == null)
return;
preparing = false;
// The effective weight will be greater than 0 if the graph is paused and the playhead is still on this clip.
if (info.effectiveWeight <= 0)
videoPlayer.Stop();
else
videoPlayer.Pause();
}
// Called when the playable is destroyed.
public override void OnPlayableDestroy(Playable playable)
{
if (videoPlayer != null)
{
videoPlayer.Stop();
if (Application.isPlaying)
Object.Destroy(videoPlayer.gameObject);
else
Object.DestroyImmediate(videoPlayer.gameObject);
}
}
// Syncs the video player time to playable time
private void SyncVideoToPlayable(Playable playable)
{
if (videoPlayer == null || videoPlayer.clip == null)
return;
if (videoPlayer.isLooping)
videoPlayer.time = playable.GetTime() % videoPlayer.clip.length;
else
videoPlayer.time = System.Math.Min(playable.GetTime(), videoPlayer.clip.length);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 177ac68ca0c735544b1616ab4fdbbb3e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using System;
using UnityEngine;
using UnityEngine.Playables;
namespace Timeline.Samples
{
// The runtime instance of the VideoTrack. It is responsible for letting the VideoPlayableBehaviours
// they need to start loading the video
public sealed class VideoSchedulerPlayableBehaviour : PlayableBehaviour
{
// Called every frame that the timeline is evaluated. This is called prior to
// PrepareFrame on any of its input playables.
public override void PrepareFrame(Playable playable, FrameData info)
{
// Searches for clips that are in the 'preload' area and prepares them for playback
var timelineTime = playable.GetGraph().GetRootPlayable(0).GetTime();
for (int i = 0; i < playable.GetInputCount(); i++)
{
if (playable.GetInput(i).GetPlayableType() != typeof(VideoPlayableBehaviour))
continue;
if (playable.GetInputWeight(i) <= 0.0f)
{
ScriptPlayable<VideoPlayableBehaviour> scriptPlayable = (ScriptPlayable<VideoPlayableBehaviour>)playable.GetInput(i);
VideoPlayableBehaviour videoPlayableBehaviour = scriptPlayable.GetBehaviour();
double preloadTime = Math.Max(0.0, videoPlayableBehaviour.preloadTime);
double clipStart = videoPlayableBehaviour.startTime;
if (timelineTime > clipStart - preloadTime && timelineTime <= clipStart)
videoPlayableBehaviour.PrepareVideo();
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 951c577cc5477dd4ba24b29b8ecdc8dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,39 @@
using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
namespace Timeline.Samples
{
// Timeline track to play videos.
// This sample demonstrates the following
// * Using built in blending, speed and clip-in capabilities in custom clips.
// * Using ClipEditors to customize clip drawing.
// * Using a mixer PlayableBehaviour to perform look-ahead operations.
// * Managing UnityEngine.Object lifetime (VideoPlayer) with a PlayableBehaviour.
// * Using ExposedReferences to reference Components in the scene from a PlayableAsset.
[Serializable]
[TrackClipType(typeof(VideoPlayableAsset))]
[TrackColor(0.008f, 0.698f, 0.655f)]
public class VideoTrack : TrackAsset
{
// Called to create a PlayableBehaviour instance to represent the instance of the track, commonly referred
// to as a Mixer playable.
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
{
// This is called immediately before CreatePlayable on VideoPlayableAsset.
// Each playable asset needs to be updated to the last clip values.
foreach (var clip in GetClips())
{
var asset = clip.asset as VideoPlayableAsset;
if (asset != null)
{
asset.clipInTime = clip.clipIn;
asset.startTime = clip.start;
}
}
return ScriptPlayable<VideoSchedulerPlayableBehaviour>.Create(graph, inputCount);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1f59f3cc5e7d1e74299689783b0fe149
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: