Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility fix for 2019.4.40f1 #371

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,57 +163,57 @@ public static void OnEnterPlayMode()
if (CSGProjectSettings.Instance.SaveMeshesInSceneFiles)
return;

static bool ensureExternalMethodsPopulated()
{
if (External == null ||
External.ResetCSG == null)
{
NativeMethodBindings.RegisterUnityMethods();
NativeMethodBindings.RegisterExternalMethods();
}

if (External == null)
{
Debug.LogError("RealtimeCSG: Cannot rebuild meshes for some reason. External modules not loaded. Please save meshes into the Scene.");
return false;
}

return true;
}

static void rebuildMeshes()
{
if (!ensureExternalMethodsPopulated())
return;
if (!ensureExternalMethodsPopulated())
return;

RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = true;
InternalCSGModelManager.Shutdown();
DoForcedMeshUpdate();
InternalCSGModelManager.CheckForChanges(false);
RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = false;
}
EditorApplication.playModeStateChanged += onPlayModeChange;
UnityEngine.SceneManagement.SceneManager.sceneLoaded += sceneLoaded;
}

static void sceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode)
static bool ensureExternalMethodsPopulated()
{
if (External == null ||
External.ResetCSG == null)
{
rebuildMeshes();
NativeMethodBindings.RegisterUnityMethods();
NativeMethodBindings.RegisterExternalMethods();
}

static void onPlayModeChange(PlayModeStateChange playMode)
if (External == null)
{
if (playMode == PlayModeStateChange.EnteredEditMode)
{
UnityEngine.SceneManagement.SceneManager.sceneLoaded -= sceneLoaded;
EditorApplication.playModeStateChanged -= onPlayModeChange;

rebuildMeshes();
}
Debug.LogError("RealtimeCSG: Cannot rebuild meshes for some reason. External modules not loaded. Please save meshes into the Scene.");
return false;
}

return true;
}

static void rebuildMeshes()
{
if (!ensureExternalMethodsPopulated())
return;

EditorApplication.playModeStateChanged += onPlayModeChange;
UnityEngine.SceneManagement.SceneManager.sceneLoaded += sceneLoaded;
RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = true;
InternalCSGModelManager.Shutdown();
DoForcedMeshUpdate();
InternalCSGModelManager.CheckForChanges(false);
RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = false;
}

static void sceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode)
{
rebuildMeshes();
}

static void onPlayModeChange(PlayModeStateChange playMode)
{
if (playMode == PlayModeStateChange.EnteredEditMode)
{
UnityEngine.SceneManagement.SceneManager.sceneLoaded -= sceneLoaded;
EditorApplication.playModeStateChanged -= onPlayModeChange;

rebuildMeshes();
}
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using InternalRealtimeCSG;
using RealtimeCSG.Foundation;
using RealtimeCSG.Components;
using UnityEngine.SceneManagement;

namespace RealtimeCSG
{
Expand Down Expand Up @@ -598,7 +599,19 @@ public static bool UpdateMeshes(System.Text.StringBuilder text = null, bool forc
[MenuItem("Edit/Realtime-CSG/Destroy All Helper Surface Meshes In Scene")]
public static void DestroyAllHelperSurfaceCSGMeshes()
{
var allMeshesInScene = UnityEngine.Object.FindObjectsOfType<Mesh>(true);
var allMeshesInScene = new List<Mesh>();
for(int i = 0; i< SceneManager.sceneCount; i++)
{
var s = SceneManager.GetSceneAt(i);
if (s.isLoaded == false)
continue;

foreach (var go in s.GetRootGameObjects())
{
foreach (var filter in go.GetComponentsInChildren<MeshFilter>(true))
allMeshesInScene.Add(filter.sharedMesh);
}
}

// regex matches all possible names for the helper surfaces that we can generate
var nameMatch = new System.Text.RegularExpressions.Regex(
Expand Down