-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathExternalForcesModuleUI.cs
More file actions
151 lines (131 loc) · 6.7 KB
/
Copy pathExternalForcesModuleUI.cs
File metadata and controls
151 lines (131 loc) · 6.7 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEditorInternal;
using UnityEngine;
using Unity.Scripting.LifecycleManagement;
namespace UnityEditor
{
class ExternalForcesModuleUI : ModuleUI
{
SerializedMinMaxCurve m_Multiplier;
SerializedProperty m_InfluenceFilter;
SerializedProperty m_InfluenceMask;
SerializedProperty m_InfluenceList;
ReorderableList m_InfluenceListView;
class Texts
{
public GUIContent multiplier = EditorGUIUtility.TrTextContent("Multiplier", "Used to scale the force applied to this Particle System. If you use a curve to set this value, the Particle System applies the curve over the lifetime of each particle.");
public GUIContent influenceFilter = EditorGUIUtility.TrTextContent("Influence Filter", "Use either a LayerMask or a List, to decide which Force Fields affect this Particle System.");
public GUIContent influenceMask = EditorGUIUtility.TrTextContent("Influence Mask", "Select a global mask of which GameObjects can affect this Particle System.");
public GUIContent createForceField = EditorGUIUtility.TrTextContent("", "Create a GameObject containing a Particle System Force Field and assign it to the list.");
public GUIContent[] influenceFilters = new GUIContent[]
{
EditorGUIUtility.TrTextContent("Layer Mask"),
EditorGUIUtility.TrTextContent("List"),
EditorGUIUtility.TrTextContent("Layer Mask and List")
};
}
[NoAutoStaticsCleanup] // lazy-initialized UI text cache
static Texts s_Texts;
public ExternalForcesModuleUI(ParticleSystemUI owner, SerializedObject o, string displayName)
: base(owner, o, "ExternalForcesModule", displayName)
{
m_ToolTip = "Controls the wind zones that each particle is affected by.";
}
protected override void Init()
{
// Already initialized?
if (m_Multiplier != null)
return;
if (s_Texts == null)
s_Texts = new Texts();
m_Multiplier = new SerializedMinMaxCurve(this, s_Texts.multiplier, "multiplierCurve");
m_InfluenceFilter = GetProperty("influenceFilter");
m_InfluenceMask = GetProperty("influenceMask");
m_InfluenceList = GetProperty("influenceList");
m_InfluenceListView = new ReorderableList(serializedObject, m_InfluenceList, true, true, true, true);
m_InfluenceListView.elementHeight = kReorderableListElementHeight;
m_InfluenceListView.headerHeight = 0;
m_InfluenceListView.drawElementCallback = DrawInfluenceListElementCallback;
m_InfluenceListView.onAddCallback = OnAddForceFieldElementCallback;
}
override public void OnInspectorGUI(InitialModuleUI initial)
{
GUIMinMaxCurve(s_Texts.multiplier, m_Multiplier);
ParticleSystemGameObjectFilter filter = (ParticleSystemGameObjectFilter)GUIPopup(s_Texts.influenceFilter, m_InfluenceFilter, s_Texts.influenceFilters);
if (m_InfluenceFilter.hasMultipleDifferentValues)
{
EditorGUILayout.HelpBox("Influence List editing is only available when all selected systems have the same filter type", MessageType.Info, true);
}
else
{
if (filter != ParticleSystemGameObjectFilter.List)
GUILayerMask(s_Texts.influenceMask, m_InfluenceMask);
if (filter != ParticleSystemGameObjectFilter.LayerMask)
m_InfluenceListView.DoLayoutList();
}
}
override public void OnSceneViewGUI()
{
using (new Handles.DrawingScope(Handles.matrix))
{
ParticleSystemForceField[] forceFields = ParticleSystemForceField.FindAll();
foreach (ParticleSystemForceField ff in forceFields)
{
bool valid = false;
foreach (ParticleSystem ps in m_ParticleSystemUI.m_ParticleSystems)
{
if (ps.externalForces.IsAffectedBy(ff))
{
valid = true;
break;
}
}
if (!valid)
continue;
ParticleSystemForceFieldInspector.DrawHandle(ff);
}
}
}
override public void UpdateCullingSupportedString(ref string text)
{
text += "\nExternal Forces module is enabled.";
}
void OnAddForceFieldElementCallback(ReorderableList list)
{
int index = m_InfluenceList.arraySize;
m_InfluenceList.InsertArrayElementAtIndex(index);
m_InfluenceList.GetArrayElementAtIndex(index).objectReferenceValue = null;
}
private void DrawInfluenceListElementCallback(Rect rect, int index, bool isActive, bool isFocused)
{
SerializedProperty forceField = m_InfluenceList.GetArrayElementAtIndex(index);
rect.height = kSingleLineHeight;
Rect objectRect = new Rect(rect.x, rect.y, rect.width - EditorGUI.kSpacing - ParticleSystemStyles.Get().plus.fixedWidth, rect.height);
GUIObject(objectRect, GUIContent.none, forceField, null);
if (forceField.objectReferenceValue == null)
{
Rect buttonRect = new Rect(objectRect.xMax + EditorGUI.kSpacing, rect.y + 4, ParticleSystemStyles.Get().plus.fixedWidth, rect.height);
if (GUI.Button(buttonRect, s_Texts.createForceField, ParticleSystemStyles.Get().plus))
{
GameObject go = CreateDefaultForceField("ForceField " + (index + 1), m_ParticleSystemUI.m_ParticleSystems[0]);
go.transform.localPosition = new Vector3(0, 0, 10 + index); // ensure each force field is not at the same position
forceField.objectReferenceValue = go.GetComponent<ParticleSystemForceField>();
}
}
}
private static GameObject CreateDefaultForceField(string name, ParticleSystem parentOfGameObject)
{
GameObject go = new GameObject(name);
if (go)
{
if (parentOfGameObject)
go.transform.parent = parentOfGameObject.transform;
go.AddComponent<ParticleSystemForceField>();
return go;
}
return null;
}
} // namespace UnityEditor
}