Skip to content

Commit

Permalink
Upgrade package to 2022.2 + (#13)
Browse files Browse the repository at this point in the history
* [VFX] Base code upgrade for multiview (not functional atm : debug stats broken)

* Made multiview functional (data storage is now per-window, preferences are per-asset)

* Fixes for navigator in Multi View

* Upgraded Assets

* Updated Assets / Subgraphs to 2022.2

* Bump Package Version to 2022.2.0

* Update versions in Readme
  • Loading branch information
peeweek authored Nov 11, 2022
1 parent ca5746e commit 11c3405
Show file tree
Hide file tree
Showing 35 changed files with 3,985 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ VisualEffectResource:
m_PreWarmDeltaTime: 0.05
m_PreWarmStepCount: 0
m_InitialEventName: OnPlay
m_InstancingMode: -1
m_InstancingCapacity: 64
--- !u!114 &114350483966674976
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -78,7 +80,7 @@ MonoBehaviour:
enumValues: []
descendantCount: 0
m_ImportDependencies: []
m_GraphVersion: 9
m_GraphVersion: 11
m_ResourceVersion: 1
m_SubgraphDependencies:
- {fileID: 5371698745253816930, guid: 11a2d0a6e693e7248b7df41a4ecd150b, type: 3}
Expand Down Expand Up @@ -181,6 +183,7 @@ MonoBehaviour:
- {fileID: 114350483966674981}
m_OutputSlots: []
m_Disabled: 0
m_ActivationSlot: {fileID: 114350483966675183}
attribute: position
Composition: 0
Source: 0
Expand Down Expand Up @@ -626,7 +629,8 @@ MonoBehaviour:
- {fileID: 114350483966675182}
m_OutputSlots:
- {fileID: 114350483966675176}
m_Subgraph: {fileID: 5371698745253816930, guid: 11a2d0a6e693e7248b7df41a4ecd150b, type: 3}
m_Subgraph: {fileID: 5371698745253816930, guid: 11a2d0a6e693e7248b7df41a4ecd150b,
type: 3}
--- !u!114 &114350483966675171
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1051,3 +1055,37 @@ MonoBehaviour:
m_Direction: 0
m_LinkedSlots:
- {fileID: 114350483966675181}
--- !u!114 &114350483966675183
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b4c11ff25089a324daf359f4b0629b33, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UIIgnoredErrors: []
m_Parent: {fileID: 0}
m_Children: []
m_UIPosition: {x: 0, y: 0}
m_UICollapsed: 1
m_UISuperCollapsed: 0
m_MasterSlot: {fileID: 114350483966675183}
m_MasterData:
m_Owner: {fileID: 114350483966674980}
m_Value:
m_Type:
m_SerializableType: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
m_SerializableObject: True
m_Space: 2147483647
m_Property:
name: _vfx_enabled
m_serializedType:
m_SerializableType: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
m_Direction: 0
m_LinkedSlots: []
5 changes: 1 addition & 4 deletions Editor/Debug/VFXDebugEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,7 @@ private void OnGUI()
r.xMin = r.xMax; r.width = 40;
if (GUI.Button(r, "Edit", Styles.toolbarButton))
{
if (VFXViewWindow.currentWindow == null)
GetWindow<VFXViewWindow>();

VFXViewWindow.currentWindow.LoadAsset(entry.asset, entry.component);
VFXViewWindow.GetWindow(entry.asset, true);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions Editor/Gallery/VFXGraphGalleryWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ enum WindowMode
bool debug = false;
Vector2 addPosition;

public static void OpenWindowCreateAsset(string outPath)
internal static void OpenWindowCreateAsset(string outPath)
{
var window = GetWindow<VFXGraphGalleryWindow>(true, "Create New VFX Asset", true);
window.outPath = outPath;
window.mode = WindowMode.CreateAsset;
}

public static void OpenWindowAddTemplate(Vector2 addPosition)
internal static void OpenWindowAddTemplate(Vector2 addPosition, VFXViewWindow vfxWindow)
{
var window = GetWindow<VFXGraphGalleryWindow>(true, $"Create New System from Template", true);
window.mode = WindowMode.AddNode;
window.addPosition = addPosition;
vfxInvokingWindow = vfxWindow;
}

private void OnEnable()
Expand All @@ -51,7 +52,7 @@ void SetTitle(string title)
Vector2 scroll;
Vector2 scrollDesc;


static VFXViewWindow vfxInvokingWindow;
List<VFXGraphGalleryTemplate> categories;

VFXGraphGalleryTemplate.Template selected;
Expand All @@ -71,7 +72,6 @@ bool createGameObject
}
}


