-
Notifications
You must be signed in to change notification settings - Fork 871
Expand file tree
/
Copy pathRenderer2DMenus.cs
More file actions
197 lines (168 loc) · 9.07 KB
/
Renderer2DMenus.cs
File metadata and controls
197 lines (168 loc) · 9.07 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
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
using System;
using UnityEditor.ProjectWindowCallback;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Universal
{
static class Renderer2DMenus
{
static void Create2DRendererData(Action<Renderer2DData> onCreatedCallback)
{
var instance = ScriptableObject.CreateInstance<Create2DRendererDataAsset>();
instance.onCreated += onCreatedCallback;
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, instance, "New 2D Renderer Data.asset", null, null);
}
class Create2DRendererDataAsset : EndNameEditAction
{
public event Action<Renderer2DData> onCreated;
public override void Action(int instanceId, string pathName, string resourceFile)
{
var instance = UniversalRenderPipelineAsset.CreateRendererAsset(pathName, RendererType._2DRenderer, false) as Renderer2DData;
Selection.activeObject = instance;
onCreated?.Invoke(instance);
}
}
internal static void PlaceGameObjectInFrontOfSceneView(GameObject go)
{
var sceneViews = SceneView.sceneViews;
if (sceneViews.Count >= 1)
{
SceneView view = SceneView.lastActiveSceneView;
if (!view)
view = sceneViews[0] as SceneView;
if (view)
view.MoveToView(go.transform);
}
}
// This is from GOCreationCommands
internal static void Place(GameObject go, GameObject parent)
{
if (parent != null)
{
var transform = go.transform;
Undo.SetTransformParent(transform, parent.transform, "Reparenting");
transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity;
transform.localScale = Vector3.one;
go.layer = parent.layer;
if (parent.GetComponent<RectTransform>())
ObjectFactory.AddComponent<RectTransform>(go);
}
else
{
PlaceGameObjectInFrontOfSceneView(go);
StageUtility.PlaceGameObjectInCurrentStage(go); // may change parent
go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, 0);
}
// Only at this point do we know the actual parent of the object and can modify its name accordingly.
GameObjectUtility.EnsureUniqueNameForSibling(go);
Undo.SetCurrentGroupName("Create " + go.name);
//EditorWindow.FocusWindowIfItsOpen<SceneHierarchyWindow>();
Selection.activeGameObject = go;
}
static Light2D CreateLight(MenuCommand menuCommand, Light2D.LightType type, Vector3[] shapePath = null)
{
var lightName = type != Light2D.LightType.Point ? type.ToString() : "Spot";
GameObject go = ObjectFactory.CreateGameObject(lightName + " Light 2D", typeof(Light2D));
Light2D light2D = go.GetComponent<Light2D>();
light2D.lightType = type;
if (shapePath != null && shapePath.Length > 0)
light2D.shapePath = shapePath;
var parent = menuCommand.context as GameObject;
Place(go, parent);
Analytics.Light2DData lightData = new Analytics.Light2DData();
lightData.was_create_event = true;
lightData.instance_id = light2D.GetInstanceID();
lightData.light_type = light2D.lightType;
Analytics.Renderer2DAnalytics.instance.SendData(Analytics.AnalyticsDataTypes.k_LightDataString, lightData);
return light2D;
}
static bool CreateLightValidation()
{
return Light2DEditorUtility.IsUsing2DRenderer();
}
[MenuItem("GameObject/Light/Freeform Light 2D/Square", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 4)]
static void CreateSquareFreeformLight2D(MenuCommand menuCommand)
{
CreateLight(menuCommand, Light2D.LightType.Freeform, FreeformPathPresets.CreateSquare());
}
[MenuItem("GameObject/Light/Freeform Light 2D/Circle", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 5)]
static void CreateCircleFreeformLight2D(MenuCommand menuCommand)
{
CreateLight(menuCommand, Light2D.LightType.Freeform, FreeformPathPresets.CreateCircle());
}
[MenuItem("GameObject/Light/Freeform Light 2D/Isometric Diamond", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 6)]
static void CreateIsometricDiamondFreeformLight2D(MenuCommand menuCommand)
{
CreateLight(menuCommand, Light2D.LightType.Freeform, FreeformPathPresets.CreateIsometricDiamond());
}
[MenuItem("GameObject/Light/Freeform Light 2D/Hexagon Flat Top", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 7)]
static void CreateHexagonFlatTopFreeformLight2D(MenuCommand menuCommand)
{
CreateLight(menuCommand, Light2D.LightType.Freeform, FreeformPathPresets.CreateHexagonFlatTop());
}
[MenuItem("GameObject/Light/Freeform Light 2D/Hexagon Pointed Top", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 8)]
static void CreateHexagonPointedTopFreeformLight2D(MenuCommand menuCommand)
{
CreateLight(menuCommand, Light2D.LightType.Freeform, FreeformPathPresets.CreateHexagonPointedTop());
}
[MenuItem("GameObject/Light/Sprite Light 2D", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 1)]
static void CreateSpriteLight2D(MenuCommand menuCommand)
{
Light2D light = CreateLight(menuCommand, Light2D.LightType.Sprite);
ResourceReloader.ReloadAllNullIn(light, UniversalRenderPipelineAsset.packagePath);
}
[MenuItem("GameObject/Light/Spot Light 2D", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 2)]
static void CreatePointLight2D(MenuCommand menuCommand)
{
CreateLight(menuCommand, Light2D.LightType.Point);
}
[MenuItem("GameObject/Light/Global Light 2D", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.gameObjectMenuPriority + 3)]
static void CreateGlobalLight2D(MenuCommand menuCommand)
{
CreateLight(menuCommand, Light2D.LightType.Global);
}
[MenuItem("GameObject/Light/Freeform Light 2D/Isometric Diamond", true)]
[MenuItem("GameObject/Light/Freeform Light 2D/Square", true)]
[MenuItem("GameObject/Light/Freeform Light 2D/Circle", true)]
[MenuItem("GameObject/Light/Freeform Light 2D/Hexagon Flat Top", true)]
[MenuItem("GameObject/Light/Freeform Light 2D/Hexagon Pointed Top", true)]
[MenuItem("GameObject/Light/Sprite Light 2D", true)]
[MenuItem("GameObject/Light/Spot Light 2D", true)]
[MenuItem("GameObject/Light/Global Light 2D", true)]
static bool CreateLight2DValidation()
{
return CreateLightValidation();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812")]
internal class CreateUniversalPipelineAsset : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
//Create asset
AssetDatabase.CreateAsset(UniversalRenderPipelineAsset.Create(UniversalRenderPipelineAsset.CreateRendererAsset(pathName, RendererType._2DRenderer)), pathName);
}
}
[MenuItem("Assets/Create/Rendering/URP Asset (with 2D Renderer)", priority = CoreUtils.Sections.section2 + CoreUtils.Priorities.assetsCreateRenderingMenuPriority)]
static void CreateUniversalPipeline()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, UniversalRenderPipelineAsset.CreateInstance<CreateUniversalPipelineAsset>(),
"New Universal Render Pipeline Asset.asset", null, null);
}
[MenuItem("Assets/Create/Rendering/URP 2D Renderer", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.assetsCreateRenderingMenuPriority + 1)]
static void Create2DRendererData()
{
Renderer2DMenus.Create2DRendererData((instance) =>
{
Analytics.RendererAssetData modifiedData = new Analytics.RendererAssetData();
modifiedData.instance_id = instance.GetInstanceID();
modifiedData.was_create_event = true;
modifiedData.blending_layers_count = 1;
modifiedData.blending_modes_used = 2;
Analytics.Renderer2DAnalytics.instance.SendData(Analytics.AnalyticsDataTypes.k_Renderer2DDataString, modifiedData);
});
}
}
}