/// <summary> /// Called when an AnimatorUpdateMessage is received. /// </summary> /// <param name="msg"></param> /// <param name="receivedOnClient"></param> private void AnimatorUpdateMessageReceived(AnimatorUpdateMessage msg, bool receivedOnClient) { //Have to check sequence id against the FNT sending. int count = msg.Data.Count; for (int i = 0; i < count; i++) { /* Initially I tried caching the getcomponent calls but the performance difference * couldn't be registered. At this time it's not worth creating the extra complexity * for what might be a 1% fps difference. */ if (NetworkIdentity.spawned.TryGetValue(msg.Data[i].NetworkIdentity, out NetworkIdentity ni)) { if (ni != null) { FlexNetworkAnimator fna = ReturnFNAOnNetworkIdentity(ni, msg.Data[i].ComponentIndex); if (fna != null) { if (receivedOnClient) { fna.ServerDataReceived(msg.Data[i]); } else { fna.ClientDataReceived(msg.Data[i]); } } } } } }
/// <summary> /// Sends data to all or specified connection. /// </summary> /// <param name="conn"></param> /// <param name="datas"></param> /// <param name="reliable"></param> private void SendAnimatorUpdates(bool toServer, NetworkConnection conn, List <AnimatorUpdate> datas) { int index = 0; int bundleCount = _reliableDataBundleCount; int channel = 0; while (index < datas.Count) { int count = Mathf.Min(bundleCount, datas.Count - index); AnimatorUpdateMessage msg = new AnimatorUpdateMessage() { Data = datas.GetRange(index, count) }; if (toServer) { NetworkClient.Send(msg, channel); } else { //If no connection then send to all. if (conn == null) { NetworkServer.SendToAll(msg, channel); } //Otherwise send to connection. else { conn.Send(msg, channel); } } index += count; } }
/// <summary> /// Received on server when client sends data. /// </summary> /// <param name="msg"></param> private void OnClientAnimatorUpdate(AnimatorUpdateMessage msg) { AnimatorUpdateMessageReceived(msg, false); }
/// <summary> /// Received on clients when server sends data. /// </summary> /// <param name="msg"></param> private void OnServerAnimatorUpdate(AnimatorUpdateMessage msg) { AnimatorUpdateMessageReceived(msg, true); }