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

Do not call Resources.UnloadUnusedAssets() more than once every 3 mins #1787

Merged
merged 2 commits into from Apr 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Scripts/Game/UserInterface/UserInterfaceWindow.cs
Expand Up @@ -128,7 +128,7 @@ public void CloseWindow()
{
uiManager.PopWindow();
RaiseOnCloseHandler();
Resources.UnloadUnusedAssets();
DaggerfallGC.ThrottledUnloadUnusedAssets();
}

public void PopWindow()
Expand Down
36 changes: 36 additions & 0 deletions Assets/Scripts/Internal/DaggerfallGC.cs
@@ -0,0 +1,36 @@
// Project: Daggerfall Tools For Unity
// Copyright: Copyright (C) 2009-2020 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Source Code: https://github.com/Interkarma/daggerfall-unity
// Original Author: Pango (petchema@concept-micro.com)
// Contributors:
//
// Notes:
//

using System;
using UnityEngine;

namespace DaggerfallWorkshop
{
public static class DaggerfallGC
{
// Min time between two unused assets collections
private const float uuaThrottleDelay = 180f;

private static float uuaTimer = Time.realtimeSinceStartup;

public static void ThrottledUnloadUnusedAssets()
{
if (Time.realtimeSinceStartup >= uuaTimer)
ForcedUnloadUnusedAssets();
}

public static void ForcedUnloadUnusedAssets()
{
Resources.UnloadUnusedAssets();
uuaTimer = Time.realtimeSinceStartup + uuaThrottleDelay;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Internal/DaggerfallGC.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Scripts/Terrain/StreamingWorld.cs
Expand Up @@ -659,7 +659,7 @@ private IEnumerator UpdateTerrains()
if (init)
{
DaggerfallUnity.Instance.MaterialReader.PruneCache();
Resources.UnloadUnusedAssets();
DaggerfallGC.ThrottledUnloadUnusedAssets();
}

// Set terrain neighbours
Expand Down