Unity가 템플릿에서 새로운 씬을 인스턴스화할 때 커스텀 코드를 실행하려면 씬 템플릿 파이프라인 스크립트를 생성한 후 템플릿에 연결하십시오. 템플릿에서 새로운 씬을 생성할 때마다 Unity는 파이프라인 스크립트의 새로운 인스턴스도 함께 생성합니다.
스크립트를 템플릿에 연결하려면 다음 단계를 따르십시오.
SceneTemplateAsset.templatePipeline
메서드를 사용하여 C#을 통해 스크립트를 템플릿에 연결할 수도 있습니다.
씬 템플릿 파이프라인 스크립트는 [ISceneTemplatePipeline
] 인터페이스 또는 [SceneTemplatePipelineAdapter
]에서 파생되어야 합니다. 또한 반응할 이벤트를 구현해야 합니다. 예를 들어 아래 코드에서는 BeforeTemplateInstantiation
또는 AfterTemplateInstantiation
입니다.
예제:
using UnityEditor.SceneTemplate;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DummySceneTemplatePipeline : ISceneTemplatePipeline
{
public void BeforeTemplateInstantiation(SceneTemplateAsset sceneTemplateAsset, bool isAdditive, string sceneName)
{
if (sceneTemplateAsset)
{
Debug.Log($"Before Template Pipeline {sceneTemplateAsset.name} isAdditive: {isAdditive} sceneName: {sceneName}");
}
}
public void AfterTemplateInstantiation(SceneTemplateAsset sceneTemplateAsset, Scene scene, bool isAdditive, string sceneName)
{
if (sceneTemplateAsset)
{
Debug.Log($"After Template Pipeline {sceneTemplateAsset.name} scene: {scene} isAdditive: {isAdditive} sceneName: {sceneName}");
}
}
}
복제 가능한 종속성이 있는 템플릿에서 새로운 씬을 생성하면 Unity는 여러 파일 작업을 수행합니다. 이러한 작업의 대부분은 스크립트에서 수신하고 반응할 수 있는 Unity 이벤트를 트리거합니다.
인스턴스화 시퀀스는 다음과 같습니다.
Unity가 템플릿 에셋에 대해 ISceneTemplatePipeline.BeforeTemplateInstantiation
이벤트를 트리거하고, 트리거하는 ISceneTemplatePipeline
스크립트에 에셋을 바인딩합니다.
Unity가 SceneTemplate.NewTemplateInstantiating
이벤트를 트리거합니다.
Unity가 템플릿 씬의 복사본인 새로운 씬을 생성합니다.
Unity가 새로운 씬과 동일한 이름의 폴더를 생성하고 복제 가능한 모든 종속성을 해당 폴더에 복사합니다.
EditorSceneManager.sceneOpening
MonoBehavior.OnValidate
(구현하는 모든 게임 오브젝트에서 트리거)EditorSceneManager.sceneOpened
Unity가 모든 복제 가능 에셋에 대한 레퍼런스를 다시 매핑하므로, 새로운 씬이 복제물을 가리킵니다.
Unity가 템플릿 에셋에 대해 ISceneTemplatePipeline.AfterTemplateInstantiation
을 트리거하고, 트리거하는 ISceneTemplatePipeline
스크립트에 에셋을 바인딩합니다.
Unity가 SceneTemplate.NewTemplateInstantiated
이벤트를 트리거합니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.