void OnCollideBall(BallBeh ball) { var args = new BallCollisionArgs { Ball1 = this, Ball2 = ball }; SendMessageUpwards(Constants.OnBallAndBallCollision, args, SendMessageOptions.DontRequireReceiver); }
void OnBallAndBallCollision(BallCollisionArgs args) { var ball1 = args.Ball1; var ball2 = args.Ball2; // 判断胜负 var weight1 = ball1.Player.CustomProperties.GetFloat("weight"); var weight2 = ball2.Player.CustomProperties.GetFloat("weight"); Player winner, loser; if (weight1 > weight2) { winner = ball1.Player; loser = ball2.Player; } else { winner = ball2.Player; loser = ball1.Player; } var winnerWeight = weight1 + weight2; var props = new PlayObject { { "weight", winnerWeight } }; // 设置胜利方 winner.SetCustomProperties(props); // 重置失败方 var loserWeight = Mathf.Pow(Constants.BORN_SIZE, 2); var pos = BattleHelper.RandomPos(); props = new PlayObject { { "pos", pos }, { "weight", loserWeight }, { "move", null } }; loser.SetCustomProperties(props); // 通知胜负情况 var client = LeanCloudUtils.GetClient(); var eventData = new PlayObject { { "winnerId", winner.ActorId }, { "loserId", loser.ActorId } }; client.SendEvent(Constants.KILL_EVENT, eventData); // 通知重生 eventData = new PlayObject { { "playerId", loser.ActorId } }; client.SendEvent(Constants.REBORN_EVENT, eventData); }