void UpdateTemplates()
{
if (categories == null)
Expand Down Expand Up @@ -251,7 +251,8 @@ private void OnGUI()

if (GUILayout.Button("Add System", GUILayout.Width(100), GUILayout.Height(22)) || pressedReturn)
{
VFXViewWindow.currentWindow.graphView.CreateTemplateSystem(AssetDatabase.GetAssetPath(selectedSource), addPosition, null);
vfxInvokingWindow.graphView.CreateTemplateSystem(AssetDatabase.GetAssetPath(selectedSource), addPosition, null);
vfxInvokingWindow = null;
Close();
}
EditorGUI.EndDisabledGroup();
Expand Down
2 changes: 1 addition & 1 deletion Editor/Navigator/VFXNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void ReloadNavigator()
needReloadNavigator = false;
}

class VFXNavigatorTreeView : TreeView
class VFXNavigatorTreeView : IMGUI.Controls.TreeView
{
VFXViewWindow m_Window;
VFXView m_VFXView;
Expand Down
110 changes: 67 additions & 43 deletions Extension/VFXGraphExtension.DebugView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@

static partial class VFXGraphExtension //.DebugView
{
static bool debugInfoVisible
static bool GetDebugInfoVisible(VisualEffectAsset asset)
{
get { return EditorPrefs.GetBool("VFXGraphExtension.debugInfoVisible", true); }
set { EditorPrefs.SetBool("VFXGraphExtension.debugInfoVisible", value); }
return EditorPrefs.GetBool($"VFXGraphExtension.debugInfoVisible.{asset.name}", true);
}

static void SetDebugInfoVisible(VisualEffectAsset asset, bool visible)
{
EditorPrefs.SetBool($"VFXGraphExtension.debugInfoVisible.{asset.name}", visible);
}

static List<SpawnerDebugInfo> spawnersToDelete = new List<SpawnerDebugInfo>();
Expand Down Expand Up @@ -55,40 +59,60 @@ struct SystemDebugInfo
public Label memoryLabel;
}

static List<SpawnerDebugInfo> spawnerDebugInfos;
static List<SystemDebugInfo> systemDebugInfos;
static Dictionary<VFXViewWindow, List<SpawnerDebugInfo>> spawnerDebugInfos;
static Dictionary<VFXViewWindow, List<SystemDebugInfo>> systemDebugInfos;
static Dictionary<VFXViewWindow, VisualEffectAsset> currentVisualEffectAsset;

static Dictionary<VisualEffectAsset, List<string>> systemNames = new Dictionary<VisualEffectAsset, List<string>>();
static Dictionary<VisualEffectAsset, List<string>> spawnerNames = new Dictionary<VisualEffectAsset, List<string>>();

static void ToggleSpawnerStats()
static void ToggleSpawnerStats(object wnd)
{
debugInfoVisible = !debugInfoVisible;
UpdateStatsUIElements();
VFXViewWindow window = (VFXViewWindow)wnd;
var asset = window.displayedResource.asset;

if(asset != null)
{
bool visible = !GetDebugInfoVisible(asset);
SetDebugInfoVisible(asset, visible);
UpdateStatsUIElements(window);
}
}

static void UpdateStatsUIElements()
static void UpdateStatsUIElements(VFXViewWindow window)
{
var wnd = VFXViewWindow.currentWindow;
if (wnd == null)
if (window == null)
return;

var gv = wnd.graphView;
var gv = window.graphView;
if (gv == null || gv.controller == null || gv.controller.model == null)
return;

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

if (systemDebugInfos == null)
systemDebugInfos = new List<SystemDebugInfo>();
systemDebugInfos = new Dictionary<VFXViewWindow, List<SystemDebugInfo>>();

if (currentVisualEffectAsset == null)
currentVisualEffectAsset = new Dictionary<VFXViewWindow, VisualEffectAsset>();

// Check if asset changed
VisualEffectAsset currentAsset = VFXViewWindow.currentWindow.graphView.controller.model.asset;
VisualEffectAsset currentAsset = window.graphView.controller.model.asset;

if (currentAsset != m_CurrentVisualEffectAsset)
// If window was not registered, register it
if(!currentVisualEffectAsset.ContainsKey(window))
{
spawnerDebugInfos.Clear();
systemDebugInfos.Clear();
m_CurrentVisualEffectAsset = currentAsset;
currentVisualEffectAsset.Add(window, currentAsset);
spawnerDebugInfos.Add(window, new List<SpawnerDebugInfo>());
systemDebugInfos.Add(window, new List<SystemDebugInfo>());
}

if (currentAsset != currentVisualEffectAsset[window])
{
spawnerDebugInfos[window].Clear();
systemDebugInfos[window].Clear();
currentVisualEffectAsset[window] = currentAsset;
}

gv.Query<VFXContextUI>().Build().ForEach((context) =>
Expand All @@ -97,7 +121,7 @@ static void UpdateStatsUIElements()
{
string name = context.Q<Label>("user-label").text;

if (spawnerDebugInfos.Any(o => o.ui == context))
if (spawnerDebugInfos[window].Any(o => o.ui == context))
return;

SpawnerDebugInfo info = new SpawnerDebugInfo();
Expand Down Expand Up @@ -223,14 +247,14 @@ static void UpdateStatsUIElements()
info.debugPanel = panel;
info.evtAttribute = evtAttribute;

spawnerDebugInfos.Add(info);
spawnerDebugInfos[window].Add(info);
}

info.debugPanel = panel;
}
else if (context.ClassListContains("init"))
{
if (systemDebugInfos.Any(o => o.ui == context))
if (systemDebugInfos[window].Any(o => o.ui == context))
return;

var model = context.controller.model;
Expand Down Expand Up @@ -343,29 +367,29 @@ static void UpdateStatsUIElements()
info.countLabel = countLabel;
info.progress = progress;

systemDebugInfos.Add(info);
systemDebugInfos[window].Add(info);
}
}
});
}

