From 8dc8538c3e0f52b436dc578d34c91687bf528673 Mon Sep 17 00:00:00 2001 From: Yuri Visser Date: Fri, 15 Aug 2014 15:04:17 -0400 Subject: [PATCH] added auto load & play feature to player --- Assets/Scenes/TestScene.unity | 212 +++++------------- .../UniTunes/Prefabs/SoundCloudPlayer.prefab | 56 ++--- .../Scripts/Player/SoundCloudPlayer.cs | 26 ++- Assets/readme.txt | 8 +- README.md | 8 +- 5 files changed, 124 insertions(+), 186 deletions(-) diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index c42b1ac..aaa441d 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -74,6 +74,50 @@ NavMeshSettings: widthInaccuracy: 16.666666 heightInaccuracy: 10 m_NavMesh: {fileID: 0} +--- !u!1001 &557827785 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + m_RootGameObject: {fileID: 1926965186} + m_IsPrefabParent: 0 + m_IsExploded: 1 --- !u!1 &920936955 GameObject: m_ObjectHideFlags: 0 @@ -116,8 +160,8 @@ Transform: --- !u!1 &1323473098 GameObject: m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 100002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - m_PrefabInternal: {fileID: 1642048048} + m_PrefabParentObject: {fileID: 100000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + m_PrefabInternal: {fileID: 557827785} serializedVersion: 4 m_Component: - 4: {fileID: 1323473099} @@ -132,8 +176,8 @@ GameObject: --- !u!4 &1323473099 Transform: m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - m_PrefabInternal: {fileID: 1642048048} + m_PrefabParentObject: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + m_PrefabInternal: {fileID: 557827785} m_GameObject: {fileID: 1323473098} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -2.21174788, y: -1.965734, z: 7.99403429} @@ -144,9 +188,9 @@ Transform: --- !u!114 &1323473100 MonoBehaviour: m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 11400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, + m_PrefabParentObject: {fileID: 11400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - m_PrefabInternal: {fileID: 1642048048} + m_PrefabInternal: {fileID: 557827785} m_GameObject: {fileID: 1323473098} m_Enabled: 1 m_EditorHideFlags: 0 @@ -420,153 +464,11 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 ---- !u!1001 &1642048048 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - propertyPath: m_RootOrder - value: 2 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - m_RootGameObject: {fileID: 1926965186} - m_IsPrefabParent: 0 - m_IsExploded: 1 ---- !u!1 &1914169999 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1914170002} - - 82: {fileID: 1914170001} - - 114: {fileID: 1914170000} - m_Layer: 0 - m_Name: SoundCloudService - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1914170000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1914169999} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9e103450920dd4d42a0e45c7517c32dd, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!82 &1914170001 -AudioSource: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1914169999} - m_Enabled: 1 - serializedVersion: 3 - m_audioClip: {fileID: 0} - m_PlayOnAwake: 1 - m_Volume: 1 - m_Pitch: 1 - Loop: 0 - Mute: 0 - Priority: 128 - DopplerLevel: 1 - MinDistance: 1 - MaxDistance: 500 - Pan2D: 0 - rolloffMode: 0 - BypassEffects: 0 - BypassListenerEffects: 0 - BypassReverbZones: 0 - rolloffCustomCurve: - serializedVersion: 2 - m_Curve: - - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - panLevelCustomCurve: - serializedVersion: 2 - m_Curve: - - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - spreadCustomCurve: - serializedVersion: 2 - m_Curve: - - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 ---- !u!4 &1914170002 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1914169999} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 3 --- !u!1 &1926965186 GameObject: m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 100000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - m_PrefabInternal: {fileID: 1642048048} + m_PrefabParentObject: {fileID: 100002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + m_PrefabInternal: {fileID: 557827785} serializedVersion: 4 m_Component: - 4: {fileID: 1926965187} @@ -581,8 +483,8 @@ GameObject: --- !u!4 &1926965187 Transform: m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - m_PrefabInternal: {fileID: 1642048048} + m_PrefabParentObject: {fileID: 400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} + m_PrefabInternal: {fileID: 557827785} m_GameObject: {fileID: 1926965186} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} @@ -594,9 +496,9 @@ Transform: --- !u!114 &1926965188 MonoBehaviour: m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 11400000, guid: a56c9212e7c4e44f78b1f162b9feffdb, + m_PrefabParentObject: {fileID: 11400002, guid: a56c9212e7c4e44f78b1f162b9feffdb, type: 2} - m_PrefabInternal: {fileID: 1642048048} + m_PrefabInternal: {fileID: 557827785} m_GameObject: {fileID: 1926965186} m_Enabled: 1 m_EditorHideFlags: 0 @@ -605,3 +507,5 @@ MonoBehaviour: m_EditorClassIdentifier: widgetDocking: 3 playerMode: 0 + playerStartupMode: 0 + autoStartupUrl: diff --git a/Assets/UniTunes/Prefabs/SoundCloudPlayer.prefab b/Assets/UniTunes/Prefabs/SoundCloudPlayer.prefab index bf89a89..6a3f024 100644 --- a/Assets/UniTunes/Prefabs/SoundCloudPlayer.prefab +++ b/Assets/UniTunes/Prefabs/SoundCloudPlayer.prefab @@ -9,13 +9,13 @@ GameObject: m_Component: - 4: {fileID: 400000} - 114: {fileID: 11400000} - m_Layer: 0 - m_Name: SoundCloudPlayer + m_Layer: 8 + m_Name: GUIPlayer m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!1 &100002 GameObject: m_ObjectHideFlags: 0 @@ -25,13 +25,13 @@ GameObject: m_Component: - 4: {fileID: 400002} - 114: {fileID: 11400002} - m_Layer: 8 - m_Name: GUIPlayer + m_Layer: 0 + m_Name: SoundCloudPlayer m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!4 &400000 Transform: m_ObjectHideFlags: 1 @@ -39,11 +39,10 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 100000} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: -2.21174788, y: -1.965734, z: 7.99403429} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 400002} - m_Father: {fileID: 0} + m_Children: [] + m_Father: {fileID: 400002} m_RootOrder: 0 --- !u!4 &400002 Transform: @@ -52,10 +51,11 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 100002} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -2.21174788, y: -1.965734, z: 7.99403429} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 400000} + m_Children: + - {fileID: 400000} + m_Father: {fileID: 0} m_RootOrder: 0 --- !u!114 &11400000 MonoBehaviour: @@ -65,19 +65,6 @@ MonoBehaviour: m_GameObject: {fileID: 100000} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: da5ddf56437424c77b345b96cb1d0495, type: 3} - m_Name: - m_EditorClassIdentifier: - widgetDocking: 3 - playerMode: 0 ---- !u!114 &11400002 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 100002} - m_Enabled: 1 - m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: b7ea2bd687c5641a68448495cebba29e, type: 3} m_Name: m_EditorClassIdentifier: @@ -264,6 +251,21 @@ MonoBehaviour: m_StretchWidth: 0 m_StretchHeight: 0 skin: {fileID: 0} +--- !u!114 &11400002 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100002} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: da5ddf56437424c77b345b96cb1d0495, type: 3} + m_Name: + m_EditorClassIdentifier: + widgetDocking: 3 + playerMode: 0 + playerStartupMode: 0 + autoStartupUrl: --- !u!1001 &100100000 Prefab: m_ObjectHideFlags: 1 @@ -273,6 +275,6 @@ Prefab: m_Modifications: [] m_RemovedComponents: [] m_ParentPrefab: {fileID: 0} - m_RootGameObject: {fileID: 100000} + m_RootGameObject: {fileID: 100002} m_IsPrefabParent: 1 m_IsExploded: 1 diff --git a/Assets/UniTunes/Scripts/Player/SoundCloudPlayer.cs b/Assets/UniTunes/Scripts/Player/SoundCloudPlayer.cs index 84ddaa1..5d2bc2b 100644 --- a/Assets/UniTunes/Scripts/Player/SoundCloudPlayer.cs +++ b/Assets/UniTunes/Scripts/Player/SoundCloudPlayer.cs @@ -10,7 +10,18 @@ public class SoundCloudPlayer : UniTunesSingleton public SCPlayerDocking.Docking widgetDocking = SCPlayerDocking.Docking.None; public PlayerMode playerMode = PlayerMode.StartMaximized; - public enum PlayerMode { + public PlayerStatupMode playerStartupMode = PlayerStatupMode.Manual_ViaScript; + public string autoStartupUrl = string.Empty; + + public enum PlayerStatupMode + { + Manual_ViaScript, + Auto_StreamingAssets, + Auto_Url + } + + public enum PlayerMode + { StartMaximized, StartMinimized, AlwaysMaximized, @@ -31,6 +42,19 @@ void Start() _playerWidget = gameObject.GetComponentInChildren(); _playerWidget.SetPlayerMessage(UniTunesConsts.EN_WAITING_FOR, UniTunesConsts.EN_PLAYLIST_CONFIG); + + //if the player startup is not manual, load config & start playback + if(playerStartupMode == PlayerStatupMode.Auto_StreamingAssets) { + LoadSet(true); + } + else if(playerStartupMode == PlayerStatupMode.Auto_Url) { + if(!string.IsNullOrEmpty(autoStartupUrl)) { + LoadSet(autoStartupUrl, true); + } + else { + Debug.LogWarning("SoundCloudPlayer - you have selected Auto_Url as Player Startup Mode. Please provide a URL"); + } + } } void OnEnable() diff --git a/Assets/readme.txt b/Assets/readme.txt index 47d9150..8f96d1f 100644 --- a/Assets/readme.txt +++ b/Assets/readme.txt @@ -42,12 +42,16 @@ Usage - Bottom-Left - Bottom-Centre - Bottom-Right -7. Use the following API to control playback +7. Set the "Player Startup Mode". The possible selections are: + 1. Manual_ViaScript - control set loading and playback start via script (see #9) + 2. Auto_StreamingAssets - automatically loads set config from StreamingAssets, and starts playback on load completion + 3. Auto_Url - automatically loads set config from the url provided in "Auto Startup Url", and starts playback on load completion +8. Use the following API to control playback - __LoadSet(string configUrl, bool autoPlay)__ Use this method if you have your config file online and wish to specify the URL of the Json Config - __LoadSet(bool autoPlay)__ - __PlaySet()__ -8. Additional API methods available +9. Additional API methods available - __PlayNext()__ - __PlayFromIndex(int index)__ - __StopPlayback()__ diff --git a/README.md b/README.md index db4c67f..01e26fc 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,16 @@ Usage - Bottom-Left - Bottom-Centre - Bottom-Right -7. Use the following API to control playback +7. Set the "Player Startup Mode". The possible selections are: + 1. Manual_ViaScript - control set loading and playback start via script (see #9) + 2. Auto_StreamingAssets - automatically loads set config from StreamingAssets, and starts playback on load completion + 3. Auto_Url - automatically loads set config from the url provided in "Auto Startup Url", and starts playback on load completion +8. Use the following API to control playback - __LoadSet(string configUrl, bool autoPlay)__ Use this method if you have your config file online and wish to specify the URL of the Json Config - __LoadSet(bool autoPlay)__ - __PlaySet()__ -8. Additional API methods available +9. Additional API methods available - __PlayNext()__ - __PlayFromIndex(int index)__ - __StopPlayback()__