using UnityEngine ;
using UnityEngine.Experimental.Rendering ;
using UnityEngine.Experimental.Rendering.HDPipeline ;
using UnityEditor.Experimental.Rendering.HDPipeline ;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
if ( ! s . sceneViewEditing )
return ;
var mat = p . target . transform . localToWorldMatrix ;
EditorGUI . BeginChangeCheck ( ) ;
switch ( EditMode . editMode )
Handle_InfluenceEditing ( s , p , o ) ;
InfluenceVolumeUI . DrawHandles_EditBase ( s . influenceVolume , p . targetData . influenceVolume , o , mat , p . targetData ) ;
Handle_InfluenceFadeEditing ( s , p , o , InfluenceType . Standard ) ;
InfluenceVolumeUI . DrawHandles_EditInfluence ( s . influenceVolume , p . targetData . influenceVolume , o , mat , p . targetData ) ;
Handle_InfluenceFadeEditing ( s , p , o , InfluenceType . Normal ) ;
InfluenceVolumeUI . DrawHandles_EditInfluenceNormal ( s . influenceVolume , p . targetData . influenceVolume , o , mat , p . targetData ) ;
break ;
// Origin editing
case EditMode . SceneViewEditMode . ReflectionProbeOrigin :
if ( EditorGUI . EndChangeCheck ( ) )
Repaint ( ) ;
}
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 . influenceVolume . boxBlendDistancePositive ;
probeBlendDistanceNegative = sp . targetData . influenceVolume . boxBlendDistanceNegative ;
color = k_GizmoThemeColorInfluenceBlend ;
break ;
}
case InfluenceType . Normal :
{
alternativeBlendBox = s . alternativeBoxBlendNormalHandle ;
sphereHandle = s . sphereBlendNormalHandle ;
probeBlendDistancePositive = sp . targetData . influenceVolume . boxBlendNormalDistancePositive ;
probeBlendDistanceNegative = sp . targetData . influenceVolume . boxBlendNormalDistanceNegative ;
color = k_GizmoThemeColorInfluenceNormalBlend ;
break ;
}
}
var mat = Handles . matrix ;
var col = Handles . color ;
Handles . matrix = HDReflectionProbeEditorUtility . GetLocalSpace ( sp . target ) ;
switch ( ( Shape ) sp . influenceVolume . shape . enumValueIndex )
{
case Shape . 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 Shape . Sphere :
{
sphereHandle . center = sp . target . center ;
sphereHandle . radius = Mathf . Clamp ( sp . targetData . influenceVolume . sphereRadius - probeBlendDistancePositive . x , 0 , sp . targetData . influenceVolume . sphereRadius ) ;
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 . influenceVolume . sphereRadius ;
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 . influenceVolume . boxBlendDistancePositive . vector3Value = probeBlendDistancePositive ;
sp . influenceVolume . boxBlendDistanceNegative . vector3Value = probeBlendDistanceNegative ;
//save advanced/simplified saved data
if ( sp . influenceVolume . editorAdvancedModeEnabled . boolValue )
{
sp . influenceVolume . editorAdvancedModeBlendDistancePositive . vector3Value = probeBlendDistancePositive ;
sp . influenceVolume . editorAdvancedModeBlendDistanceNegative . vector3Value = probeBlendDistanceNegative ;
}
else
{
sp . influenceVolume . editorSimplifiedModeBlendDistance . floatValue = probeBlendDistancePositive . x ;
}
break ;
}
case InfluenceType . Normal :
{
sp . influenceVolume . boxBlendNormalDistancePositive . vector3Value = probeBlendDistancePositive ;
sp . influenceVolume . boxBlendNormalDistanceNegative . vector3Value = probeBlendDistanceNegative ;
//save advanced/simplified saved data
if ( sp . influenceVolume . editorAdvancedModeEnabled . boolValue )
{
sp . influenceVolume . editorAdvancedModeBlendNormalDistancePositive . vector3Value = probeBlendDistancePositive ;
sp . influenceVolume . editorAdvancedModeBlendNormalDistanceNegative . vector3Value = probeBlendDistanceNegative ;
}
else
{
sp . influenceVolume . editorSimplifiedModeBlendNormalDistance . floatValue = probeBlendDistancePositive . x ;
}
break ;
}
}
sp . Apply ( ) ;
}
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 ( ( Shape ) sp . influenceVolume . shape . enumValueIndex )
{
case Shape . Box :
{
s . alternativeBoxInfluenceHandle . center = sp . target . center ;
s . alternativeBoxInfluenceHandle . size = sp . target . size ;
EditorGUI . BeginChangeCheck ( ) ;
s . alternativeBoxInfluenceHandle . DrawHandle ( ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
Undo . RecordObject ( sp . target , "Modified Reflection Probe AABB" ) ;
Undo . RecordObject ( sp . targetData , "Modified Reflection Probe AABB" ) ;
Vector3 center ;
Vector3 size ;
center = s . alternativeBoxInfluenceHandle . center ;
size = s . alternativeBoxInfluenceHandle . 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 Shape . Sphere :
{
s . sphereInfluenceHandle . center = sp . target . center ;
s . sphereInfluenceHandle . radius = sp . targetData . influenceVolume . sphereRadius ;
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 . influenceVolume . sphereRadius = influenceRadius ;
//ApplyConstraintsOnTargets(s, sp, o);
EditorUtility . SetDirty ( sp . target ) ;
EditorUtility . SetDirty ( sp . targetData ) ;
}
break ;
}
}
Handles . matrix = mat ;
Handles . color = col ;
}
static void Handle_OriginEditing ( HDReflectionProbeUI s , SerializedHDReflectionProbe sp , Editor o )