Skip to content

Commit

Permalink
Add a second 360 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Apr 13, 2024
1 parent eb2ec3f commit b39ca9c
Show file tree
Hide file tree
Showing 52 changed files with 1,700 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using YoutubePlayer.Components;
using YoutubePlayer.Extensions;

namespace YoutubePlayer.Samples
namespace YoutubePlayer.Samples.PlayVideo
{
public class DownloadVideoButton : MonoBehaviour
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using UnityEngine.UI;
using UnityEngine.Video;

namespace YoutubePlayer.Samples
namespace YoutubePlayer.Samples.PlayVideo
{
[RequireComponent(typeof(Button))]
public class PlayVideoButton : MonoBehaviour
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using UnityEngine;
using YoutubePlayer.Components;

namespace YoutubePlayer.Samples
namespace YoutubePlayer.Samples.PlayVideo
{
public class PrepareVideoButton : MonoBehaviour
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEngine.UI;
using UnityEngine.Video;

namespace YoutubePlayer.Samples
namespace YoutubePlayer.Samples.PlayVideo
{
/// <summary>
/// A progress bar for VideoPlayer
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using UnityEngine;
using UnityEngine.Video;

namespace YoutubePlayer.Samples.Three60EquiRectangular
{
[RequireComponent(typeof(VideoPlayer))]
public class PanoramicSkyboxVideo : MonoBehaviour
{
public Material skyboxMaterial;

public string videoTextureName;

VideoPlayer m_VideoPlayer;
void Awake()
{
m_VideoPlayer = GetComponent<VideoPlayer>();
m_VideoPlayer.prepareCompleted += VideoPlayerOnPrepareCompleted;
}

void VideoPlayerOnPrepareCompleted(VideoPlayer source)
{
if (skyboxMaterial.HasProperty(videoTextureName))
{
skyboxMaterial.SetTexture(videoTextureName, m_VideoPlayer.texture);
}
else
{
skyboxMaterial.mainTexture = m_VideoPlayer.texture;
}
}

void OnDestroy()
{
m_VideoPlayer.prepareCompleted -= VideoPlayerOnPrepareCompleted;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using UnityEngine;

namespace YoutubePlayer.Samples.Three60EquiRectangular
{
public class SimpleCameraController : MonoBehaviour
{
class CameraState
{
public float yaw;
public float pitch;
public float roll;
public float x;
public float y;
public float z;

public void SetFromTransform(Transform t)
{
pitch = t.eulerAngles.x;
yaw = t.eulerAngles.y;
roll = t.eulerAngles.z;
x = t.position.x;
y = t.position.y;
z = t.position.z;
}

public void Translate(Vector3 translation)
{
Vector3 rotatedTranslation = Quaternion.Euler(pitch, yaw, roll) * translation;

x += rotatedTranslation.x;
y += rotatedTranslation.y;
z += rotatedTranslation.z;
}

public void LerpTowards(CameraState target, float positionLerpPct, float rotationLerpPct)
{
yaw = Mathf.Lerp(yaw, target.yaw, rotationLerpPct);
pitch = Mathf.Lerp(pitch, target.pitch, rotationLerpPct);
roll = Mathf.Lerp(roll, target.roll, rotationLerpPct);

x = Mathf.Lerp(x, target.x, positionLerpPct);
y = Mathf.Lerp(y, target.y, positionLerpPct);
z = Mathf.Lerp(z, target.z, positionLerpPct);
}

public void UpdateTransform(Transform t)
{
t.eulerAngles = new Vector3(pitch, yaw, roll);
t.position = new Vector3(x, y, z);
}
}

CameraState m_TargetCameraState = new CameraState();
CameraState m_InterpolatingCameraState = new CameraState();

[Header("Movement Settings")]
[Tooltip("Exponential boost factor on translation, controllable by mouse wheel.")]
public float boost = 3.5f;

[Tooltip("Time it takes to interpolate camera position 99% of the way to the target."), Range(0.001f, 1f)]
public float positionLerpTime = 0.2f;

[Header("Rotation Settings")]
[Tooltip("X = Change in mouse position.\nY = Multiplicative factor for camera rotation.")]
public AnimationCurve mouseSensitivityCurve = new AnimationCurve(new Keyframe(0f, 0.5f, 0f, 5f), new Keyframe(1f, 2.5f, 0f, 0f));

[Tooltip("Time it takes to interpolate camera rotation 99% of the way to the target."), Range(0.001f, 1f)]
public float rotationLerpTime = 0.01f;

[Tooltip("Whether or not to invert our Y axis for mouse input to rotation.")]
public bool invertY = false;

void OnEnable()
{
m_TargetCameraState.SetFromTransform(transform);
m_InterpolatingCameraState.SetFromTransform(transform);
}

Vector3 GetInputTranslationDirection()
{
Vector3 direction = new Vector3();
if (Input.GetKey(KeyCode.W))
{
direction += Vector3.forward;
}
if (Input.GetKey(KeyCode.S))
{
direction += Vector3.back;
}
if (Input.GetKey(KeyCode.A))
{
direction += Vector3.left;
}
if (Input.GetKey(KeyCode.D))
{
direction += Vector3.right;
}
if (Input.GetKey(KeyCode.Q))
{
direction += Vector3.down;
}
if (Input.GetKey(KeyCode.E))
{
direction += Vector3.up;
}
return direction;
}

void Update()
{
// Exit Sample
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
}

// Hide and lock cursor when right mouse button pressed
if (Input.GetMouseButtonDown(1))
{
Cursor.lockState = CursorLockMode.Locked;
}

// Unlock and show cursor when right mouse button released
if (Input.GetMouseButtonUp(1))
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}

// Rotation
if (Input.GetMouseButton(1))
{
var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1));

var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude);

m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor;
m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor;
}

// Translation
var translation = GetInputTranslationDirection() * Time.deltaTime;

// Speed up movement when shift key held
if (Input.GetKey(KeyCode.LeftShift))
{
translation *= 10.0f;
}

// Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel)
boost += Input.mouseScrollDelta.y * 0.2f;
translation *= Mathf.Pow(2.0f, boost);

m_TargetCameraState.Translate(translation);

// Framerate-independent interpolation
// Calculate the lerp amount, such that we get 99% of the way to our target in the specified time
var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime);
var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime);
m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct);

m_InterpolatingCameraState.UpdateTransform(transform);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Skybox360
m_Shader: {fileID: 108, guid: 0000000000000000f000000000000000, type: 0}
m_ValidKeywords: []
m_InvalidKeywords:
- _MAPPING_LATITUDE_LONGITUDE_LAYOUT
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _Exposure: 1
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _ImageType: 0
- _Layout: 0
- _Mapping: 1
- _Metallic: 0
- _MirrorOnBack: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Rotation: 0
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Tint: {r: 0.5, g: 0.5, b: 0.5, a: 0.5}
m_BuildTextureStacks: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b39ca9c

Please sign in to comment.