static void DrawBoxFadeHandle(InfluenceVolumeUI s, SerializedInfluenceVolume d, Editor o, Object sourceAsset, Gizmo6FacesBox box, SerializedProperty positive, SerializedProperty negative) { box.center = d.offset.vector3Value - (positive.vector3Value - negative.vector3Value) * 0.5f; box.size = d.boxSize.vector3Value - positive.vector3Value - negative.vector3Value; box.allHandleControledByOne = !d.editorAdvancedModeEnabled.boolValue; EditorGUI.BeginChangeCheck(); box.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(sourceAsset, "Modified Influence Volume"); var influenceCenter = d.offset.vector3Value; var halfInfluenceSize = d.boxSize.vector3Value * .5f; var centerDiff = box.center - influenceCenter; var halfSizeDiff = halfInfluenceSize - box.size * .5f; var positiveNew = halfSizeDiff - centerDiff; var negativeNew = halfSizeDiff + centerDiff; var blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positiveNew, halfInfluenceSize)); var blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negativeNew, halfInfluenceSize)); positive.vector3Value = blendDistancePositive; negative.vector3Value = blendDistanceNegative; d.Apply(); } }
static void DrawBoxHandle(InfluenceVolumeUI s, SerializedInfluenceVolume d, Editor o, Object sourceAsset, Gizmo6FacesBox box) { box.center = d.offset.vector3Value; box.size = d.boxSize.vector3Value; EditorGUI.BeginChangeCheck(); box.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(sourceAsset, "Modified Base Volume AABB"); d.offset.vector3Value = box.center; var size = box.size; Vector3 blendPositive = d.boxBlendDistancePositive.vector3Value; Vector3 blendNegative = d.boxBlendDistanceNegative.vector3Value; Vector3 blendNormalPositive = d.boxBlendNormalDistancePositive.vector3Value; Vector3 blendNormalNegative = d.boxBlendNormalDistanceNegative.vector3Value; for (int i = 0; i < 3; ++i) { size[i] = Mathf.Max(0f, size[i]); } d.boxSize.vector3Value = size; Vector3 halfSize = size * .5f; for (int i = 0; i < 3; ++i) { blendPositive[i] = Mathf.Clamp(blendPositive[i], 0f, halfSize[i]); blendNegative[i] = Mathf.Clamp(blendNegative[i], 0f, halfSize[i]); blendNormalPositive[i] = Mathf.Clamp(blendNormalPositive[i], 0f, halfSize[i]); blendNormalNegative[i] = Mathf.Clamp(blendNormalNegative[i], 0f, halfSize[i]); } d.boxBlendDistancePositive.vector3Value = blendPositive; d.boxBlendDistanceNegative.vector3Value = blendNegative; d.boxBlendNormalDistancePositive.vector3Value = blendNormalPositive; d.boxBlendNormalDistanceNegative.vector3Value = blendNormalNegative; if (d.editorAdvancedModeEnabled.boolValue) { d.editorAdvancedModeBlendDistancePositive.vector3Value = d.boxBlendDistancePositive.vector3Value; d.editorAdvancedModeBlendDistanceNegative.vector3Value = d.boxBlendDistanceNegative.vector3Value; d.editorAdvancedModeBlendNormalDistancePositive.vector3Value = d.boxBlendNormalDistancePositive.vector3Value; d.editorAdvancedModeBlendNormalDistanceNegative.vector3Value = d.boxBlendNormalDistanceNegative.vector3Value; } else { d.editorSimplifiedModeBlendDistance.floatValue = Mathf.Min( d.boxBlendDistancePositive.vector3Value.x, d.boxBlendDistancePositive.vector3Value.y, d.boxBlendDistancePositive.vector3Value.z, d.boxBlendDistanceNegative.vector3Value.x, d.boxBlendDistanceNegative.vector3Value.y, d.boxBlendDistanceNegative.vector3Value.z); d.boxBlendDistancePositive.vector3Value = d.boxBlendDistanceNegative.vector3Value = Vector3.one * d.editorSimplifiedModeBlendDistance.floatValue; d.editorSimplifiedModeBlendNormalDistance.floatValue = Mathf.Min( d.boxBlendNormalDistancePositive.vector3Value.x, d.boxBlendNormalDistancePositive.vector3Value.y, d.boxBlendNormalDistancePositive.vector3Value.z, d.boxBlendNormalDistanceNegative.vector3Value.x, d.boxBlendNormalDistanceNegative.vector3Value.y, d.boxBlendNormalDistanceNegative.vector3Value.z); d.boxBlendNormalDistancePositive.vector3Value = d.boxBlendNormalDistanceNegative.vector3Value = Vector3.one * d.editorSimplifiedModeBlendNormalDistance.floatValue; } d.Apply(); } }