๐ŸŽฎ Unity Study/Unity

[Unity] ์ปค์Šคํ…€ ๋ฉ”๋‰ด ๋งŒ๋“ค๊ธฐ

ibelieveinme 2021. 9. 11. 11:56
728x90

Unity ๋Š” ์ƒ๋‹จ ๋ฉ”๋‰ด๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

Scene ๋ฐ”๋กœ๊ฐ€๊ธฐ ๋ฒ„ํŠผ, Jenkins ๋นŒ๋“œ ๋ฒ„ํŠผ ๋“ฑ์˜ ์ž์ฃผ ์“ฐ๋Š” ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค๋ฉด ๋”์šฑ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ด์šฉํ•  ์ˆ˜ ์žˆ๊ฒ ์ฃ ? 

 

๋ฉ”๋‰ด๋Š” Script๋ฅผ ํ†ตํ•ด ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์ด์ง€์š”.

using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;

public class ShortcutScneneMenu{
    [MenuItem("Scene Shortcut/Intro")]
    private static void MoveIntroScene(){
        EditorSceneManager.OpenScene("Assets/Dashboard/Intro/Intro.unity");
    }
}

=> Script๋ฅผ ํ†ตํ•ด ShortcutSceneMenu๋ผ๋Š” ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ  MenuItem ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ Menu UI๋ฅผ ๋งŒ๋“ค๊ณ , ๋ฐ”๋กœ ์•„๋ž˜์— ์›ํ•˜๋Š” ๊ธฐ๋Šฅ(ํ•จ์ˆ˜)์„ ๋‹ฌ์•„์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋!

=> ๊ทธ ์™ธ์—๋„ ํ•ด๋‹น ๋ฉ”๋‰ด์— ๋‹จ์ถ•ํ‚ค๋ฅผ ๋ถ€์—ฌํ•  ์ˆ˜๋„ ์žˆ๊ณ , ๋ฉ”๋‰ด ์•ˆ์— ๋ฉ”๋‰ด๋ฅผ ๋˜ ๋งŒ๋“ค์–ด์„œ ๊ตฌ์กฐ์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

 

P.S) ์ฒ˜์Œ์—” SceneManager๋กœ Scene ๋กœ๋“œ๋ฅผ ํ–ˆ์—ˆ๋Š”๋ฐ, ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๊ธธ๋ž˜ ์˜ค๋ฅ˜์—์„œ ์•ˆ๋‚ดํ•˜๋Š” EditorSceneManager.OpenScene() ์„ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

This can only be used during play mode, please use EditorSceneManager.OpenScene() instead.

 

๐Ÿ’› EditorSceneManager ๊ด€๋ จ ๊ณต์‹ reference ์ฐธ๊ณ 

https://docs.unity3d.com/ScriptReference/SceneManagement.EditorSceneManager.OpenScene.html

 

Unity - Scripting API: SceneManagement.EditorSceneManager.OpenScene

Use this function to open Scenes in the Hierarchy while in the Editor. This is useful for making custom Editor scripts, tools, or menu items. It is not intended to be used for loading Scenes at run time. To load Scenes at run time, see SceneManager.LoadSce

docs.unity3d.com

 

728x90