ReflectionProbe 烘焙

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using DG.Tweening.Plugins.Core.PathCore;
using UnityEngine.WSA;
using UnityEngine.SceneManagement;
using UnityEditor.VersionControl;

public class ReflectionProbeBake : EditorWindow
{
    public string folder = string.Empty;
    [MenuItem("Tools/ ReflectionProbe 烘焙")]
    static void Init()
    {
        ReflectionProbeBake window = (ReflectionProbeBake)GetWindow(typeof(ReflectionProbeBake));
        window.Show();
    }

    void Start()
    {
    }

    private void OnGUI()
    {
        GUILayout.Space(10);
        EditorGUILayout.BeginHorizontal();
        folder = EditorGUILayout.TextField("RelectionProbe存放位置", folder);

        if (GUILayout.Button("Set", GUILayout.Width(40f)))
        {
            folder = EditorUtility.OpenFolderPanel("select save path", "", "").Replace(UnityEngine.Application.dataPath, "Assets");
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(10);

        if (GUILayout.Button("烘焙"))
        {
            BakeReflectionPrefab(folder);
        }

    }
    
    void BakeReflectionPrefab(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            Debug.LogError("存放位置不可爲空!");

            return;
        }

        foreach (Object obj in Selection.objects)
        {
            if (((GameObject)obj).GetComponent<ReflectionProbe>())
            {
                ReflectionProbe reflectionProbe = ((GameObject)obj).GetComponent<ReflectionProbe>();
                Lightmapping.BakeReflectionProbe(reflectionProbe, path + "/"+obj.name + ".exr");
            }
        }

        Repaint();
    }

}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章