コード例 #1
0
        static void Drawer_InfluenceSphereSettings(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
        {
            var maxBlendDistance = HDReflectionProbeEditorUtility.CalculateSphereMaxBlendDistance(s, p, owner);

            var blendDistance = p.blendDistancePositive.vector3Value.x;

            EditorGUI.BeginChangeCheck();
            blendDistance = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."), blendDistance, 0, maxBlendDistance);
            if (EditorGUI.EndChangeCheck())
            {
                p.blendDistancePositive.vector3Value = Vector3.one * blendDistance;
                p.blendDistanceNegative.vector3Value = Vector3.one * blendDistance;
            }

            var blendNormalDistance = p.blendNormalDistancePositive.vector3Value.x;

            EditorGUI.BeginChangeCheck();
            blendNormalDistance = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."), blendNormalDistance, 0, maxBlendDistance);
            if (EditorGUI.EndChangeCheck())
            {
                p.blendNormalDistancePositive.vector3Value = Vector3.one * blendNormalDistance;
                p.blendNormalDistanceNegative.vector3Value = Vector3.one * blendNormalDistance;
            }

            EditorGUILayout.PropertyField(p.influenceSphereRadius, CoreEditorUtils.GetContent("Radius"));
            EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Sphere Offset|The center of the sphere in which the reflections will be applied to objects. The value is relative to the position of the Game Object."));

            EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Sphere Projection|Sphere projection causes reflections to appear to change based on the object's position within the probe's sphere, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting sphere projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings"));
        }
コード例 #2
0
        static void ApplyConstraintsOnTargets(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o)
        {
            switch ((ShapeType)sp.influenceShape.enumValueIndex)
            {
            case ShapeType.Box:
            {
                var maxBlendDistance = HDReflectionProbeEditorUtility.CalculateBoxMaxBlendDistance(s, sp, o);
                sp.targetData.blendDistancePositive       = Vector3.Min(sp.targetData.blendDistancePositive, maxBlendDistance);
                sp.targetData.blendDistanceNegative       = Vector3.Min(sp.targetData.blendDistanceNegative, maxBlendDistance);
                sp.targetData.blendNormalDistancePositive = Vector3.Min(sp.targetData.blendNormalDistancePositive, maxBlendDistance);
                sp.targetData.blendNormalDistanceNegative = Vector3.Min(sp.targetData.blendNormalDistanceNegative, maxBlendDistance);
                break;
            }

            case ShapeType.Sphere:
            {
                var maxBlendDistance = Vector3.one * HDReflectionProbeEditorUtility.CalculateSphereMaxBlendDistance(s, sp, o);
                sp.targetData.blendDistancePositive       = Vector3.Min(sp.targetData.blendDistancePositive, maxBlendDistance);
                sp.targetData.blendDistanceNegative       = Vector3.Min(sp.targetData.blendDistanceNegative, maxBlendDistance);
                sp.targetData.blendNormalDistancePositive = Vector3.Min(sp.targetData.blendNormalDistancePositive, maxBlendDistance);
                sp.targetData.blendNormalDistanceNegative = Vector3.Min(sp.targetData.blendNormalDistanceNegative, maxBlendDistance);
                break;
            }
            }
        }
コード例 #3
0
        static void Drawer_InfluenceShapeBoxSettings(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(p.boxSize, CoreEditorUtils.GetContent("Box Size|The size of the box in which the reflections will be applied to objects. The value is not affected by the Transform of the Game Object."));
            if (GUILayout.Button(toolbar_Contents[0], GUILayout.Width(28f), GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                EditMode.ChangeEditMode(EditMode.SceneViewEditMode.ReflectionProbeBox, GetBoundsGetter(p)(), owner);
            }
            EditorGUILayout.EndHorizontal();


            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Box Offset|The center of the box in which the reflections will be applied to objects. The value is relative to the position of the Game Object."));
            if (GUILayout.Button(toolbar_Contents[3], GUILayout.Width(28f), GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                EditMode.ChangeEditMode(EditMode.SceneViewEditMode.ReflectionProbeOrigin, GetBoundsGetter(p)(), owner);
            }
            EditorGUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                var center = p.boxOffset.vector3Value;
                var size   = p.boxSize.vector3Value;
                if (HDReflectionProbeEditorUtility.ValidateAABB(p.target, ref center, ref size))
                {
                    //clamp to contains object center instead of resizing
                    Vector3 projector = (center - p.boxOffset.vector3Value).normalized;
                    p.boxOffset.vector3Value = center + Mathf.Abs(Vector3.Dot((p.boxSize.vector3Value - size) * .5f, projector)) * projector;
                }
            }
        }
        static void Gizmos_Influence(ReflectionProbe p, HDAdditionalReflectionData a, HDReflectionProbeEditor e, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ShapeType.Box:
            {
                Gizmos.color = k_GizmoThemeColorExtentFace;
                e.m_UIState.alternativeBoxInfluenceHandle.DrawHull(isEdit);
                break;
            }

            case ShapeType.Sphere:
            {
                Gizmos.color = k_GizmoThemeColorExtentFace;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }
コード例 #5
0
        static void Handle_OriginEditing(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o)
        {
            var p = (ReflectionProbe)sp.so.targetObject;
            var transformPosition = p.transform.position;
            var size = p.size;

            EditorGUI.BeginChangeCheck();
            var newPostion = Handles.PositionHandle(transformPosition, HDReflectionProbeEditorUtility.GetLocalSpaceRotation(p));

            var changed = EditorGUI.EndChangeCheck();

            if (changed || s.oldLocalSpace != HDReflectionProbeEditorUtility.GetLocalSpace(p))
            {
                var localNewPosition = s.oldLocalSpace.inverse.MultiplyPoint3x4(newPostion);

                var b = new Bounds(p.center, size);
                localNewPosition = b.ClosestPoint(localNewPosition);

                Undo.RecordObject(p.transform, "Modified Reflection Probe Origin");
                p.transform.position = s.oldLocalSpace.MultiplyPoint3x4(localNewPosition);

                Undo.RecordObject(p, "Modified Reflection Probe Origin");
                p.center = HDReflectionProbeEditorUtility.GetLocalSpace(p).inverse.MultiplyPoint3x4(s.oldLocalSpace.MultiplyPoint3x4(p.center));

                EditorUtility.SetDirty(p);

                s.UpdateOldLocalSpace(p);
            }
        }
コード例 #6
0
        static void Drawer_InfluenceBoxSettings(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
        {
            var maxBlendDistance = HDReflectionProbeEditorUtility.CalculateBoxMaxBlendDistance(s, p, owner);

            CoreEditorUtils.DrawVector6Slider(
                CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."),
                p.blendDistancePositive, p.blendDistanceNegative, Vector3.zero, maxBlendDistance);

            CoreEditorUtils.DrawVector6Slider(
                CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."),
                p.blendNormalDistancePositive, p.blendNormalDistanceNegative, Vector3.zero, maxBlendDistance);

            CoreEditorUtils.DrawVector6Slider(
                CoreEditorUtils.GetContent("Face fade|Fade faces of the cubemap."),
                p.boxSideFadePositive, p.boxSideFadeNegative, Vector3.zero, Vector3.one);

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(p.boxSize, CoreEditorUtils.GetContent("Box Size|The size of the box in which the reflections will be applied to objects. The value is not affected by the Transform of the Game Object."));
            EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Box Offset|The center of the box in which the reflections will be applied to objects. The value is relative to the position of the Game Object."));
            EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Box Projection|Box projection causes reflections to appear to change based on the object's position within the probe's box, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting box projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings"));

            if (EditorGUI.EndChangeCheck())
            {
                var center = p.boxOffset.vector3Value;
                var size   = p.boxSize.vector3Value;
                if (HDReflectionProbeEditorUtility.ValidateAABB(p.target, ref center, ref size))
                {
                    p.boxOffset.vector3Value = center;
                    p.boxSize.vector3Value   = size;
                }
            }
        }
コード例 #7
0
 void ChangeVisibilityOfAllTargets(bool visibility)
 {
     for (var i = 0; i < targets.Length; ++i)
     {
         var p = (ReflectionProbe)targets[i];
         HDReflectionProbeEditorUtility.ChangeVisibility(p, visibility);
     }
 }
        public static void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath, bool custom)
        {
            if (!custom && probe.bakedTexture != null)
            {
                probe.customBakedTexture = probe.bakedTexture;
            }

            string path = "";

            if (usePreviousAssetPath)
            {
                path = AssetDatabase.GetAssetPath(probe.customBakedTexture);
            }

            string targetExtension = probe.hdr ? "exr" : "png";

            if (string.IsNullOrEmpty(path) || Path.GetExtension(path) != "." + targetExtension)
            {
                // We use the path of the active scene as the target path
                var targetPath = SceneManager.GetActiveScene().path;
                targetPath = Path.Combine(Path.GetDirectoryName(targetPath), Path.GetFileNameWithoutExtension(targetPath));
                if (string.IsNullOrEmpty(targetPath))
                {
                    targetPath = "Assets";
                }
                else if (Directory.Exists(targetPath) == false)
                {
                    Directory.CreateDirectory(targetPath);
                }

                string fileName = probe.name + (probe.hdr ? "-reflectionHDR" : "-reflection") + "." + targetExtension;
                fileName = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName)));

                path = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", fileName, targetExtension, "", targetPath);
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                ReflectionProbe collidingProbe;
                if (HDReflectionProbeEditorUtility.IsCollidingWithOtherProbes(path, probe, out collidingProbe))
                {
                    if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe",
                                                     string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?",
                                                                   path, collidingProbe.name), "Yes", "No"))
                    {
                        return;
                    }
                }
            }

            EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + path, 0.5f);
            if (!UnityEditor.Lightmapping.BakeReflectionProbe(probe, path))
            {
                Debug.LogError("Failed to bake reflection probe to " + path);
            }
            EditorUtility.ClearProgressBar();
        }
