public void Interpret(INetworkMediator netMediator, EndPoint sender, IMessage message) { var engine = (IEngineFacade)netMediator.EngineProxy; int count = engine.EntityRepository.Count; var msg = new SendEntitiesToNewPlayerMessage(); msg.EntityCount = count; msg.Ids = new int[count]; msg.PrefabIds = new int[count]; msg.Positions = new Vector3[count]; msg.Rotations = new Quaternion[count]; msg.Scales = new Vector3[count]; msg.SceneIdentifiers = new string[count]; int i = 0; var itr = engine.EntityRepository.GetEnumerator(); while (itr.MoveNext()) { if (itr.Current != null) { var t = itr.Current.OwnerGameObject.transform; msg.Ids[i] = itr.Current.Id; msg.PrefabIds[i] = itr.Current.PrefabId; msg.Positions[i] = t.position; msg.Rotations[i] = t.rotation; msg.Scales[i] = t.localScale; msg.SceneIdentifiers[i] = itr.Current.SceneIdentifier; } i++; } netMediator.SendReliableMessage(msg, sender); }
private static void SetupEntityAlreadyInScene(IUnityEntity[] sceneEntities, SendEntitiesToNewPlayerMessage msg, int idx, IEngineFacade engine) { foreach (var e in sceneEntities) { if (e.SceneIdentifier == msg.SceneIdentifiers[idx]) { e.Id = msg.Ids[idx]; e.PrefabId = msg.PrefabIds[idx]; Transform t = e.OwnerGameObject.transform; t.position = msg.Positions[idx]; t.rotation = msg.Rotations[idx]; t.localScale = msg.Scales[idx]; engine.EntityRepository.Add(e); } } }