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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/// ProFlares - v1.08 - Copyright 2014-2015 All rights reserved - ProFlares.com
/// <summary>
/// FlareEditorHelper.cs
/// Helper class that contains a number of functions that other Editor Scripts use.
/// </summary>
using UnityEngine;
using UnityEditor;
using System.Collections;
public class FlareEditorHelper : MonoBehaviour {
const int menuPos = 10000;
//public static bool ProFlaresDebugMessages = false;
[MenuItem ("Window/ProFlares/Create Setup",false,menuPos+0)]
static void CreateSetup () {
GameObject rootGO = new GameObject("ProFlareSetup");
rootGO.layer = 8;
GameObject cameraGO = new GameObject("ProFlareCamera");
cameraGO.layer = 8;
Camera camera = cameraGO.AddComponent<Camera>();
cameraGO.transform.parent = rootGO.transform;
camera.clearFlags = CameraClearFlags.Depth;
camera.orthographic = true;
camera.orthographicSize = 1;
camera.farClipPlane = 2;
camera.nearClipPlane = -2;
camera.depth++;
camera.cullingMask = 1 << 8;
GameObject batchGO = new GameObject("ProFlareBatch");
batchGO.layer = 8;
batchGO.transform.parent = cameraGO.transform;
ProFlareBatch batch = batchGO.AddComponent<ProFlareBatch>();
batch.FlareCamera = camera;
GameObject MainCameraGo = GameObject.FindWithTag("MainCamera");
if(MainCameraGo){
#if UNITY_5
batch.GameCamera = MainCameraGo.GetComponent<Camera>();
batch.GameCameraTrans = MainCameraGo.transform;
#else
batch.GameCamera = MainCameraGo.GetComponent<Camera>();
batch.GameCameraTrans = MainCameraGo.transform;
#endif
}
Selection.activeGameObject = batchGO;
}
[MenuItem ("Window/ProFlares/Create Setup On Selected Camera",false,menuPos+0)]
static void CreateSetupOnExisting () {
GameObject cameraGO = null;
Camera camera = null;
if(Selection.activeGameObject){
camera = Selection.activeGameObject.GetComponent<Camera>();
if(camera == null){
Debug.LogError("ProFlares - No Camera Selected");
return;
}else{
cameraGO = Selection.activeGameObject;
}
}else{
Debug.LogError("ProFlares - Nothing Selected");
return;
}
Vector3 worldScale = cameraGO.transform.localScale;
Transform parent = cameraGO.transform.parent;
while (parent != null)
{
worldScale = Vector3.Scale(worldScale,parent.localScale);
parent = parent.parent;
}
// Debug.LogError(worldScale.x + " " + worldScale.y + " " + worldScale.z);
// Debug.LogError(1f/worldScale.x + " " + 1f/worldScale.y + " " + 1f/worldScale.z);
int layerNumber = cameraGO.layer;
GameObject batchGO = new GameObject("ProFlareBatch");
batchGO.layer = layerNumber;
batchGO.transform.parent = cameraGO.transform;
batchGO.transform.localPosition = Vector3.zero;
batchGO.transform.localScale = new Vector3(1f/worldScale.x,1f/worldScale.y,1f/worldScale.z);
ProFlareBatch batch = batchGO.AddComponent<ProFlareBatch>();
batch.FlareCamera = camera;
batch.FlareCameraTrans = camera.transform;
GameObject MainCameraGo = GameObject.FindWithTag("MainCamera");
if(MainCameraGo){
#if UNITY_5
batch.GameCamera = MainCameraGo.GetComponent<Camera>();
batch.GameCameraTrans = MainCameraGo.transform;
#else
batch.GameCamera = MainCameraGo.GetComponent<Camera>();
batch.GameCameraTrans = MainCameraGo.transform;
#endif
}
Selection.activeGameObject = batchGO;
}
[MenuItem ("Window/ProFlares/Create Single Camera Setup On Selected Main Camera",false,menuPos+1)]
static void CreateSetupOnExistingGameCamera () {
GameObject cameraGO = null;
Camera camera = null;
if(Selection.activeGameObject){
camera = Selection.activeGameObject.GetComponent<Camera>();
if(camera == null){
Debug.LogError("ProFlares - No Camera Selected");
return;
}else{
cameraGO = Selection.activeGameObject;
}
}else{
Debug.LogError("ProFlares - Nothing Selected");
return;
}
// Vector3 worldScale = cameraGO.transform.localScale;
// Transform parent = cameraGO.transform.parent;
int layerNumber = cameraGO.layer;
GameObject batchGO = new GameObject("ProFlareBatch");
batchGO.layer = layerNumber;
batchGO.transform.parent = cameraGO.transform;
batchGO.transform.localPosition = Vector3.zero;
batchGO.transform.localRotation = Quaternion.identity;
batchGO.transform.localScale = Vector3.one;
ProFlareBatch batch = batchGO.AddComponent<ProFlareBatch>();
batch.FlareCamera = camera;
batch.GameCamera = camera;
batch.FlareCameraTrans = camera.transform;
batch.mode = ProFlareBatch.Mode.SingleCamera;
batch.SingleCamera_Mode = true;
batch.zPos = 1;
/*
GameObject MainCameraGo = GameObject.FindWithTag("MainCamera");
if(MainCameraGo){
batch.GameCamera = MainCameraGo.camera;
batch.GameCameraTrans = MainCameraGo.transform;
}*/
Selection.activeGameObject = batchGO;
}
[MenuItem ("Window/ProFlares/Create Flare",false,menuPos+12)]
static void CreateFlare () {
GameObject flareGO = new GameObject("Flare");
flareGO.layer = 8;
flareGO.AddComponent<ProFlare>();
Selection.activeGameObject = flareGO;
}
[MenuItem ("Window/ProFlares/Help",false,menuPos+71)]
static void ProFlareHelp () {
Application.OpenURL("http://www.proflares.com/help");
}
public static void DrawGuiInBoxDivider(){
GUILayout.Space(8f);
if (Event.current.type == EventType.Repaint)
{
int extra = 0;
#if UNITY_4_3
extra = 10;
#endif
Texture2D tex = EditorGUIUtility.whiteTexture;
Rect rect = GUILayoutUtility.GetLastRect();
GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.25f);
GUI.DrawTexture(new Rect(5f+extra, rect.yMin + 5f, Screen.width-11, 1f), tex);
GUI.color = Color.white;
}
}
public static void DrawGuiDivider(){
GUILayout.Space(12f);
if (Event.current.type == EventType.Repaint)
{
Texture2D tex = EditorGUIUtility.whiteTexture;
Rect rect = GUILayoutUtility.GetLastRect();
GUI.color = new Color(0f, 0f, 0f, 0.25f);
GUI.DrawTexture(new Rect(0f, rect.yMin + 6f, Screen.width, 4f), tex);
GUI.DrawTexture(new Rect(0f, rect.yMin + 6f, Screen.width, 1f), tex);
GUI.DrawTexture(new Rect(0f, rect.yMin + 9f, Screen.width, 1f), tex);
GUI.color = Color.white;
}
}
public static GUIStyle TitleStyle(){
GUIStyle title = new GUIStyle(EditorStyles.largeLabel);
title.fontSize = 16;
title.clipping = TextClipping.Overflow;
return title;
}
public static GUIStyle ThinButtonStyle(){
GUIStyle thinButton = new GUIStyle(EditorStyles.toolbarButton);
thinButton.fontStyle = FontStyle.Bold;
thinButton.fixedHeight = 24f;
return thinButton;
}
public static GUIStyle ThinButtonRedStyle(){
GUIStyle thinButtonRed = new GUIStyle(EditorStyles.toolbarButton);
thinButtonRed.fontStyle = FontStyle.Bold;
thinButtonRed.fixedHeight = 24f;
thinButtonRed.normal.textColor = Color.red;
return thinButtonRed;
}
public static GUIStyle ThinButtonPressedStyle(){
GUIStyle thinButtonPressed = new GUIStyle(EditorStyles.toolbarButton);
thinButtonPressed.fontStyle = FontStyle.Bold;
thinButtonPressed.fixedHeight = 24f;
return thinButtonPressed;
}
public static GUIStyle DropDownButtonStyle(){
GUIStyle dropDownButton = new GUIStyle(EditorStyles.toolbarDropDown);
dropDownButton.fontStyle = FontStyle.Bold;
dropDownButton.fixedHeight = 20f;
return dropDownButton;
}
public static GUIStyle EnumStyleButton(){
GUIStyle enumStyleButton = new GUIStyle(EditorStyles.toolbarDropDown);
enumStyleButton.onActive.background = ThinButtonStyle().onActive.background;
enumStyleButton.fixedHeight = 24f;
return enumStyleButton;
}
public static GUIStyle FoldOutButtonStyle(){
GUIStyle foldOutButton = new GUIStyle(EditorStyles.foldout);
foldOutButton.fontStyle = FontStyle.Bold;
return foldOutButton;
}
}
|