Skip to content

Commit 8585af7

Browse files
committed
editor: Add prefab creation to game object menu.
1 parent d832eeb commit 8585af7

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

Editor/BlueprintProjector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace VisualPinball.Engine.Unity.Hdrp.Editor
2525
{
2626
public static class BlueprintProjector
2727
{
28-
[MenuItem("GameObject/Visual Pinball/Blueprint Projector", false, 12)]
28+
[MenuItem("GameObject/Visual Pinball/Blueprint Projector", false, 15)]
2929
private static void CreateBlueprintProjector()
3030
{
3131
// TODO: Move post-instantiation logic to BP authoring component. Extend to make it simpler to swap projections.

Editor/PrefabCreator.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2020 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
using UnityEditor;
18+
using UnityEditor.SceneManagement;
19+
using UnityEngine;
20+
using UnityEngine.Rendering.HighDefinition;
21+
using UnityEngine.SceneManagement;
22+
using VisualPinball.Unity;
23+
24+
namespace VisualPinball.Engine.Unity.Hdrp.Editor
25+
{
26+
public static class PrefabCreator
27+
{
28+
[MenuItem("GameObject/Visual Pinball/Editor Camera", false, 12)]
29+
private static void CreateEditorCamera()
30+
{
31+
Create(AssetPath.CameraPrefab, "Editor Camera", "Create Editor Camera");
32+
}
33+
34+
[MenuItem("GameObject/Visual Pinball/Editor Post Processing", false, 13)]
35+
private static void CreatePostProcessing()
36+
{
37+
Create(AssetPath.PostProcessPrefab, "Editor Post Processing", "Create Editor Post Processing");
38+
}
39+
40+
[MenuItem("GameObject/Visual Pinball/Editor Lighting", false, 14)]
41+
private static void CreateLighting()
42+
{
43+
Create(AssetPath.LightingPrefab, "Editor Lighting", "Create Editor Lighting");
44+
}
45+
46+
private static void Create(string path, string name, string undoLabel)
47+
{
48+
var prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
49+
50+
// Spawn the prefab in the scene.
51+
var go = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
52+
go.name = name;
53+
Undo.RegisterCreatedObjectUndo(go, undoLabel);
54+
55+
// parent
56+
var parent = Selection.activeGameObject == null
57+
? go.transform.root
58+
: Selection.activeGameObject.transform;
59+
60+
go.transform.SetParent(parent, true);
61+
Selection.activeGameObject = go;
62+
}
63+
}
64+
}

Editor/PrefabCreator.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)