您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
53 行
2.0 KiB
53 行
2.0 KiB
using UnityEngine;
|
|
using UnityEngine.Experimental.Rendering;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace UnityEditor.Experimental.Rendering
|
|
{
|
|
partial class HDReflectionProbeEditor
|
|
{
|
|
static Material s_PreviewMaterial;
|
|
static Mesh s_SphereMesh;
|
|
static int _Cubemap = Shader.PropertyToID("_Cubemap");
|
|
|
|
|
|
[InitializeOnLoadMethod]
|
|
static void Initialize()
|
|
{
|
|
s_PreviewMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview"))
|
|
{
|
|
hideFlags = HideFlags.HideAndDontSave
|
|
};
|
|
s_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh;
|
|
}
|
|
|
|
static void InitializeProbe(ReflectionProbe p, HDAdditionalReflectionData data)
|
|
{
|
|
var meshFilter = p.GetComponent<MeshFilter>() ?? p.gameObject.AddComponent<MeshFilter>();
|
|
var meshRenderer = p.GetComponent<MeshRenderer>() ?? p.gameObject.AddComponent<MeshRenderer>();
|
|
|
|
meshFilter.sharedMesh = s_SphereMesh;
|
|
|
|
var material = meshRenderer.sharedMaterial;
|
|
if (material == null
|
|
|| material == s_PreviewMaterial
|
|
|| material.shader != s_PreviewMaterial.shader)
|
|
{
|
|
material = Object.Instantiate(s_PreviewMaterial);
|
|
material.SetTexture(_Cubemap, p.texture);
|
|
material.hideFlags = HideFlags.HideAndDontSave;
|
|
meshRenderer.material = material;
|
|
}
|
|
|
|
meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
|
|
meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
|
meshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
|
|
}
|
|
|
|
static void ChangeVisibility(ReflectionProbe p, bool visible)
|
|
{
|
|
var meshRenderer = p.GetComponent<MeshRenderer>() ?? p.gameObject.AddComponent<MeshRenderer>();
|
|
meshRenderer.enabled = visible;
|
|
}
|
|
}
|
|
}
|