This repository was archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOverlayWindowContainer.cs
More file actions
47 lines (42 loc) · 1.53 KB
/
Copy pathOverlayWindowContainer.cs
File metadata and controls
47 lines (42 loc) · 1.53 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
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Plugins.Editor
{
/// <summary>
/// Allow to draw stacked floating <see cref="EditorWindow"/> in <see cref="SceneView"/>, similar to <see cref="ParticleSystem"/>
/// <br/><br/>HOW TO:
/// <br/>create instance of <see cref="OverlayWindowContainer"/>
/// <br/>call <see cref="OverlayWindowContainer.OnGUI"/> from any your OnGUI function
/// </summary>
public class OverlayWindowContainer
{
private object Window;
private MethodInfo _onGUIMethod;
public delegate void WindowFunction(Object target, SceneView sceneView);
public void OnGUI() => _onGUIMethod.Invoke(null, new[] { Window });
public OverlayWindowContainer(
GUIContent title,
WindowFunction guiFunction,
int primaryOrder,
UnityEngine.Object target,
WindowDisplayOption option)
{
Assembly assembly = typeof(UnityEditor.Editor).Assembly;
var overlayType = assembly.GetType("UnityEditor.SceneViewOverlay");
Type delegateType = overlayType.GetNestedType("WindowFunction");
Delegate deleg = Delegate.CreateDelegate(delegateType, target, guiFunction.Method);
ConstructorInfo constructor = assembly.GetType("UnityEditor.OverlayWindow").GetConstructors()[0];
Window = constructor.Invoke(new object[] { title, deleg, primaryOrder, target, (int)option });
_onGUIMethod = overlayType.GetMethod("ShowWindow");
}
public enum WindowDisplayOption
{
MultipleWindowsPerTarget,
OneWindowPerTarget,
OneWindowPerTitle,
}
}
}