Commit b1a0ee9d authored by LiLiuZhou's avatar LiLiuZhou

1

parent a8c07a3c
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class MusicMgr : BaseMgr<MusicMgr>
{
......@@ -138,4 +139,6 @@ public class MusicMgr : BaseMgr<MusicMgr>
DragingMusic.GetComponent<AudioSource>().Pause();
}
}
}
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!687078895 &4343727234628468602
SpriteAtlas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: MusicPanel
m_EditorData:
serializedVersion: 2
textureSettings:
serializedVersion: 2
anisoLevel: 1
compressionQuality: 50
maxTextureSize: 2048
textureCompression: 0
filterMode: 1
generateMipMaps: 0
readable: 0
crunchedCompression: 0
sRGB: 1
platformSettings: []
packingSettings:
serializedVersion: 2
padding: 4
blockOffset: 1
allowAlphaSplitting: 0
enableRotation: 1
enableTightPacking: 1
variantMultiplier: 1
packables:
- {fileID: 21300000, guid: de06fc9c6cc871d43a282e9947ad8569, type: 3}
- {fileID: 21300000, guid: 4ba2a34dd9c70cd4b9d650767139a49f, type: 3}
bindAsDefault: 1
m_MasterAtlas: {fileID: 0}
m_PackedSprites:
- {fileID: 21300000, guid: de06fc9c6cc871d43a282e9947ad8569, type: 3}
- {fileID: 21300000, guid: 4ba2a34dd9c70cd4b9d650767139a49f, type: 3}
m_PackedSpriteNamesToIndex:
- Start
- Pause
m_Tag: MusicPanel
m_IsVariant: 0
fileFormatVersion: 2
guid: 0cdd583dec719154f9c01d47a867208b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4343727234628468602
userData:
assetBundleName:
assetBundleVariant:
......@@ -424,7 +424,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
......
......@@ -154,6 +154,138 @@ MonoBehaviour:
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: "\u6211\u5408\u6210\u7684\u6B4C\u66F2"
--- !u!1 &4733793534904436019
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2931496132081761462}
- component: {fileID: 973893917629565500}
m_Layer: 5
m_Name: AudioPlayer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2931496132081761462
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4733793534904436019}
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: 4635386703514042469}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!82 &973893917629565500
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4733793534904436019}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &6443396136560327243
GameObject:
m_ObjectHideFlags: 0
......@@ -407,7 +539,7 @@ MonoBehaviour:
m_StartCorner: 0
m_StartAxis: 0
m_CellSize: {x: 750, y: 120}
m_Spacing: {x: 0, y: 3.06}
m_Spacing: {x: 0, y: -5}
m_Constraint: 1
m_ConstraintCount: 1
--- !u!114 &2864378883970242340
......@@ -528,6 +660,7 @@ RectTransform:
m_Children:
- {fileID: 3609245793505339117}
- {fileID: 1269257140283984089}
- {fileID: 2931496132081761462}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.U2D;
using UnityEngine.UI;
public class MusicCell : BasePanel
{
public SongItemBean bean;
public bool IsPlaying = false;
public override void OnHide(object data = null)
{
......@@ -26,6 +32,8 @@ public class MusicCell : BasePanel
GetControl<Text>("txtNum").color = bean.song_id <= 3 ? Color.red : Color.black;
GetControl<Text>("txtMusicName").text = bean.song_name;
MonoMgr.Getinstance().StartCoroutine(GetTexture(bean.song_cover, GetControl<Image>("imgMusicPic")));
}
public override void OnRefresh(object data = null)
......@@ -35,17 +43,75 @@ public class MusicCell : BasePanel
public void OnStartMusic()
{
if (bean == null)
GetControl<Image>("btnPlayMusic").sprite = Resources.Load<SpriteAtlas>("Atlas/MusicPanel").GetSprite("Start");
//开始获取音频
MonoMgr.Getinstance().StartCoroutine(GetAudioClip(bean.song_play,clip=>
{
throw new System.Exception("cell数据为空");
}
MusicPanel panel = UIMgr.Getinstance().GetPanel<MusicPanel>();
if (panel == null)
return;
//如果当前面板播放的音乐不是自己
if (panel.PlayingCell != this)
return;
//如果当前正在播放
if (panel.IsPlayingMusic())
return;
panel.PlayMusic(clip);
}));
}
public void OnStopMusic()
{
if (bean == null)
GetControl<Image>("btnPlayMusic").sprite = Resources.Load<SpriteAtlas>("Atlas/MusicPanel").GetSprite("Pause");
MusicPanel panel = UIMgr.Getinstance().GetPanel<MusicPanel>();
panel.StopMusic();
}
//设置图片的方法
IEnumerator GetTexture(string URL,Image img)
{
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(URL))
{
throw new System.Exception("cell数据为空");
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
}
else
{
// Get downloaded asset bundle
Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
Sprite sp = Sprite.Create(texture, new Rect(0, 0, texture.width,texture.height), Vector2.zero);
img.sprite = sp;
}
}
}
//设置音频的方法
IEnumerator GetAudioClip(string URL,UnityAction<AudioClip> callback)
{
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(URL, AudioType.WAV))
{
yield return www.SendWebRequest();
if (www.isNetworkError)
{
Debug.Log(www.error);
}
else
{
callback.Invoke(DownloadHandlerAudioClip.GetContent(www));
}
}
}
}
......@@ -48,8 +48,6 @@ public class Fruit : MonoBehaviour
int fruitNum = int.Parse(gameObject.name) + 1;
string NewObjName = fruitNum.ToString();
GameObject Obj = Instantiate(Resources.Load<GameObject>("Fruits/" + NewObjName), MidPos, Quaternion.identity);
Obj.transform.localScale = new Vector3(0.3f, 0.3f, 1);
Obj.name = NewObjName;
......
......@@ -8,6 +8,8 @@ public class MusicPanel : BasePanel
{
//当前正在播放的格子
public MusicCell PlayingCell;
public AudioSource AS;
public override void OnHide(object data = null)
{
......@@ -17,6 +19,8 @@ public class MusicPanel : BasePanel
{
GetControl<Button>("btnBack").onClick.AddListener(() =>{ UIMgr.Getinstance().HidePanel<MusicPanel>(); });
AS = GetComponentInChildren<AudioSource>();
#region 通过数据初始化面板
Dictionary<string, object> paras = new Dictionary<string, object>();
......@@ -46,7 +50,40 @@ public class MusicPanel : BasePanel
public void ChangeMusic(MusicCell cell)
{
//如果正在播放的和点击的歌曲相同 表示 用户正在关闭当前播放的音乐
if (PlayingCell == cell)
{
cell.OnStopMusic();
PlayingCell = null;
return;
}
PlayingCell?.OnStopMusic();
PlayingCell = cell;
cell.OnStartMusic();
}
public bool IsPlayingMusic()
{
if (AS.clip == null)
return false;
return AS.isPlaying;
}
public void PlayMusic(AudioClip clip)
{
AS.clip = clip;
AS.loop = true;
AS.Play();
}
public void StopMusic()
{
AS.Stop();
AS.clip = null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment