forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneFXWindow.cs
More file actions
103 lines (80 loc) · 3.44 KB
/
SceneFXWindow.cs
File metadata and controls
103 lines (80 loc) · 3.44 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using UnityEngine;
namespace UnityEditor
{
internal class SceneFXWindow : PopupWindowContent
{
private class Styles
{
public readonly GUIStyle menuItem = "MenuItem";
}
private static Styles s_Styles;
private readonly SceneView m_SceneView;
const float kFrameWidth = 1f;
public override Vector2 GetWindowSize()
{
var windowHeight = 2f * kFrameWidth + EditorGUI.kSingleLineHeight * 6;
var windowSize = new Vector2(160, windowHeight);
return windowSize;
}
public SceneFXWindow(SceneView sceneView)
{
m_SceneView = sceneView;
}
public override void OnGUI(Rect rect)
{
if (m_SceneView == null || m_SceneView.sceneViewState == null)
return;
// We do not use the layout event
if (Event.current.type == EventType.Layout)
return;
if (s_Styles == null)
s_Styles = new Styles();
// Content
Draw(rect);
// Use mouse move so we get hover state correctly in the menu item rows
if (Event.current.type == EventType.MouseMove)
Event.current.Use();
// Escape closes the window
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
{
editorWindow.Close();
GUIUtility.ExitGUI();
}
}
private void Draw(Rect rect)
{
if (m_SceneView == null || m_SceneView.sceneViewState == null)
return;
var drawPos = new Rect(kFrameWidth, kFrameWidth, rect.width - 2 * kFrameWidth, EditorGUI.kSingleLineHeight);
var state = m_SceneView.sceneViewState;
//
// scene view effect options
DrawListElement(drawPos, "Skybox", state.showSkybox, value => state.showSkybox = value);
drawPos.y += EditorGUI.kSingleLineHeight;
DrawListElement(drawPos, "Fog", state.showFog, value => state.showFog = value);
drawPos.y += EditorGUI.kSingleLineHeight;
DrawListElement(drawPos, "Flares", state.showFlares, value => state.showFlares = value);
drawPos.y += EditorGUI.kSingleLineHeight;
DrawListElement(drawPos, "Animated Materials", state.showMaterialUpdate, value => state.showMaterialUpdate = value);
drawPos.y += EditorGUI.kSingleLineHeight;
DrawListElement(drawPos, "Post Processings", state.showImageEffects, value => state.showImageEffects = value);
drawPos.y += EditorGUI.kSingleLineHeight;
DrawListElement(drawPos, "Particle Systems", state.showParticleSystems, value => state.showParticleSystems = value);
drawPos.y += EditorGUI.kSingleLineHeight;
}
void DrawListElement(Rect rect, string toggleName, bool value, Action<bool> setValue)
{
EditorGUI.BeginChangeCheck();
bool result = GUI.Toggle(rect, value, EditorGUIUtility.TempContent(toggleName), s_Styles.menuItem);
if (EditorGUI.EndChangeCheck())
{
setValue(result);
m_SceneView.Repaint();
}
}
}
}