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
53f5d6f7
Commit
53f5d6f7
authored
Aug 03, 2021
by
LiLiuZhou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
b1a0ee9d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
11 deletions
+102
-11
MusicCell.cs
Assets/Scripts/Cell/MusicCell.cs
+0
-1
Fruit.cs
Assets/Scripts/Game/Fruit.cs
+102
-10
No files found.
Assets/Scripts/Cell/MusicCell.cs
View file @
53f5d6f7
...
@@ -10,7 +10,6 @@ public class MusicCell : BasePanel
...
@@ -10,7 +10,6 @@ public class MusicCell : BasePanel
{
{
public
SongItemBean
bean
;
public
SongItemBean
bean
;
public
bool
IsPlaying
=
false
;
public
override
void
OnHide
(
object
data
=
null
)
public
override
void
OnHide
(
object
data
=
null
)
{
{
...
...
Assets/Scripts/Game/Fruit.cs
View file @
53f5d6f7
...
@@ -11,6 +11,19 @@ public class Fruit : MonoBehaviour
...
@@ -11,6 +11,19 @@ public class Fruit : MonoBehaviour
{
{
private
Rigidbody2D
rig2D
;
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
()
public
void
OnInit
()
{
{
rig2D
=
GetComponent
<
Rigidbody2D
>();
rig2D
=
GetComponent
<
Rigidbody2D
>();
...
@@ -24,9 +37,46 @@ public class Fruit : MonoBehaviour
...
@@ -24,9 +37,46 @@ public class Fruit : MonoBehaviour
private
void
OnCollisionEnter2D
(
Collision2D
collision
)
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
)
if
(
int
.
Parse
(
gameObject
.
name
)
>=
11
)
{
{
return
;
return
;
...
@@ -80,18 +130,60 @@ public class Fruit : MonoBehaviour
...
@@ -80,18 +130,60 @@ public class Fruit : MonoBehaviour
//生成爆炸效果
//生成爆炸效果
Instantiate
(
Resources
.
Load
<
GameObject
>(
"Prefabs/BoomEffect"
),
MidPos
,
Quaternion
.
identity
);
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"
);
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
=
obj
.
GetComponent
<
Image
>().
sprite
=
ResMgr
.
Getinstance
().
Load
<
SpriteAtlas
>(
"Atlas/Notes"
).
GetSprite
(
"note"
+
UnityEngine
.
Random
.
Range
(
1
,
4
).
ToString
());
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"
);
EventCenter
.
Getinstance
().
EventTrigger
(
"FlyNote"
);
}
Destroy
(
collision
.
gameObject
);
//刷新底部CD
Destroy
(
this
.
gameObject
);
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
;
}
}
}
}
}
}
}
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