Création des video et bike managers

This commit is contained in:
Florent Guiotte 2018-03-05 20:54:00 +01:00
parent 7ee6e8aa36
commit 8d556377b2
7 changed files with 383 additions and 3 deletions

View File

@ -194,3 +194,210 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1036252277
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1036252279}
- component: {fileID: 1036252278}
- component: {fileID: 1036252280}
- component: {fileID: 1036252281}
m_Layer: 0
m_Name: Square
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!212 &1036252278
SpriteRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1036252277}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 5409794c08b164f178fedef6756b97d3, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
--- !u!4 &1036252279
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1036252277}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 8.888889, y: 0, z: 0}
m_LocalScale: {x: 17.777779, y: 10, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1036252280
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1036252277}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4cdc0f9b9c7604ab9a5d4ac68eb8277f, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1036252281
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1036252277}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 13a913077695c4ddc883aee3cab314fd, type: 3}
m_Name:
m_EditorClassIdentifier:
playerID: 0
distanceToRun: 100
wheelDiameter: 0.559
ticPerTurn: 4
speedIntegrationTime: 1
--- !u!1 &2032723387
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 2032723390}
- component: {fileID: 2032723389}
- component: {fileID: 2032723388}
m_Layer: 0
m_Name: Square (2)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!328 &2032723388
VideoPlayer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2032723387}
m_Enabled: 1
m_VideoClip: {fileID: 0}
m_TargetCameraAlpha: 1
m_TargetCamera3DLayout: 0
m_TargetCamera: {fileID: 0}
m_TargetTexture: {fileID: 0}
m_TimeReference: 0
m_TargetMaterialRenderer: {fileID: 0}
m_TargetMaterialProperty: _MainTex
m_RenderMode: 3
m_AspectRatio: 2
m_DataSource: 0
m_PlaybackSpeed: 1
m_AudioOutputMode: 1
m_TargetAudioSources: []
m_DirectAudioVolumes: []
m_Url:
m_EnabledAudioTracks:
m_DirectAudioMutes:
m_ControlledAudioTrackCount: 0
m_PlayOnAwake: 1
m_SkipOnDrop: 1
m_Looping: 0
m_WaitForFirstFrame: 1
m_FrameReadyEventEnabled: 0
--- !u!212 &2032723389
SpriteRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2032723387}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 5409794c08b164f178fedef6756b97d3, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
--- !u!4 &2032723390
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2032723387}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -4.444445, y: 0, z: 0}
m_LocalScale: {x: 8.888889, y: 10, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 018ff6a89c6ef4b8dbe38a28037d0ae0
folderAsset: yes
timeCreated: 1520258441
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,85 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BikeManager : MonoBehaviour {
[SerializeField]
public int playerID; // {get; set; }
// metric system ftw
[SerializeField]
private float distanceToRun = 100f; // {get; set; }
[SerializeField]
private float wheelDiameter = .559f; // {get; set; }
[SerializeField]
private int ticPerTurn = 4;
[SerializeField]
private float speedIntegrationTime = .5f;
private string inputID;
private float distancePerTick;
private float distanceRun;
private float Speed {get; set; }
private Queue<float> impulses = new Queue<float>();
// Use this for initialization
void Start () {
// TODO: Refactor w a player manager ?
switch (playerID) {
case 0:
inputID = "WheelP1";
break;
case 1:
inputID = "WheelP2";
break;
}
distancePerTick = wheelDiameter * Mathf.PI / ticPerTurn;
Debug.Log("Distance to run:" + distanceToRun);
Debug.Log("Distance per tick:" + distancePerTick);
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown(inputID)) {
WheelTic();
}
Speed = getBikeSpeed(speedIntegrationTime);
Debug.Log(Speed);
}
int getBikeImpulses(float timeWindow = .5f) {
if (impulses.Count == 0) {
return 0;
}
float time = Time.time;
float delta = time - impulses.Peek();
while (delta > timeWindow) {
impulses.Dequeue();
if (impulses.Count == 0) {
break;
}
delta = time - impulses.Peek();
}
return impulses.Count;
}
float getBikeSpeed(float timeWindow = .5f) {
int imp = getBikeImpulses(timeWindow);
return imp * distancePerTick / timeWindow;
}
void WheelTic() {
impulses.Enqueue(Time.time);
distanceRun += distancePerTick;
//Debug.Log(GetProgress());
}
float GetProgress() {
return distanceRun / distanceToRun;
}
}

View File

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 13a913077695c4ddc883aee3cab314fd
timeCreated: 1520266495
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class VideoManager : MonoBehaviour {
private VideoPlayer videoPlayer;
private float speed {get; set; }
void Start () {
speed = 1.0f;
videoPlayer = gameObject.AddComponent<VideoPlayer>();
// TODO: Aspect Ratio is not working?
videoPlayer.aspectRatio = VideoAspectRatio.FitOutside;
Debug.Log(videoPlayer.aspectRatio);
videoPlayer.url = "/home/florent/Stockage/Works/Unity/GoldSprint/Videos/redbull/redbull_30s.webm";
videoPlayer.isLooping = true;
videoPlayer.playOnAwake = false;
videoPlayer.Prepare();
videoPlayer.Pause();
//videoPlayer.Play();
Run();
}
void Update () {
videoPlayer.playbackSpeed = speed;
}
void Run() {
videoPlayer.Play();
}
void WheelImpulse() {
}
}

View File

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 4cdc0f9b9c7604ab9a5d4ac68eb8277f
timeCreated: 1520258375
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -246,11 +246,27 @@ InputManager:
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: VerticalP2
m_Name: WheelP1
descriptiveName:
descriptiveNegativeName:
negativeButton: down
positiveButton: up
negativeButton:
positiveButton: f
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 1
invert: 0
type: 0
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: WheelP2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: j
altNegativeButton:
altPositiveButton:
gravity: 1000