Add main mesh fixes

This commit is contained in:
Toomas Tamm
2021-02-23 02:13:14 +02:00
parent c89f326c37
commit 989424e659
139 changed files with 8101 additions and 2033 deletions

View File

@@ -0,0 +1,94 @@
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace Asset_Cleaner {
class AufWindow : EditorWindow {
[SerializeField] PersistentUndoRedoState _persistentUndo;
[MenuItem("Window/- Asset Cleaner %L")]
static void OpenActiveWindow() {
GetWindow<AufWindow>();
}
// restore window state after recompilation
void OnEnable() {
var wd = Globals<WindowData>.Value = new WindowData();
wd.Window = this;
var firstTime = _persistentUndo == null;
Globals<PersistentUndoRedoState>.Value = _persistentUndo ?? new PersistentUndoRedoState();
Globals<BacklinkStore>.Value = new BacklinkStore();
var config = Globals<Config>.Value = new Config();
PersistenceUtils.Load(ref config);
if (firstTime || !config.RebuildCacheOnDemand)
Globals<BacklinkStore>.Value.Init();
EditorApplication.update += Upd;
EditorApplication.projectWindowItemOnGUI += ProjectViewGui.OnProjectWindowItemOnGui;
AufCtx.TryInitWorld();
// need to close window in case of Asset Cleaner uninstalled
if (!CleanerStyleAsset.Style.TryFindSelf(out wd.Style))
ForceClose();
}
void OnGUI() {
var store = Globals<BacklinkStore>.Value;
if (!store.Initialized) {
// prevent further window GUI rendering
if (!GUILayout.Button("Initialize Cache")) return;
var stopwatch = new Stopwatch();
stopwatch.Start();
store.Init();
stopwatch.Stop();
Globals<Config>.Value.InitializationTime = $"Initialized in {stopwatch.Elapsed.TotalSeconds:N} s";
AufCtx.World.NewEntityWith(out RequestRepaintEvt _);
}
AufCtx.OnGuiGroup.Run();
}
static void Upd() {
if (AufCtx.World == null) {
AufCtx.DestroyWorld();
return;
}
if (!Globals<BacklinkStore>.Value.Initialized) return;
AufCtx.UpdateGroup.Run();
}
bool _closing;
void ForceClose() {
if (_closing) return;
_closing = true;
Close();
EditorWindow.DestroyImmediate(this);
}
void OnDisable() {
if (AufCtx.Destroyed) return;
_persistentUndo = Globals<PersistentUndoRedoState>.Value;
AufCtx.UpdateGroup.Destroy();
AufCtx.OnGuiGroup.Destroy();
AufCtx.DestroyWorld();
Globals<Config>.Value = default;
Globals<PersistentUndoRedoState>.Value = default;
Globals<WindowData>.Value = default;
EditorApplication.update -= Upd;
EditorApplication.projectWindowItemOnGUI -= ProjectViewGui.OnProjectWindowItemOnGui;
// need to close window in case of Asset Cleaner uninstalled
if (!CleanerStyleAsset.Style.TryFindSelf(out _))
ForceClose();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 44ebd7bbb2bb41b4ba0187901e8d583f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using UnityEditor;
namespace Asset_Cleaner {
class ProcessAllAssets : AssetPostprocessor {
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {
if (!AufCtx.InitStarted) return;
if (!Globals<BacklinkStore>.Value.Initialized) return;
var store = Globals<BacklinkStore>.Value;
var length = movedAssets.Length;
for (var i = 0; i < length; i++)
store.Replace(movedFromAssetPaths[i], movedAssets[i]);
foreach (var path in deletedAssets)
store.Remove(path);
foreach (var path in importedAssets)
store.RebuildFor(path, true);
store.UpdateUnusedAssets();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 17c1f845fa88d38448c4cf65e9745f30
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
using UnityEditor;
using UnityEngine;
namespace Asset_Cleaner {
static class ProjectViewGui {
static CleanerStyleAsset.Style _style = Globals<WindowData>.Value.Style;
public static void OnProjectWindowItemOnGui(string guid, Rect rect) {
if (!Globals<Config>.Value.MarkRed) return;
var store = Globals<BacklinkStore>.Value;
if (!store.Initialized) return;
var path = AssetDatabase.GUIDToAssetPath(guid);
ShowRowQuantity(rect, path, store);
long size = 0;
var _ = store.UnusedFiles.TryGetValue(path, out size) || store.UnusedScenes.TryGetValue(path, out size);
if (SearchUtils.IsUnused(path)) {
var buf = GUI.color;
{
GUI.color = _style.RedHighlight;
GUI.Box(rect, string.Empty);
}
GUI.color = buf;
GUI.Label(rect, CommonUtils.BytesToString(size), _style.ProjectViewCounterLabel);
}
}
static void ShowRowQuantity(Rect rect, string path, BacklinkStore backlinkStore) {
if (!AssetDatabase.IsValidFolder(path))
return;
backlinkStore.FoldersWithQty.TryGetValue(path, out var folderWithQty);
var cntFiles = folderWithQty?.UnusedFilesQty ?? 0;
var cntScenes = folderWithQty?.UnusedScenesQty ?? 0;
long size = folderWithQty?.UnusedSize ?? 0;
if (cntFiles == 0 && cntScenes == 0) return;
var countStr = cntFiles + cntScenes > 0 ? $"{cntFiles} | {cntScenes} ({CommonUtils.BytesToString(size)})" : "";
GUI.Label(rect, countStr, _style.ProjectViewCounterLabel);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a17718cc645348b0bc4ed6d7e514ab30
timeCreated: 1589032770