|
| 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 | +} |
0 commit comments