Commit 53f5d6f7 authored by LiLiuZhou's avatar LiLiuZhou

1

parent b1a0ee9d
...@@ -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)
{ {
......
...@@ -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);
//生成音符特效 //生成音符特效 并发送事件
GameObject obj = ResMgr.Getinstance().Load<GameObject>("Prefabs/Note"); FlyNotes(MidPos);
obj.transform.ResetToCanvas(E_Layer.system,UIMgr.Getinstance().canvas.InverseTransformPoint(MidPos));
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); });
//发送事件
EventCenter.Getinstance().EventTrigger("FlyNote");
Destroy(collision.gameObject); Destroy(collision.gameObject);
Destroy(this.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(StartPos));
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); });
//发送事件
EventCenter.Getinstance().EventTrigger("FlyNote");
}
//刷新底部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;
}
}
}
} }
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