コード例 #9
0
        static void DrawNonSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
        {
            var reflectionData = reflectionProbe.GetComponent <HDAdditionalReflectionData>();

            if (reflectionData != null)
            {
                HDReflectionProbeEditorUtility.ChangeVisibility(reflectionProbe, false);
            }
        }
コード例 #10
0
        static void DrawSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
        {
            var reflectionData = reflectionProbe.GetComponent <HDAdditionalReflectionData>();

            Gizmos_Influence(reflectionProbe, reflectionData, null, false);
            Gizmos_InfluenceFade(reflectionProbe, reflectionData, null, InfluenceType.Standard, false);
            Gizmos_InfluenceFade(reflectionProbe, reflectionData, null, InfluenceType.Normal, false);

            DrawVerticalRay(reflectionProbe.transform);
            HDReflectionProbeEditorUtility.ChangeVisibility(reflectionProbe, true);
        }
コード例 #11
0
 static void Drawer_ReflectionProbeMode(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
 {
     EditorGUI.BeginChangeCheck();
     EditorGUI.showMixedValue = p.mode.hasMultipleDifferentValues;
     EditorGUILayout.IntPopup(p.mode, k_Content_ReflectionProbeMode, k_Content_ReflectionProbeModeValues, CoreEditorUtils.GetContent("Type|'Baked Cubemap' uses the 'Auto Baking' mode from the Lighting window. If it is enabled then baking is automatic otherwise manual bake is needed (use the bake button below). \n'Custom' can be used if a custom cubemap is wanted. \n'Realtime' can be used to dynamically re-render the cubemap during runtime (via scripting)."));
     EditorGUI.showMixedValue = false;
     if (EditorGUI.EndChangeCheck())
     {
         s.SetModeTarget(p.mode.intValue);
         foreach (var targetObject in p.so.targetObjects)
         {
             HDReflectionProbeEditorUtility.ResetProbeSceneTextureInMaterial((ReflectionProbe)targetObject);
         }
     }
 }
コード例 #12
0
        void ChangeVisibilityOfAllTargets(bool visibility)
        {
            if (targets.Length == 0)
            {
                return;
            }

            for (var i = 0; i < targets.Length; ++i)
            {
                if (targets[i] != null)
                {
                    var p = (ReflectionProbe)targets[i];
                    HDReflectionProbeEditorUtility.ChangeVisibility(p, visibility);
                }
            }
        }
コード例 #13
0
        void InitializeAllTargetProbes()
        {
            for (var i = 0; i < targets.Length; ++i)
            {
                var p = (ReflectionProbe)targets[i];
                var a = (HDAdditionalReflectionData)m_AdditionalDataSerializedObject.targetObjects[i];
                HDReflectionProbeEditorUtility.InitializeProbe(p, a);
            }

            // For an unknown reason, newly created probes sometype have the type "Quad" (value = 1)
            // This type of probe is not supported by Unity since 5.4
            // But we need to force it here so it does not bake into a 2D texture but a Cubemap
            serializedObject.Update();
            serializedObject.FindProperty("m_Type").intValue = 0;
            serializedObject.ApplyModifiedProperties();
        }
        static void DrawNonSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
        {
            var e = GetEditorFor(reflectionProbe);

            if (e == null || !e.sceneViewEditing)
            {
                return;
            }

            var reflectionData = reflectionProbe.GetComponent <HDAdditionalReflectionData>();

            if (reflectionData != null)
            {
                HDReflectionProbeEditorUtility.ChangeVisibility(reflectionProbe, false);
            }
        }
        static void DrawSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
        {
            var e = GetEditorFor(reflectionProbe);

            if (e == null || !e.sceneViewEditing)
            {
                return;
            }

            var reflectionData = reflectionProbe.GetComponent <HDAdditionalReflectionData>();

            //Gizmos_Influence(reflectionProbe, reflectionData, e, false);
            Gizmos_InfluenceFade(reflectionProbe, reflectionData, null, InfluenceType.Standard, false);
            Gizmos_InfluenceFade(reflectionProbe, reflectionData, null, InfluenceType.Normal, false);

            DrawVerticalRay(reflectionProbe.transform);
            HDReflectionProbeEditorUtility.ChangeVisibility(reflectionProbe, true);
        }
コード例 #16
0
        static void Gizmos_Influence(ReflectionProbe p, HDAdditionalReflectionData a, Editor e, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ReflectionInfluenceShape.Box:
            {
                Gizmos.color = isEdit ? k_GizmoThemeColorExtentFace : k_GizmoThemeColorExtent;
                if (isEdit)
                {
                    Gizmos.DrawCube(p.center, p.size);
                }
                else
                {
                    Gizmos.DrawWireCube(p.center, p.size);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                Gizmos.color = k_GizmoThemeColorExtentFace;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }
コード例 #17
0
        static void Drawer_InfluenceSphereSettings(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
        {
            var maxBlendDistance = HDReflectionProbeEditorUtility.CalculateSphereMaxBlendDistance(s, p, owner);

            var blendDistance = p.blendDistancePositive.vector3Value.x;

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = p.blendDistancePositive.hasMultipleDifferentValues;
            blendDistance            = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."), blendDistance, 0, maxBlendDistance);
            if (EditorGUI.EndChangeCheck())
            {
                p.blendDistancePositive.vector3Value = Vector3.one * blendDistance;
                p.blendDistanceNegative.vector3Value = Vector3.one * blendDistance;
            }
            if (GUILayout.Button(toolbar_Contents[1], GUILayout.Width(28f), GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                EditMode.ChangeEditMode(k_Toolbar_SceneViewEditModes[1], GetBoundsGetter(p)(), owner);
            }
            EditorGUILayout.EndHorizontal();

            var blendNormalDistance = p.blendNormalDistancePositive.vector3Value.x;

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = p.blendNormalDistancePositive.hasMultipleDifferentValues;
            blendNormalDistance      = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."), blendNormalDistance, 0, maxBlendDistance);
            if (EditorGUI.EndChangeCheck())
            {
                p.blendNormalDistancePositive.vector3Value = Vector3.one * blendNormalDistance;
                p.blendNormalDistanceNegative.vector3Value = Vector3.one * blendNormalDistance;
            }
            if (GUILayout.Button(toolbar_Contents[2], GUILayout.Width(28f), GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                EditMode.ChangeEditMode(k_Toolbar_SceneViewEditModes[2], GetBoundsGetter(p)(), owner);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.showMixedValue = false;
        }
コード例 #18
0
        static void Drawer_InfluenceBoxSettings(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
        {
            bool advanced         = p.editorAdvancedModeEnabled.boolValue;
            var  maxBlendDistance = HDReflectionProbeEditorUtility.CalculateBoxMaxBlendDistance(s, p, owner);

            EditorGUILayout.BeginHorizontal();
            Drawer_AdvancedBlendDistance(
                p,
                false,
                maxBlendDistance,
                CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes.")
                );
            if (GUILayout.Button(toolbar_Contents[1], GUILayout.ExpandHeight(true), GUILayout.Width(28f), GUILayout.MinHeight(22f), GUILayout.MaxHeight((advanced ? 3 : 1) * (EditorGUIUtility.singleLineHeight + 3))))
            {
                EditMode.ChangeEditMode(k_Toolbar_SceneViewEditModes[1], GetBoundsGetter(p)(), owner);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            Drawer_AdvancedBlendDistance(
                p,
                true,
                maxBlendDistance,
                CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes.")
                );
            if (GUILayout.Button(toolbar_Contents[2], GUILayout.ExpandHeight(true), GUILayout.Width(28f), GUILayout.MinHeight(22f), GUILayout.MaxHeight((advanced ? 3 : 1) * (EditorGUIUtility.singleLineHeight + 3))))
            {
                EditMode.ChangeEditMode(k_Toolbar_SceneViewEditModes[2], GetBoundsGetter(p)(), owner);
            }
            EditorGUILayout.EndHorizontal();

            if (advanced)
            {
                CoreEditorUtils.DrawVector6(
                    CoreEditorUtils.GetContent("Face fade|Fade faces of the cubemap."),
                    p.boxSideFadePositive, p.boxSideFadeNegative, Vector3.zero, Vector3.one, HDReflectionProbeEditor.k_handlesColor);
            }
        }
コード例 #19
0
        static void Handle_InfluenceFadeEditing(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o, InfluenceType influenceType)
        {
            BoxBoundsHandle    blendBox;
            SphereBoundsHandle sphereHandle;
            Vector3            probeBlendDistancePositive, probeBlendDistanceNegative;
            Color color;

            switch (influenceType)
            {
            default:
            case InfluenceType.Standard:
            {
                blendBox     = s.boxBlendHandle;
                sphereHandle = s.sphereBlendHandle;
                probeBlendDistancePositive = sp.targetData.blendDistancePositive;
                probeBlendDistanceNegative = sp.targetData.blendDistanceNegative;
                color = k_GizmoThemeColorInfluenceBlend;
                break;
            }

            case InfluenceType.Normal:
            {
                blendBox     = s.boxBlendNormalHandle;
                sphereHandle = s.sphereBlendNormalHandle;
                probeBlendDistancePositive = sp.targetData.blendNormalDistancePositive;
                probeBlendDistanceNegative = sp.targetData.blendNormalDistanceNegative;
                color = k_GizmoThemeColorInfluenceNormalBlend;
                break;
            }
            }


            var mat = Handles.matrix;
            var col = Handles.color;

            Handles.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(sp.target);
            switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
            {
            case ReflectionInfluenceShape.Box:
            {
                blendBox.center = sp.target.center - (probeBlendDistancePositive - probeBlendDistanceNegative) * 0.5f;
                blendBox.size   = sp.target.size - probeBlendDistancePositive - probeBlendDistanceNegative;

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                Handles.color = color;
                blendBox.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection Probe Influence");
                    Undo.RecordObject(sp.targetData, "Modified Reflection Probe Influence");

                    var center        = sp.target.center;
                    var influenceSize = sp.target.size;

                    var diff     = 2 * (blendBox.center - center);
                    var sum      = influenceSize - blendBox.size;
                    var positive = (sum - diff) * 0.5f;
                    var negative = (sum + diff) * 0.5f;
                    var blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positive, influenceSize));
                    var blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negative, influenceSize));

                    probeBlendDistancePositive = blendDistancePositive;
                    probeBlendDistanceNegative = blendDistanceNegative;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                sphereHandle.center = sp.target.center;
                sphereHandle.radius = Mathf.Clamp(sp.targetData.influenceSphereRadius - probeBlendDistancePositive.x, 0, sp.targetData.influenceSphereRadius);

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                Handles.color = color;
                sphereHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection influence volume");
                    Undo.RecordObject(sp.targetData, "Modified Reflection influence volume");

                    var influenceRadius = sp.targetData.influenceSphereRadius;
                    var blendRadius     = sphereHandle.radius;

                    var blendDistance = Mathf.Clamp(influenceRadius - blendRadius, 0, influenceRadius);

                    probeBlendDistancePositive = Vector3.one * blendDistance;
                    probeBlendDistanceNegative = probeBlendDistancePositive;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }
            }
            Handles.matrix = mat;
            Handles.color  = col;


            switch (influenceType)
            {
            default:
            case InfluenceType.Standard:
            {
                sp.targetData.blendDistancePositive = probeBlendDistancePositive;
                sp.targetData.blendDistanceNegative = probeBlendDistanceNegative;
                break;
            }

            case InfluenceType.Normal:
            {
                sp.targetData.blendNormalDistancePositive = probeBlendDistancePositive;
                sp.targetData.blendNormalDistanceNegative = probeBlendDistanceNegative;
                break;
            }
            }
        }
コード例 #20
0
        static void Gizmos_InfluenceFade(ReflectionProbe p, HDAdditionalReflectionData a, Editor e, InfluenceType type, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Vector3 boxCenterOffset;
            Vector3 boxSizeOffset;
            float   sphereRadiusOffset;
            Color   color;

            switch (type)
            {
            default:
            case InfluenceType.Standard:
            {
                boxCenterOffset    = a.boxBlendCenterOffset;
                boxSizeOffset      = a.boxBlendSizeOffset;
                sphereRadiusOffset = a.sphereBlendRadiusOffset;
                color = isEdit ? k_GizmoThemeColorInfluenceBlendFace : k_GizmoThemeColorInfluenceBlend;
                break;
            }

            case InfluenceType.Normal:
            {
                boxCenterOffset    = a.boxBlendNormalCenterOffset;
                boxSizeOffset      = a.boxBlendNormalSizeOffset;
                sphereRadiusOffset = a.sphereBlendNormalRadiusOffset;
                color = isEdit ? k_GizmoThemeColorInfluenceNormalBlendFace : k_GizmoThemeColorInfluenceNormalBlend;
                break;
            }
            }

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ReflectionInfluenceShape.Box:
            {
                Gizmos.color = color;
                if (isEdit)
                {
                    Gizmos.DrawCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                }
                else
                {
                    Gizmos.DrawWireCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                Gizmos.color = color;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }
        static void Gizmos_InfluenceFade(ReflectionProbe p, HDAdditionalReflectionData a, HDReflectionProbeEditor e, InfluenceType type, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Gizmo6FacesBoxContained box;
            Vector3 boxCenterOffset;
            Vector3 boxSizeOffset;
            float   sphereRadiusOffset;
            Color   color;

            switch (type)
            {
            default:
            case InfluenceType.Standard:
            {
                box                = e != null ? e.m_UIState.alternativeBoxBlendHandle : null;
                boxCenterOffset    = a.boxBlendCenterOffset;
                boxSizeOffset      = a.boxBlendSizeOffset;
                sphereRadiusOffset = a.sphereBlendRadiusOffset;
                color              = isEdit ? k_GizmoThemeColorInfluenceBlendFace : k_GizmoThemeColorInfluenceBlend;
                break;
            }

            case InfluenceType.Normal:
            {
                box                = e != null ? e.m_UIState.alternativeBoxBlendNormalHandle : null;
                boxCenterOffset    = a.boxBlendNormalCenterOffset;
                boxSizeOffset      = a.boxBlendNormalSizeOffset;
                sphereRadiusOffset = a.sphereBlendNormalRadiusOffset;
                color              = isEdit ? k_GizmoThemeColorInfluenceNormalBlendFace : k_GizmoThemeColorInfluenceNormalBlend;
                break;
            }
            }

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ShapeType.Box:
            {
                Gizmos.color = color;
                if (e != null)        // e == null may occure when editor have still not been created at selection while the tool is not used for this part
                {
                    box.DrawHull(isEdit);
                }
                else
                {
                    if (isEdit)
                    {
                        Gizmos.DrawCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                    }
                    else
                    {
                        Gizmos.DrawWireCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                    }
                }
                break;
            }

            case ShapeType.Sphere:
            {
                Gizmos.color = color;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }
コード例 #22
0
        static void Drawer_BakeActions(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
        {
            if (p.mode.intValue == (int)ReflectionProbeMode.Realtime)
            {
                EditorGUILayout.HelpBox("Refresh of this reflection probe should be initiated from the scripting API because the type is 'Realtime'", MessageType.Info);

                if (!QualitySettings.realtimeReflectionProbes)
                {
                    EditorGUILayout.HelpBox("Realtime reflection probes are disabled in Quality Settings", MessageType.Warning);
                }
                return;
            }

            if (p.mode.intValue == (int)ReflectionProbeMode.Baked && UnityEditor.Lightmapping.giWorkflowMode != UnityEditor.Lightmapping.GIWorkflowMode.OnDemand)
            {
                EditorGUILayout.HelpBox("Baking of this reflection probe is automatic because this probe's type is 'Baked' and the Lighting window is using 'Auto Baking'. The cubemap created is stored in the GI cache.", MessageType.Info);
                return;
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            switch ((ReflectionProbeMode)p.mode.intValue)
            {
            case ReflectionProbeMode.Custom:
            {
                if (ButtonWithDropdownList(
                        CoreEditorUtils.GetContent("Bake|Bakes Reflection Probe's cubemap, overwriting the existing cubemap texture asset (if any)."), k_BakeCustomOptionText,
                        data =>
                    {
                        var mode = (int)data;

                        var probe = p.target;
                        if (mode == 0)
                        {
                            HDReflectionProbeEditorUtility.BakeCustomReflectionProbe(probe, false, true);
                            HDReflectionProbeEditorUtility.ResetProbeSceneTextureInMaterial(probe);
                        }
                    },
                        GUILayout.ExpandWidth(true)))
                {
                    var probe = p.target;
                    HDReflectionProbeEditorUtility.BakeCustomReflectionProbe(probe, true, true);
                    HDReflectionProbeEditorUtility.ResetProbeSceneTextureInMaterial(probe);
                    GUIUtility.ExitGUI();
                }
                break;
            }

            case ReflectionProbeMode.Baked:
            {
                GUI.enabled = p.target.enabled;

                // Bake button in non-continous mode
                if (ButtonWithDropdownList(
                        CoreEditorUtils.GetContent("Bake"),
                        k_BakeButtonsText,
                        data =>
                    {
                        var mode = (int)data;
                        if (mode == 0)
                        {
                            HDReflectionProbeEditorUtility.BakeAllReflectionProbesSnapshots();
                        }
                    },
                        GUILayout.ExpandWidth(true)))
                {
                    var probe = p.target;
                    HDReflectionProbeEditorUtility.BakeReflectionProbeSnapshot(probe);
                    HDReflectionProbeEditorUtility.ResetProbeSceneTextureInMaterial(probe);
                    GUIUtility.ExitGUI();
                }

                GUI.enabled = true;
                break;
            }

            case ReflectionProbeMode.Realtime:
                // Not showing bake button in realtime
                break;
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
コード例 #23
0
        static void Handle_InfluenceEditing(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o)
        {
            var mat = Handles.matrix;
            var col = Handles.color;

            Handles.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(sp.target);
            switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
            {
            case ReflectionInfluenceShape.Box:
            {
                s.boxInfluenceHandle.center = sp.target.center;
                s.boxInfluenceHandle.size   = sp.target.size;

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                s.boxInfluenceHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection Probe AABB");
                    Undo.RecordObject(sp.targetData, "Modified Reflection Probe AABB");

                    var center = s.boxInfluenceHandle.center;
                    var size   = s.boxInfluenceHandle.size;

                    HDReflectionProbeEditorUtility.ValidateAABB(sp.target, ref center, ref size);

                    sp.target.center = center;
                    sp.target.size   = size;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                s.sphereInfluenceHandle.center = sp.target.center;
                s.sphereInfluenceHandle.radius = sp.targetData.influenceSphereRadius;

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                s.sphereInfluenceHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection Probe AABB");
                    Undo.RecordObject(sp.targetData, "Modified Reflection Probe AABB");

                    var center          = sp.target.center;
                    var influenceRadius = s.sphereInfluenceHandle.radius;
                    var radius          = Vector3.one * influenceRadius;

                    HDReflectionProbeEditorUtility.ValidateAABB(sp.target, ref center, ref radius);
                    influenceRadius = radius.x;

                    sp.targetData.influenceSphereRadius = influenceRadius;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }
            }
            Handles.matrix = mat;
            Handles.color  = col;
        }
コード例 #24
0
 internal void UpdateOldLocalSpace(ReflectionProbe target)
 {
     oldLocalSpace = HDReflectionProbeEditorUtility.GetLocalSpace(target);
 }