|
|
|
|
|
|
using UIWidgets.rendering; |
|
|
|
using UIWidgets.ui; |
|
|
|
using UIWidgets.widgets; |
|
|
|
using UnityEditor; |
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
|
|
using UnityEditor; |
|
|
|
|
|
|
|
public UIWidgetsEditorWindow() |
|
|
|
{ |
|
|
|
wantsMouseMove = true; |
|
|
|
wantsMouseEnterLeaveWindow = true; |
|
|
|
} |
|
|
|
|
|
|
|
this._windowAdapter = new WindowAdapter(this); |
|
|
|
this._windowAdapter = new EditorWindowAdapter(this); |
|
|
|
} |
|
|
|
|
|
|
|
this._windowAdapter.OnEnable(); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
protected abstract Widget rootWidget(); |
|
|
|
|
|
|
|
public Vector2 size |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return position.size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public double devicePixelRatio |
|
|
|
{ |
|
|
|
get { return EditorGUIUtility.pixelsPerPoint; } |
|
|
|
} |
|
|
|
|
|
|
|
public void scheduleFrame() |
|
|
|
{ |
|
|
|
Repaint(); |
|
|
|
} |
|
|
|
public class WindowAdapter : Window { |
|
|
|
public class EditorWindowAdapter : WindowAdapter |
|
|
|
{ |
|
|
|
|
|
|
|
public readonly EditorWindow editorWindow; |
|
|
|
|
|
|
|
public EditorWindowAdapter(EditorWindow editorWindow) |
|
|
|
{ |
|
|
|
this.editorWindow = editorWindow; |
|
|
|
} |
|
|
|
static readonly List<WindowAdapter> _windowAdapters = new List<WindowAdapter>(); |
|
|
|
public static IEnumerable<WindowAdapter> windowAdapters { |
|
|
|
get { return _windowAdapters; } |
|
|
|
public override void scheduleFrame(bool regenerateLayerTree = true) { |
|
|
|
base.scheduleFrame(regenerateLayerTree); |
|
|
|
editorWindow.Repaint(); |
|
|
|
public WindowAdapter(EditorWindow editorWindow) |
|
|
|
public override GUIContent titleContent |
|
|
|
this.editorWindow = editorWindow; |
|
|
|
this.editorWindow.wantsMouseMove = true; |
|
|
|
this.editorWindow.wantsMouseEnterLeaveWindow = true; |
|
|
|
get { return editorWindow.titleContent; } |
|
|
|
} |
|
|
|
|
|
|
|
protected override double queryDevicePixelRatio() |
|
|
|
{ |
|
|
|
return EditorGUIUtility.pixelsPerPoint; |
|
|
|
} |
|
|
|
protected override Vector2 queryWindowSize() |
|
|
|
{ |
|
|
|
return editorWindow.position.size; |
|
|
|
} |
|
|
|
public readonly EditorWindow editorWindow; |
|
|
|
#endif
|
|
|
|
|
|
|
|
public abstract class WindowAdapter : Window { |
|
|
|
|
|
|
|
static readonly List<WindowAdapter> _windowAdapters = new List<WindowAdapter>(); |
|
|
|
public static IEnumerable<WindowAdapter> windowAdapters { |
|
|
|
get { return _windowAdapters; } |
|
|
|
} |
|
|
|
|
|
|
|
public WidgetInspectorService widgetInspectorService |
|
|
|
{ |
|
|
|
|
|
|
Surface _surface; |
|
|
|
|
|
|
|
bool _alive; |
|
|
|
|
|
|
|
|
|
|
|
public bool alive |
|
|
|
{ |
|
|
|
|
|
|
public void OnEnable() { |
|
|
|
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint; |
|
|
|
this._lastWindowWidth = this.editorWindow.position.width; |
|
|
|
this._lastWindowHeight = this.editorWindow.position.height; |
|
|
|
this._devicePixelRatio = queryDevicePixelRatio(); |
|
|
|
var size = queryWindowSize(); |
|
|
|
this._lastWindowWidth = size.x; |
|
|
|
this._lastWindowHeight =size.y; |
|
|
|
this._physicalSize = new Size( |
|
|
|
this._lastWindowWidth * this._devicePixelRatio, |
|
|
|
this._lastWindowHeight * this._devicePixelRatio); |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void PostPointerEvent(List<PointerData> data) |
|
|
|
{ |
|
|
|
WithBinding(() => |
|
|
|
{ |
|
|
|
this.onPointerEvent(new PointerDataPacket(data)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void PostPointerEvent(PointerData data) |
|
|
|
{ |
|
|
|
PostPointerEvent(new List<PointerData>(){data}); |
|
|
|
} |
|
|
|
|
|
|
|
public void WithBinding(Action fn) { |
|
|
|
using (this.getScope()) { |
|
|
|
fn(); |
|
|
|
|
|
|
dirty = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (this._lastWindowWidth != this.editorWindow.position.width |
|
|
|
|| this._lastWindowHeight != this.editorWindow.position.height) { |
|
|
|
var size = queryWindowSize(); |
|
|
|
if (this._lastWindowWidth != size.x |
|
|
|
|| this._lastWindowHeight != size.y) { |
|
|
|
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint; |
|
|
|
this._lastWindowWidth = this.editorWindow.position.width; |
|
|
|
this._lastWindowHeight = this.editorWindow.position.height; |
|
|
|
this._devicePixelRatio = queryDevicePixelRatio(); |
|
|
|
this._lastWindowWidth = size.x; |
|
|
|
this._lastWindowHeight = size.y; |
|
|
|
this._physicalSize = new Size( |
|
|
|
this._lastWindowWidth * this._devicePixelRatio, |
|
|
|
this._lastWindowHeight * this._devicePixelRatio); |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public virtual GUIContent titleContent |
|
|
|
{ |
|
|
|
get { return null; } |
|
|
|
} |
|
|
|
|
|
|
|
protected abstract double queryDevicePixelRatio(); |
|
|
|
protected abstract Vector2 queryWindowSize(); |
|
|
|
|
|
|
|
|
|
|
|
void _beginFrame() { |
|
|
|
if (this.onBeginFrame != null) { |
|
|
|
this.onBeginFrame(new DateTime(Stopwatch.GetTimestamp()) - this._epoch); |
|
|
|
|
|
|
public override void scheduleFrame(bool regenerateLayerTree = true) { |
|
|
|
if (regenerateLayerTree) { |
|
|
|
this._regenerateLayerTree = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.editorWindow != null) { |
|
|
|
this.editorWindow.Repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|