using System.Collections.Generic; using System.Diagnostics; namespace ET { public static class MessageHelper { public static void Broadcast(IEnumerable mineTeam, IEnumerable targetTeam, IActorMessage message) { if (mineTeam != null) foreach (Unit unit in mineTeam) { SendActor(unit, message); } if (targetTeam != null) foreach (Unit unit in targetTeam) { SendActor(unit, message); } } /// /// 发送协议给ActorLocation /// /// 注册Actor的Id /// public static void SendToLocationActor(long id, IActorLocationMessage message) { ActorLocationSenderComponent.Instance.Send(id, message); } /// /// 发送协议给Actor /// /// 注册Actor的InstanceId /// public static void SendActor(long actorId, IActorMessage message) { ActorMessageSenderComponent.Instance.Send(actorId, message); } public static void SendActor(Unit unit, IActorMessage message) { if (!unit) { Log.Error($"unit Id = {unit?.Id} is Disposed "); return; } if (unit.IsOffline) { return; } UserGateComponent gate = unit.GetComponent(); if (gate == null) return; SendActor(unit.GetComponent().GateSessionActorId, message); } /// /// 发送RPC协议给Actor /// /// 注册Actor的InstanceId /// /// public static async ETTask CallActor(long actorId, IActorRequest message) { return await ActorMessageSenderComponent.Instance.Call(actorId, message); } /// /// 发送RPC协议给ActorLocation /// /// 注册Actor的Id /// /// public static async ETTask CallLocationActor(long id, IActorLocationRequest message) { return await ActorLocationSenderComponent.Instance.Call(id, message); } } }