Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
M
MusicBigWatermelon
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王雪伟
MusicBigWatermelon
Commits
89bd2939
Commit
89bd2939
authored
Aug 03, 2021
by
王雪伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.huolea.com:wangxuewei/musicbigwatermelon
parents
922a634d
53f5d6f7
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
401 additions
and
21 deletions
+401
-21
Pause.png
Assets/Artres/PanelPic/MusicPanel/Pause.png
+0
-0
Pause.png.meta
Assets/Artres/PanelPic/MusicPanel/Pause.png.meta
+0
-0
Start.png
Assets/Artres/PanelPic/MusicPanel/Start.png
+0
-0
Start.png.meta
Assets/Artres/PanelPic/MusicPanel/Start.png.meta
+0
-0
MusicMgr.cs
Assets/FunScripts/Core/MusicMgr.cs
+3
-0
MusicPanel.spriteatlas
Assets/Resources/Atlas/MusicPanel.spriteatlas
+44
-0
MusicPanel.spriteatlas.meta
Assets/Resources/Atlas/MusicPanel.spriteatlas.meta
+8
-0
MusicCell.prefab
Assets/Resources/Cells/MusicCell.prefab
+1
-1
MusicPanel.prefab
Assets/Resources/UI/Panel/MusicPanel.prefab
+134
-1
MusicCell.cs
Assets/Scripts/Cell/MusicCell.cs
+70
-5
Fruit.cs
Assets/Scripts/Game/Fruit.cs
+102
-12
MusicPanel.cs
Assets/Scripts/Panel/MusicPanel.cs
+39
-2
No files found.
Assets/Artres/PanelPic/MusicPanel/
暂停@3x
.png
→
Assets/Artres/PanelPic/MusicPanel/
Pause
.png
View file @
89bd2939
File moved
Assets/Artres/PanelPic/MusicPanel/
暂停@3x
.png.meta
→
Assets/Artres/PanelPic/MusicPanel/
Pause
.png.meta
View file @
89bd2939
File moved
Assets/Artres/PanelPic/MusicPanel/
开始@3x
.png
→
Assets/Artres/PanelPic/MusicPanel/
Start
.png
View file @
89bd2939
File moved
Assets/Artres/PanelPic/MusicPanel/
开始@3x
.png.meta
→
Assets/Artres/PanelPic/MusicPanel/
Start
.png.meta
View file @
89bd2939
File moved
Assets/FunScripts/Core/MusicMgr.cs
View file @
89bd2939
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
();
}
}
}
Assets/Resources/Atlas/MusicPanel.spriteatlas
0 → 100644
View file @
89bd2939
%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
Assets/Resources/Atlas/MusicPanel.spriteatlas.meta
0 → 100644
View file @
89bd2939
fileFormatVersion: 2
guid: 0cdd583dec719154f9c01d47a867208b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4343727234628468602
userData:
assetBundleName:
assetBundleVariant:
Assets/Resources/Cells/MusicCell.prefab
View file @
89bd2939
...
...
@@ -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
:
...
...
Assets/Resources/UI/Panel/MusicPanel.prefab
View file @
89bd2939
...
...
@@ -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
}
...
...
Assets/Scripts/Cell/MusicCell.cs
View file @
89bd2939
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
override
void
OnHide
(
object
data
=
null
)
{
...
...
@@ -26,6 +31,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 +42,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
));
}
}
}
}
Assets/Scripts/Game/Fruit.cs
View file @
89bd2939
...
...
@@ -11,6 +11,19 @@ public class Fruit : MonoBehaviour
{
private
Rigidbody2D
rig2D
;
//碰撞底部播放声音的CD
private
float
BottomColiderCD
=
1f
;
//CD计时器
private
float
BottomColiderCDTimer
;
//底部播放声音是否正在CD
private
bool
BottomColiderIsCD
;
//两侧是否正在CD
private
float
SidesColiderCD
=
1f
;
private
float
SidesColiderCDTimer
;
private
bool
SidesColiderIsCD
;
public
void
OnInit
()
{
rig2D
=
GetComponent
<
Rigidbody2D
>();
...
...
@@ -24,9 +37,46 @@ public class Fruit : MonoBehaviour
private
void
OnCollisionEnter2D
(
Collision2D
collision
)
{
if
(
collision
.
gameObject
.
CompareTag
(
"Bottom"
))
{
if
(!
BottomColiderIsCD
)
{
BottomColiderIsCD
=
true
;
//计算碰撞点
Bounds
bound
=
transform
.
GetComponent
<
SpriteRenderer
>().
bounds
;
float
FruitRadius
=
bound
.
size
.
x
/
2
;
//世界坐标
Vector3
CollisionPos
=
new
Vector3
(
transform
.
position
.
x
,
transform
.
position
.
y
-
FruitRadius
,
0
);
FlyNotes
(
CollisionPos
);
}
return
;
}
if
(
collision
.
gameObject
.
CompareTag
(
"Sides"
))
{
//加上角度限制 防止玩家从最左右边落下水果 直接触发音乐符号
if
(!
SidesColiderIsCD
&&
Vector3
.
Angle
(
gameObject
.
GetComponent
<
Rigidbody2D
>().
velocity
,
Vector2
.
down
)
>
5
)
{
SidesColiderIsCD
=
true
;
//计算碰撞点
Bounds
bound
=
transform
.
GetComponent
<
SpriteRenderer
>().
bounds
;
float
FruitRadius
=
bound
.
size
.
x
/
2
;
//判断是左边碰到还是右边碰到
int
factor
=
collision
.
transform
.
position
.
x
>
transform
.
position
.
x
?
1
:
-
1
;
//世界坐标
Vector3
CollisionPos
=
new
Vector3
(
transform
.
position
.
x
+
(
FruitRadius
*
factor
),
transform
.
position
.
y
,
0
);
FlyNotes
(
CollisionPos
);
}
return
;
}
//如果两个水果名字一样
if
(
gameObject
.
name
==
collision
.
gameObject
.
name
)
if
(
gameObject
.
name
==
collision
.
gameObject
.
name
)
{
//如果已经是最大的
if
(
int
.
Parse
(
gameObject
.
name
)
>=
11
)
{
return
;
...
...
@@ -48,8 +98,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
;
...
...
@@ -82,18 +130,60 @@ public class Fruit : MonoBehaviour
//生成爆炸效果
Instantiate
(
Resources
.
Load
<
GameObject
>(
"Prefabs/BoomEffect"
),
MidPos
,
Quaternion
.
identity
);
//生成音符特效
//生成音符特效 并发送事件
FlyNotes
(
MidPos
);
Destroy
(
collision
.
gameObject
);
Destroy
(
this
.
gameObject
);
}
}
private
void
FixedUpdate
()
{
UpdateBottomColiderInCD
();
UpdateSidesColiderInCD
();
}
//生成音符特效 并发送事件
private
void
FlyNotes
(
Vector2
StartPos
)
{
GameObject
obj
=
ResMgr
.
Getinstance
().
Load
<
GameObject
>(
"Prefabs/Note"
);
obj
.
transform
.
ResetToCanvas
(
E_Layer
.
system
,
UIMgr
.
Getinstance
().
canvas
.
InverseTransformPoint
(
Mid
Pos
));
obj
.
transform
.
ResetToCanvas
(
E_Layer
.
system
,
UIMgr
.
Getinstance
().
canvas
.
InverseTransformPoint
(
Start
Pos
));
obj
.
GetComponent
<
Image
>().
sprite
=
ResMgr
.
Getinstance
().
Load
<
SpriteAtlas
>(
"Atlas/Notes"
).
GetSprite
(
"note"
+
UnityEngine
.
Random
.
Range
(
1
,
4
).
ToString
());
(
obj
.
transform
as
RectTransform
).
DoMove
(
0.5f
,
new
Vector2
(
0
,
580
),
trans
=>
{
Destroy
(
trans
.
gameObject
);
});
(
obj
.
transform
as
RectTransform
).
DoMove
(
0.5f
,
new
Vector2
(
0
,
580
),
trans
=>
{
Destroy
(
trans
.
gameObject
);
});
//发送事件
EventCenter
.
Getinstance
().
EventTrigger
(
"FlyNote"
);
}
Destroy
(
collision
.
gameObject
);
Destroy
(
this
.
gameObject
);
//刷新底部CD
private
void
UpdateBottomColiderInCD
()
{
if
(
BottomColiderIsCD
)
{
BottomColiderCDTimer
+=
Time
.
fixedDeltaTime
;
if
(
BottomColiderCDTimer
>=
BottomColiderCD
)
{
BottomColiderIsCD
=
false
;
BottomColiderCDTimer
=
0
;
}
}
}
//刷新两侧CD
private
void
UpdateSidesColiderInCD
()
{
if
(
SidesColiderIsCD
)
{
SidesColiderCDTimer
+=
Time
.
fixedDeltaTime
;
if
(
SidesColiderCDTimer
>=
SidesColiderCD
)
{
SidesColiderIsCD
=
false
;
SidesColiderCDTimer
=
0
;
}
}
}
}
Assets/Scripts/Panel/MusicPanel.cs
View file @
89bd2939
...
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment