-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathVFXViewControllerExpressions.cs
More file actions
112 lines (96 loc) · 3.79 KB
/
Copy pathVFXViewControllerExpressions.cs
File metadata and controls
112 lines (96 loc) · 3.79 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
using System;
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEditor.VFX;
using UnityEngine;
using UnityEngine.Profiling;
using Object = UnityEngine.Object;
using UnityEngine.UIElements;
namespace UnityEditor.VFX.UI
{
class VFXRecompileEvent : ControllerEvent
{
public bool valueOnly { get; set; }
public static VFXRecompileEvent Default = new VFXRecompileEvent();
public VFXViewController controller = null;
}
partial class VFXViewController : Controller<VisualEffectResource>
{
public void RecompileExpressionGraphIfNeeded()
{
if (!ExpressionGraphDirty)
return;
ExpressionGraphDirty = false;
try
{
CreateExpressionContext(true /*cause == VFXModel.InvalidationCause.kStructureChanged || cause == VFXModel.InvalidationCause.kConnectionChanged*/);
m_ExpressionContext.Recompile();
}
catch (Exception e)
{
Debug.LogException(e);
}
VFXRecompileEvent.Default.valueOnly = ExpressionGraphDirtyParamOnly;
SendEvent(VFXRecompileEvent.Default);
}
public void InvalidateExpressionGraph(VFXModel model, VFXModel.InvalidationCause cause)
{
if (cause != VFXModel.InvalidationCause.kStructureChanged &&
cause != VFXModel.InvalidationCause.kExpressionInvalidated &&
cause != VFXModel.InvalidationCause.kParamChanged &&
cause != VFXModel.InvalidationCause.kExpressionValueInvalidated &&
cause != VFXModel.InvalidationCause.kEnableChanged)
{
ExpressionGraphDirtyParamOnly = false;
return;
}
ExpressionGraphDirty = true;
ExpressionGraphDirtyParamOnly = cause == VFXModel.InvalidationCause.kParamChanged || cause == VFXModel.InvalidationCause.kExpressionValueInvalidated;
}
private void CreateExpressionContext(bool forceRecreation)
{
if (!forceRecreation && m_ExpressionContext != null)
return;
m_ExpressionContext = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
var currentObjects = new HashSet<ScriptableObject>();
graph.CollectDependencies(currentObjects);
int nbExpr = 0;
foreach (var o in currentObjects)
{
if (o is VFXSlot)
{
var exp = ((VFXSlot)o).GetExpression();
if (exp != null)
{
m_ExpressionContext.RegisterExpression(exp);
++nbExpr;
}
}
}
}
public bool CanGetEvaluatedContent(VFXSlot slot)
{
if (m_ExpressionContext == null)
return false;
if (slot.GetExpression() == null)
return false;
Profiler.BeginSample("CanGetEvaluatedContent");
var reduced = m_ExpressionContext.GetReduced(slot.GetExpression());
var result = reduced != null && reduced.Is(VFXExpression.Flags.Value);
Profiler.EndSample();
return result;
}
public object GetEvaluatedContent(VFXSlot slot)
{
if (!CanGetEvaluatedContent(slot))
return null;
var reduced = m_ExpressionContext.GetReduced(slot.GetExpression());
var result = reduced.GetContent();
return result;
}
private VFXExpression.Context m_ExpressionContext;
[NonSerialized]
private bool ExpressionGraphDirty = true;
private bool ExpressionGraphDirtyParamOnly = false;
}
}