forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetainedMode.cs
More file actions
159 lines (135 loc) · 6.24 KB
/
Copy pathRetainedMode.cs
File metadata and controls
159 lines (135 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.UIElements;
using UnityEditor.UIElements.Bindings;
using UnityEditor.UIElements.StyleSheets;
using UnityEngine.UIElements;
using UnityEngine.UIElements.StyleSheets;
using UnityEngine.Scripting;
using UnityEngine;
using UnityEngine.Bindings;
using UXMLImporterImpl = UnityEditor.UIElements.UXMLImporterImpl;
namespace UnityEditor
{
[InitializeOnLoad]
[VisibleToOtherModules("UnityEditor.UIBuilderModule")]
class RetainedMode
{
static RetainedMode()
{
UIElementsUtility.s_BeginContainerCallback = OnBeginContainer;
UIElementsUtility.s_EndContainerCallback = OnEndContainer;
Panel.initEditorUpdaterFunc = EditorPanel.InitEditorUpdater;
Panel.loadResourceFunc = StyleSheetResourceUtil.LoadResource;
StylePropertyReader.getCursorIdFunc = UIElementsEditorUtility.GetCursorId;
Panel.TimeSinceStartup = () => (long)(EditorApplication.timeSinceStartup * 1000.0f);
BindingExtensions.bindingImpl = new DefaultSerializedObjectBindingImplementation();
EditorWindowBackendManager.defaultWindowBackend = (model) => model is IEditorWindowModel ? new DefaultEditorWindowBackend() : new DefaultWindowBackend();
}
static void OnBeginContainer(IMGUIContainer c)
{
LocalizedEditorFontManager.LocalizeEditorFonts();
HandleUtility.BeginHandles();
}
static void OnEndContainer(IMGUIContainer c)
{
HandleUtility.EndHandles();
}
[Obsolete("Datawatch usage will be removed", false)]
static void UpdateDataWatch()
{
DataWatchService.sharedInstance.PollNativeData();
}
[RequiredByNativeCode]
static void UpdateSchedulers()
{
#pragma warning disable 612,618, 619
UpdateDataWatch();
#pragma warning restore 612,618, 619
UIEventRegistration.UpdateSchedulers();
}
[RequiredByNativeCode]
static void RequestRepaintForPanels()
{
UIEventRegistration.RequestRepaintForPanels((obj) =>
{
var guiView = obj as GUIView;
if (guiView != null)
guiView.Repaint();
});
}
internal class RetainedModeAssetPostprocessor : AssetPostprocessor
{
private const string k_UxmlExtension = ".uxml";
private const string k_UssExtension = ".uss";
private const string k_UssExtensionGenerated = ".uss.asset"; // for editor_resources project
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
string[] movedFromAssetPaths)
{
// Early exit: no imported or deleted assets.
var uxmlImportedAssets = new HashSet<string>(importedAssets.Where(x => MatchesFileExtension(x, k_UxmlExtension)));
var uxmlDeletedAssets = new HashSet<string>(deletedAssets.Where(x => MatchesFileExtension(x, k_UxmlExtension)));
var ussImportedAssets = new HashSet<string>(importedAssets.Where(x => MatchesFileExtension(x, k_UssExtension) || MatchesFileExtension(x, k_UssExtensionGenerated)));
var ussDeletedAssets = new HashSet<string>(deletedAssets.Where(x => MatchesFileExtension(x, k_UssExtension)));
if (uxmlImportedAssets.Count == 0 && uxmlDeletedAssets.Count == 0 &&
ussImportedAssets.Count == 0 && ussDeletedAssets.Count == 0)
{
return;
}
HashSet<VisualTreeAsset> uxmlModifiedAssets = null;
if (uxmlImportedAssets.Count > 0)
{
UXMLImporterImpl.logger.FinishImport();
// the inline stylesheet cache might get out of date.
// Usually called by the USS importer, which might not get called here
StyleSheetCache.ClearCaches();
uxmlModifiedAssets = new HashSet<VisualTreeAsset>();
foreach (var assetPath in uxmlImportedAssets)
{
VisualTreeAsset asset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(assetPath);
if (asset != null) // Shouldn't be!
{
uxmlModifiedAssets.Add(asset);
}
}
}
HashSet<StyleSheet> ussModifiedAssets = null;
var iterator = UIElementsUtility.GetPanelsIterator();
while (iterator.MoveNext())
{
var panel = iterator.Current.Value;
panel.liveReloadSystem.OnVisualTreeAssetsImported(uxmlModifiedAssets, uxmlDeletedAssets);
// ussModifiedAssets is null but we don't care for those, only deleted ones (that we'll stop tracking).
panel.liveReloadSystem.OnStyleSheetAssetsImported(ussModifiedAssets, ussDeletedAssets);
}
if (ussImportedAssets.Count > 0 || ussDeletedAssets.Count > 0)
{
FlagStyleSheetChange();
}
}
private static bool MatchesFileExtension(string assetPath, string fileExtension)
{
return assetPath.EndsWithIgnoreCaseFast(fileExtension);
}
}
public static void FlagStyleSheetChange()
{
// clear caches that depend on loaded style sheets
StyleSheetCache.ClearCaches();
// for now we don't bother tracking which panel depends on which style sheet
var iterator = UIElementsUtility.GetPanelsIterator();
while (iterator.MoveNext())
{
var panel = iterator.Current.Value;
panel.DirtyStyleSheets();
var guiView = panel.ownerObject as GUIView;
if (guiView != null)
guiView.Repaint();
}
}
}
}