public void UpdateObject(SyncObjectMessage msg) { Object obj = EditorUtility.InstanceIDToObject(msg.object_id); if (obj) { SerializedObject ser_obj = new UnityEditor.SerializedObject(obj); ser_obj.CopyFromSerializedProperty(msg.prop); ser_obj.ApplyModifiedPropertiesWithoutUndo(); EditorSceneManager.MarkSceneDirty(m_scene); } }
UndoPropertyModification[] OnPostProcessModifications(UndoPropertyModification[] propertyModifications) { foreach (UndoPropertyModification mod in propertyModifications) { Debug.Log("Modified: " + mod.currentValue.propertyPath + " Value: " + mod.currentValue.value + " Object: " + mod.currentValue.target.name + " ObjectID: " + UnityEditorInternal.InternalEditorUtility.GetGameObjectInstanceIDFromComponent(mod.currentValue.target.GetInstanceID()) + " Componenet ObjectID: " + mod.currentValue.target.GetInstanceID() + " Component: " + mod.currentValue.target.GetType().Name); if (mod.currentValue.target.GetType() == typeof(GameObject)) { GameObject obj = (GameObject)mod.currentValue.target; SyncObjectMessage msg = new SyncObjectMessage(); msg.prop = SerializeMod(mod.currentValue); msg.client_info = new ClientInfo(); if (obj.scene.name == "Session") { msg.scene_name = Client.scene_name; msg.client_info.client_id = Client.client_id; msg.client_info.m_name = Client.client_name; msg.object_id = Client.GetServerObjID(mod.currentValue.target.GetInstanceID()); Client.SendSyncObjectMessage(Server, msg); } else { msg.scene_name = obj.scene.name; msg.client_info.client_id = 0; msg.client_info.m_name = "Server"; msg.object_id = mod.currentValue.target.GetInstanceID(); Server.SendSyncObjectMessage(Client, msg); } } else// if (mod.currentValue.target.GetType() == typeof(Component)) { Component comp = (Component)mod.currentValue.target; SyncObjectMessage msg = new SyncObjectMessage(); msg.prop = SerializeMod(mod.currentValue); msg.client_info = new ClientInfo(); if (comp.gameObject.scene.name == "Session") { msg.scene_name = Client.scene_name; msg.client_info.client_id = Client.client_id; msg.client_info.m_name = Client.client_name; msg.object_id = Client.GetServerObjID(mod.currentValue.target.GetInstanceID()); Client.SendSyncObjectMessage(Server, msg); } else { msg.scene_name = comp.gameObject.scene.name; msg.client_info.client_id = 0; msg.client_info.m_name = "Server"; msg.object_id = mod.currentValue.target.GetInstanceID(); Server.SendSyncObjectMessage(Client, msg); } } } return(propertyModifications); }
public void Update() { // Check for Join/Leave Session while (m_join_messages.Count > 0) { JoinMessage msg = m_join_messages.Dequeue(); Session s = new Session(); if (!m_session_mgr.Exists(msg.scene_name)) { // CreateSession s = m_session_mgr.CreateSession(m_name_to_path[msg.scene_name], OpenSceneMode.Additive); } if (s) { s.AddClient(msg.client); foreach (SceneManagerClient smc in clients) { SendJoinMsg(smc, msg); } } } while (m_leave_messages.Count > 0) { LeaveMessage msg = m_leave_messages.Dequeue(); Session s = m_session_mgr.GetSessionBySceneName(msg.scene_name); if (s) { s.RemoveClient(msg.client); if (!(s.GetClientSize() > 0)) { // Save Scene // EditorSceneManager.Save // DestroySession m_session_mgr.DestroySession(m_session_mgr.GetSessionBySceneName(msg.scene_name)); } foreach (SceneManagerClient smc in clients) { SendLeaveMsg(smc, msg); } } } while (m_sync_scene_messages.Count > 0) { // Grab all objects in the scene and send them to the client to map SyncSceneMessage msg = m_sync_scene_messages.Dequeue(); Session s = m_session_mgr.GetSessionBySceneName(msg.scene_name); SyncSceneMessage sync_msg = new SyncSceneMessage(); sync_msg.scene_name = s.Scene.name; sync_msg.client_id = 0; sync_msg.objects = s.Scene.GetRootGameObjects(); SceneManagerClient client = clients.Find(x => x.client_id == msg.client_id); SendSyncSceneMsg(client, sync_msg); } while (m_lock_obj_messages.Count > 0) { LockObjectMessage msg = m_lock_obj_messages.Dequeue(); Session s = m_session_mgr.GetSessionBySceneName(msg.scene_name); if (s) { s.LockObject(msg.object_id, msg.lock_info.client_info); //foreach (SceneManagerClient smc in clients) //{ // SendLockObjMsg(smc, msg); //} } } while (m_unlock_obj_messages.Count > 0) { UnlockObjectMessage msg = m_unlock_obj_messages.Dequeue(); Session s = m_session_mgr.GetSessionBySceneName(msg.scene_name); if (s) { s.UnlockObject(msg.object_id, msg.lock_info.client_info); //foreach (SceneManagerClient smc in clients) //{ // SendUnlockObjMsg(smc, msg); //} } } while (m_sync_obj_messages.Count > 0) { SyncObjectMessage msg = m_sync_obj_messages.Dequeue(); Session s = m_session_mgr.GetSessionBySceneName(msg.scene_name); if (s) { s.UpdateObject(msg); foreach (SceneManagerClient smc in clients) { SendSyncObjectMessage(smc, msg); } } } m_session_mgr.Update(); }
public void RecieveSyncObjectMessage(SyncObjectMessage msg) { m_sync_obj_messages.Enqueue(msg); }
public void SendSyncObjectMessage(SceneManagerClient client, SyncObjectMessage msg) { client.RecieveSyncObjectMessage(msg); }
public void Update() { // Check for Join/Leave Session while (m_join_messages.Count > 0) { JoinMessage msg = m_join_messages.Dequeue(); if (msg.scene_name == scene_name) { session.AddClient(msg.client); if (msg.client.client_id == client_id) { SyncSceneMessage sync_msg = new SyncSceneMessage(); sync_msg.scene_name = scene_name; sync_msg.client_id = client_id; SendSyncSceneMsg(server, sync_msg); } } } while (m_leave_messages.Count > 0) { LeaveMessage msg = m_leave_messages.Dequeue(); if (msg.scene_name == scene_name) { session.RemoveClient(msg.client); } } while (m_sync_scene_messages.Count > 0) { // Check if the given objects are in the client // Map the Client's ObjectID's to the Server's ObjectID's // Set Client Objects as copies of Server Objects // TODO: Create an object if it's not present on Client SyncSceneMessage msg = m_sync_scene_messages.Dequeue(); if (msg.scene_name == scene_name) { GameObject[] objs = session.GetGameObjects(); foreach (GameObject obj in objs) { Object.DestroyImmediate(obj); } foreach (GameObject obj in msg.objects) { GameObject g_obj = Object.Instantiate(obj); ClientToServerID[g_obj.GetInstanceID()] = obj.GetInstanceID(); ServerToClientID[obj.GetInstanceID()] = g_obj.GetInstanceID(); Component[] server_comps = obj.GetComponents(typeof(Component)); Component[] client_comps = g_obj.GetComponents(typeof(Component)); for (int i = 0; i < client_comps.Length; ++i) { ClientToServerID[client_comps[i].GetInstanceID()] = server_comps[i].GetInstanceID(); ServerToClientID[server_comps[i].GetInstanceID()] = client_comps[i].GetInstanceID(); } } } } // Check for Locked/Unlocked Object(s) while (m_lock_obj_messages.Count > 0) { LockObjectMessage msg = m_lock_obj_messages.Dequeue(); if (msg.scene_name == scene_name) { session.LockObject(msg.object_id, msg.lock_info.client_info); } } while (m_unlock_obj_messages.Count > 0) { UnlockObjectMessage msg = m_unlock_obj_messages.Dequeue(); if (msg.scene_name == scene_name) { session.UnlockObject(msg.object_id, msg.lock_info.client_info); } } // Check for SyncObjects while (m_sync_obj_messages.Count > 0) { SyncObjectMessage msg = m_sync_obj_messages.Dequeue(); if (msg.scene_name == scene_name) { msg.object_id = GetClientObjID(msg.object_id); if (msg.client_info.client_id != client_id) { session.UpdateObject(msg); } } } // If any of those checked, update log //Object[] obj = Object.FindObjectsOfType(typeof(Component)); }
public void SendSyncObjectMessage(SceneManagerServer server, SyncObjectMessage msg) { msg.scene_name = scene_name; server.RecieveSyncObjectMessage(msg); }