static void Drawer_AdvancedBlendDistance(SerializedHDReflectionProbe p, bool isNormal, Vector3 maxBlendDistance, GUIContent content)
        {
            SerializedProperty blendDistancePositive = isNormal ? p.blendNormalDistancePositive : p.blendDistancePositive;
            SerializedProperty blendDistanceNegative = isNormal ? p.blendNormalDistanceNegative : p.blendDistanceNegative;
            SerializedProperty editorAdvancedModeBlendDistancePositive = isNormal ? p.editorAdvancedModeBlendNormalDistancePositive : p.editorAdvancedModeBlendDistancePositive;
            SerializedProperty editorAdvancedModeBlendDistanceNegative = isNormal ? p.editorAdvancedModeBlendNormalDistanceNegative : p.editorAdvancedModeBlendDistanceNegative;
            SerializedProperty editorSimplifiedModeBlendDistance       = isNormal ? p.editorSimplifiedModeBlendNormalDistance : p.editorSimplifiedModeBlendDistance;
            Vector3            bdp = blendDistancePositive.vector3Value;
            Vector3            bdn = blendDistanceNegative.vector3Value;

            EditorGUILayout.BeginVertical();

            if (p.editorAdvancedModeEnabled.boolValue)
            {
                EditorGUI.BeginChangeCheck();
                CoreEditorUtils.DrawVector6(
                    content,
                    editorAdvancedModeBlendDistancePositive, editorAdvancedModeBlendDistanceNegative, Vector3.zero, maxBlendDistance, HDReflectionProbeEditor.k_handlesColor);
                if (EditorGUI.EndChangeCheck())
                {
                    blendDistancePositive.vector3Value = editorAdvancedModeBlendDistancePositive.vector3Value;
                    blendDistanceNegative.vector3Value = editorAdvancedModeBlendDistanceNegative.vector3Value;
                    p.Apply();
                }
            }
            else
            {
                float distance = editorSimplifiedModeBlendDistance.floatValue;
                EditorGUI.BeginChangeCheck();
                distance = EditorGUILayout.FloatField(content, distance);
                if (EditorGUI.EndChangeCheck())
                {
                    Vector3 decal = Vector3.one * distance;
                    bdp.x = Mathf.Clamp(decal.x, 0f, maxBlendDistance.x);
                    bdp.y = Mathf.Clamp(decal.y, 0f, maxBlendDistance.y);
                    bdp.z = Mathf.Clamp(decal.z, 0f, maxBlendDistance.z);
                    bdn.x = Mathf.Clamp(decal.x, 0f, maxBlendDistance.x);
                    bdn.y = Mathf.Clamp(decal.y, 0f, maxBlendDistance.y);
                    bdn.z = Mathf.Clamp(decal.z, 0f, maxBlendDistance.z);
                    blendDistancePositive.vector3Value           = bdp;
                    blendDistanceNegative.vector3Value           = bdn;
                    editorSimplifiedModeBlendDistance.floatValue = distance;
                    p.Apply();
                }
            }

            GUILayout.EndVertical();
        }
        static void Drawer_InfluenceAdvancedSwitch(HDReflectionProbeUI s, SerializedHDReflectionProbe p, Editor owner)
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();

                bool advanced = p.editorAdvancedModeEnabled.boolValue;
                advanced = !GUILayout.Toggle(!advanced, CoreEditorUtils.GetContent("Normal|Normal parameters mode (only change for box shape)."), EditorStyles.miniButtonLeft, GUILayout.Width(60f), GUILayout.ExpandWidth(false));
                advanced = GUILayout.Toggle(advanced, CoreEditorUtils.GetContent("Advanced|Advanced parameters mode (only change for box shape)."), EditorStyles.miniButtonRight, GUILayout.Width(60f), GUILayout.ExpandWidth(false));
                s.alternativeBoxBlendHandle.allHandleControledByOne = s.alternativeBoxBlendNormalHandle.allHandleControledByOne = !advanced;
                if (p.editorAdvancedModeEnabled.boolValue ^ advanced)
                {
                    p.editorAdvancedModeEnabled.boolValue = advanced;
                    if (advanced)
                    {
                        p.blendDistancePositive.vector3Value       = p.editorAdvancedModeBlendDistancePositive.vector3Value;
                        p.blendDistanceNegative.vector3Value       = p.editorAdvancedModeBlendDistanceNegative.vector3Value;
                        p.blendNormalDistancePositive.vector3Value = p.editorAdvancedModeBlendNormalDistancePositive.vector3Value;
                        p.blendNormalDistanceNegative.vector3Value = p.editorAdvancedModeBlendNormalDistanceNegative.vector3Value;
                    }
                    else
                    {
                        p.blendDistanceNegative.vector3Value       = p.blendDistancePositive.vector3Value = Vector3.one * p.editorSimplifiedModeBlendDistance.floatValue;
                        p.blendNormalDistanceNegative.vector3Value = p.blendNormalDistancePositive.vector3Value = Vector3.one * p.editorSimplifiedModeBlendNormalDistance.floatValue;
                    }
                    p.Apply();
                }
            }
        }
Beispiel #3
0
        static void Handle_InfluenceFadeEditing(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o, InfluenceType influenceType)
        {
            Gizmo6FacesBoxContained alternativeBlendBox;
            SphereBoundsHandle      sphereHandle;
            Vector3 probeBlendDistancePositive, probeBlendDistanceNegative;
            Color   color;

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

            case InfluenceType.Normal:
            {
                alternativeBlendBox        = s.alternativeBoxBlendNormalHandle;
                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 ((ShapeType)sp.influenceShape.enumValueIndex)
            {
            case ShapeType.Box:
            {
                alternativeBlendBox.center = sp.target.center - (probeBlendDistancePositive - probeBlendDistanceNegative) * 0.5f;
                alternativeBlendBox.size   = sp.target.size - probeBlendDistancePositive - probeBlendDistanceNegative;

                alternativeBlendBox.container.center = sp.target.center;
                alternativeBlendBox.container.size   = sp.target.size;

                EditorGUI.BeginChangeCheck();
                alternativeBlendBox.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 * (alternativeBlendBox.center - center);
                    var sum      = influenceSize - (alternativeBlendBox.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 ShapeType.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.blendDistancePositive.vector3Value = probeBlendDistancePositive;
                sp.blendDistanceNegative.vector3Value = probeBlendDistanceNegative;

                //save advanced/simplified saved data
                if (sp.editorAdvancedModeEnabled.boolValue)
                {
                    sp.editorAdvancedModeBlendDistancePositive.vector3Value = probeBlendDistancePositive;
                    sp.editorAdvancedModeBlendDistanceNegative.vector3Value = probeBlendDistanceNegative;
                }
                else
                {
                    sp.editorSimplifiedModeBlendDistance.floatValue = probeBlendDistancePositive.x;
                }
                break;
            }

            case InfluenceType.Normal:
            {
                sp.blendNormalDistancePositive.vector3Value = probeBlendDistancePositive;
                sp.blendNormalDistanceNegative.vector3Value = probeBlendDistanceNegative;

                //save advanced/simplified saved data
                if (sp.editorAdvancedModeEnabled.boolValue)
                {
                    sp.editorAdvancedModeBlendNormalDistancePositive.vector3Value = probeBlendDistancePositive;
                    sp.editorAdvancedModeBlendNormalDistanceNegative.vector3Value = probeBlendDistanceNegative;
                }
                else
                {
                    sp.editorSimplifiedModeBlendNormalDistance.floatValue = probeBlendDistancePositive.x;
                }
                break;
            }
            }
            sp.Apply();
        }