본문 바로가기

Unity/Common

Unity Current Scene Upgrade Standard terrain shader to HDRP Shader

반응형

현재 Scene의  스탠다드 터레인 머티리얼을 HDRP 기본 셰이더로 변경해주는 스크립트입니다.

 

 

using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;

public class StandardToHDRP 
{
    [MenuItem("Edit/Render Pipeline/Upgrade Scene Terrain Materials")]
    public static void UpgradeSceneTerrainMaterial()
    {
        Scene scene = EditorSceneManager.GetActiveScene();
        List<GameObject> gameObjects = new List<GameObject>();
        scene.GetRootGameObjects(gameObjects);
        if (gameObjects.Count == 0) return;
        foreach(GameObject root in gameObjects)
        {
            Terrain[] terrains = root.GetComponentsInChildren<Terrain>();
            foreach(Terrain terrain in terrains)
            {
                if (!terrain.materialTemplate.shader.name.ToLower().Contains("standard")) continue;
                terrain.materialTemplate.shader = Shader.Find("HDRP/TerrainLit");

            }//Terrain
        }//GameObject
    }
}

아래에서 네번째에 추가된 메뉴

 

반응형