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

Shortcuts #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Editor/Extension/VFXGraphExtension.Shortcuts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using UnityEditor.VFX.UI;
using UnityEditor;
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEditor.VFX;
using UnityEngine.VFX;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Profiling;
using System.Text;
using System.Reflection;

static partial class VFXGraphExtension
{
static Dictionary<Event, ShortcutDelegate> ClearAndGetShortcuts(VFXViewWindow window)
{
FieldInfo sh_info = typeof(VFXViewWindow).GetField("m_ShortcutHandler", BindingFlags.NonPublic | BindingFlags.Instance);
ShortcutHandler current = sh_info.GetValue(window) as ShortcutHandler;

FieldInfo dict_info = typeof(ShortcutHandler).GetField("m_Dictionary", BindingFlags.NonPublic | BindingFlags.Instance);
Dictionary<Event, ShortcutDelegate> dict = dict_info.GetValue(current) as Dictionary<Event, ShortcutDelegate>;
dict.Clear();
return dict;
}

static bool shortcuts_initialized = false;

static void InitializeShortcuts(VFXViewWindow window)
{
if (shortcuts_initialized)
return;

UpdateShortcuts(window);
shortcuts_initialized = true;
}

static void UpdateShortcuts(object wnd)
{
VFXViewWindow window = wnd as VFXViewWindow;
Dictionary<Event, ShortcutDelegate> shortcuts = ClearAndGetShortcuts(window);
shortcuts.Add(Event.KeyboardEvent("F7"), toto);
window.graphView.isReframable = false;

}

static EventPropagation toto()
{
Debug.Log("AAA");
return EventPropagation.Stop;
}
}
11 changes: 11 additions & 0 deletions Editor/Extension/VFXGraphExtension.Shortcuts.cs.meta

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

21 changes: 12 additions & 9 deletions Editor/Extension/VFXGraphExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using UnityEngine.Profiling;
using System.Text;

static class VFXGraphExtension
static partial class VFXGraphExtension
{
[InitializeOnLoadMethod]
static void InitializeExtension()
Expand Down Expand Up @@ -40,6 +40,9 @@ static void Update()
Profiler.BeginSample("VFXGraphExtension.UpdateDebugInfo");
UpdateDebugInfo();
Profiler.EndSample();

InitializeShortcuts(window);

}


Expand All @@ -63,7 +66,7 @@ static void UpdateDebugInfo()
{
debugInfo.debugPanel.visible = spawnerDebugInfoVisible;
if (!spawnerDebugInfoVisible)
return;
continue;

if(vfx == null)
{
Expand Down Expand Up @@ -238,12 +241,14 @@ static void UpdateDebugInfo()

static void OnKeyDown(KeyDownEvent e)
{
if(e.keyCode == KeyCode.T)
if(e.keyCode == KeyCode.Space && e.ctrlKey)
{
var wnd = VFXViewWindow.currentWindow;
Vector2 pos = e.originalMousePosition;
pos = wnd.graphView.ChangeCoordinatesTo(wnd.graphView.contentViewContainer, pos);
OpenAddCreateWindow(pos);
e.StopPropagation();
e.StopImmediatePropagation();
}
}

Expand Down Expand Up @@ -282,6 +287,7 @@ public void ResyncName()
}
}
}

static List<SpawnerDebugInfo> spawnerDebugInfos;

static void ToggleSpawnerStats()
Expand All @@ -300,7 +306,6 @@ static void UpdateStatsUI()
if (gv == null)
return;


if (spawnerDebugInfos == null)
spawnerDebugInfos = new List<SpawnerDebugInfo>();

Expand Down Expand Up @@ -441,10 +446,6 @@ static void UpdateStatsUI()
spawnerDebugInfos.Add(info);
}

info.debugPanel = panel;



});
}

Expand Down Expand Up @@ -502,11 +503,13 @@ void OnClick()
}
else
{
m.AddItem(new GUIContent("Add System from Template... (T)"), false, OpenAddCreateWindowScreenCenter);
m.AddItem(new GUIContent("Add System from Template... (Ctrl+Space)"), false, OpenAddCreateWindowScreenCenter);
m.AddSeparator("");
m.AddItem(new GUIContent("Create Game Object and Attach"), false, CreateGameObjectAndAttach);
m.AddItem(new GUIContent("Show Spawner Stats"), spawnerDebugInfoVisible, ToggleSpawnerStats);
m.AddItem(new GUIContent("Update Shortcuts"), false, UpdateShortcuts, VFXViewWindow.currentWindow);
m.ShowAsContext();

}

}
Expand Down