static VisualEffectAsset m_CurrentVisualEffectAsset;
static List<string> m_SystemNames = new List<string>();
static List<string> m_SpawnerNames = new List<string>();

static void UpdateDebugInfo()
static void UpdateDebugInfo(VFXViewWindow window)
{
if (spawnerDebugInfos == null || systemDebugInfos == null)
return;

VisualEffect vfx = VFXViewWindow.currentWindow.graphView.attachedComponent;
VisualEffect vfx = window.graphView.attachedComponent;
VisualEffectAsset asset = window.displayedResource.asset;

if (m_SystemNames == null)
m_SystemNames = new List<string>();
if (m_SpawnerNames == null)
m_SpawnerNames = new List<string>();
if (!systemNames.ContainsKey(asset))
systemNames.Add(asset, new List<string>());
if (!spawnerNames.ContainsKey(asset))
spawnerNames.Add(asset, new List<string>());

foreach (var debugInfo in spawnerDebugInfos)
bool debugInfoVisible = GetDebugInfoVisible(asset);

foreach (var debugInfo in spawnerDebugInfos[window])
{
debugInfo.debugPanel.visible = debugInfoVisible;
if (!debugInfoVisible)
Expand All @@ -390,8 +414,9 @@ static void UpdateDebugInfo()
}

debugInfo.ResyncName();
vfx.GetSpawnSystemNames(m_SpawnerNames);
if (!m_SpawnerNames.Contains(debugInfo.name))

vfx.GetSpawnSystemNames(spawnerNames[asset]);
if (!spawnerNames[asset].Contains(debugInfo.name))
continue;

var spawnerInfo = vfx.GetSpawnSystemInfo(debugInfo.name);
Expand Down Expand Up @@ -531,12 +556,11 @@ static void UpdateDebugInfo()
}

foreach (var info in spawnersToDelete)
spawnerDebugInfos.Remove(info);
spawnerDebugInfos[window].Remove(info);

spawnersToDelete.Clear();


foreach (var systemInfo in systemDebugInfos)
foreach (var systemInfo in systemDebugInfos[window])
{
systemInfo.panel.visible = debugInfoVisible;
if (!debugInfoVisible)
Expand Down Expand Up @@ -568,15 +592,15 @@ static void UpdateDebugInfo()

if (vfx != null) // attached
{
vfx.GetSystemNames(m_SystemNames);
if (!m_SystemNames.Contains(systemName))
vfx.GetSystemNames(systemNames[asset]);
if (!systemNames[asset].Contains(systemName))
continue;

var vfxSystemInfo = vfx.GetParticleSystemInfo(systemName);
uint aliveCount = vfxSystemInfo.aliveCount;
float t = (float)aliveCount / capacity;
float t = (float)Mathf.Min(aliveCount,capacity)/ capacity;
systemInfo.countLabel.text = $"{vfxSystemInfo.aliveCount.ToString("N0")} / {capacity.ToString("N0")}";
systemInfo.progress.style.width = t * 240;
systemInfo.progress.style.width = Mathf.Clamp01(t) * 240;

if (t > 0.75f)
systemInfo.progress.style.backgroundColor = Styles.sysInfoGreen;
Expand Down Expand Up @@ -628,7 +652,7 @@ static void UpdateDebugInfo()
}

foreach (var info in systemsToDelete)
systemDebugInfos.Remove(info);
systemDebugInfos[window].Remove(info);

systemsToDelete.Clear();

Expand Down
4 changes: 2 additions & 2 deletions Extension/VFXGraphExtension.Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void CreateNavigatorIfRequired(VFXViewWindow window)
{
if (!navigators.ContainsKey(window))
{
navigators.Add(window, new VFXNavigator(VFXViewWindow.currentWindow, NavigatorLoadPosition()));
navigators.Add(window, new VFXNavigator(window, NavigatorLoadPosition()));
navigatorVisibility.Add(window, GetNavigatorVisible(window));
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ static void SetNavigatorVisible(VFXViewWindow window, bool visible)
{
CreateNavigatorIfRequired(window);

var gv = VFXViewWindow.currentWindow.graphView;
var gv = window.graphView;
var navigator = navigators[window];
if (visible)
{
Expand Down
Loading

0 comments on commit 11c3405

Please sign in to comment.