Skip to content

Commit

Permalink
change: Give user the option to delete or stash previously imported o…
Browse files Browse the repository at this point in the history
…bjects when the session changes. (#728)

* Give user the option to delete or stash previously imported objects when the session changes.

* Extracting method.

* Only do session check in editor.
  • Loading branch information
schinkowski authored Jul 27, 2022
1 parent e78052a commit 30bae54
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
49 changes: 47 additions & 2 deletions Runtime/Scripts/BaseMeshSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ internal void Init(string assetsFolder) {

m_clientInstances.Clear();
m_clientInstancedEntities.Clear();

m_prefabDict.Clear();

InitInternalV();
}
Expand All @@ -182,7 +184,8 @@ internal IDictionary<string, EntityRecord> GetClientObjects() {
#endregion Simple Getter/Setter

#region Properties


private int currentSessionId = -1;

private protected string GetServerDocRootPath() { return Application.streamingAssetsPath + "/MeshSyncServerRoot"; }

Expand Down Expand Up @@ -473,8 +476,50 @@ internal void ForceRepaint() {
#endregion

#region ReceiveScene
internal void BeforeUpdateScene() {

internal void BeforeUpdateScene(FenceMessage? mes = null) {
onSceneUpdateBegin?.Invoke();

CheckForNewSession(mes);
}

void CheckForNewSession(FenceMessage? mes) {
#if UNITY_EDITOR
if (!mes.HasValue || currentSessionId == mes.Value.SessionId) {
return;
}

currentSessionId = mes.Value.SessionId;

if (transform.childCount <= 0) {
return;
}

int choice = EditorUtility.DisplayDialogComplex("A new session started.",
"MeshSync detected that the DCC tool session has changed. To ensure that the sync state is correct you can delete previously synced objects, stash them and move them to another game object or ignore this and keep all children.",
"Ignore and keep all children",
"Stash",
"Delete all children of the server");

switch (choice) {
case 1:
// Stash
var stash = new GameObject($"{name}_stash").transform;
for (int i = transform.childCount - 1; i >= 0; i--) {
Transform child = transform.GetChild(i);
child.SetParent(stash, true);
}

Init(GetAssetsFolder());
break;
case 2:
// Destroy
transform.DestroyChildrenImmediate();

Init(GetAssetsFolder());
break;
}
#endif
}

private protected void UpdateScene(SceneData scene, bool updateNonMaterialAssets) {
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/MeshSyncServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void OnRecvDelete(DeleteMessage mes) {

void OnRecvFence(FenceMessage mes) {
if (mes.type == FenceMessage.FenceType.SceneBegin) {
BeforeUpdateScene();
BeforeUpdateScene(mes);
} else if (mes.type == FenceMessage.FenceType.SceneEnd) {
AfterUpdateScene();
m_server.NotifyPoll(PollMessage.PollType.SceneUpdate);
Expand Down
6 changes: 6 additions & 0 deletions Runtime/Scripts/msMessagesAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ internal struct FenceMessage {
#region internal
public IntPtr self;
[DllImport(Lib.name)] static extern FenceType msFenceGetType(IntPtr self);

[DllImport(Lib.name)] static extern int msMessageGetSessionID(IntPtr self);
#endregion

public enum FenceType {
Expand All @@ -150,6 +152,10 @@ public static explicit operator FenceMessage(IntPtr v) {
}

public FenceType type { get { return msFenceGetType(self); } }

public int SessionId {
get { return msMessageGetSessionID(self); }
}
}
//----------------------------------------------------------------------------------------------------------------------

Expand Down

0 comments on commit 30bae54

Please sign in to comment.