static void DrawBoxFadeHandle(SerializedInfluenceVolume serialized, Editor owner, Transform transform, HierarchicalBox box, SerializedProperty positive, SerializedProperty negative) { using (new Handles.DrawingScope(Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one))) { box.center = -(positive.vector3Value - negative.vector3Value) * 0.5f; box.size = serialized.boxSize.vector3Value - positive.vector3Value - negative.vector3Value; box.monoHandle = !serialized.editorAdvancedModeEnabled.boolValue; EditorGUI.BeginChangeCheck(); box.DrawHandle(); box.DrawHull(true); if (EditorGUI.EndChangeCheck()) { var influenceCenter = Vector3.zero; var halfInfluenceSize = serialized.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; } } }
static void DrawGizmosSelected(DensityVolume densityVolume, GizmoType gizmoType) { if (s_BlendBox == null || s_BlendBox.Equals(null) || s_ShapeBox == null || s_ShapeBox.Equals(null)) { return; } Debug.Log(gizmoType); using (new Handles.DrawingScope(Matrix4x4.TRS(densityVolume.transform.position, densityVolume.transform.rotation, Vector3.one))) { // Blend box s_BlendBox.center = CenterBlendLocalPosition(densityVolume); s_BlendBox.size = BlendSize(densityVolume); Color baseColor = densityVolume.parameters.albedo; baseColor.a = 8 / 255f; s_BlendBox.baseColor = baseColor; s_BlendBox.DrawHull(EditMode.editMode == k_EditBlend); // Bounding box. s_ShapeBox.center = Vector3.zero; s_ShapeBox.size = densityVolume.parameters.size; s_ShapeBox.DrawHull(EditMode.editMode == k_EditShape); } }
void OnSceneGUI() { for (int i = 0; i < m_TypedTargets.Length; ++i) { var comp = m_TypedTargets[i]; var tr = comp.transform; var prox = comp.proxyVolume; using (new Handles.DrawingScope(Matrix4x4.TRS(Vector3.zero, tr.rotation, Vector3.one))) { switch (prox.shape) { case ProxyShape.Box: m_BoxHandle.center = Quaternion.Inverse(tr.rotation) * tr.position; m_BoxHandle.size = prox.boxSize; EditorGUI.BeginChangeCheck(); m_BoxHandle.DrawHull(true); m_BoxHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new Object[] { tr, comp }, "Update Proxy Volume Size"); tr.position = tr.rotation * m_BoxHandle.center; prox.boxSize = m_BoxHandle.size; } break; case ProxyShape.Sphere: m_SphereHandle.center = Quaternion.Inverse(tr.rotation) * tr.position; m_SphereHandle.radius = prox.sphereRadius; EditorGUI.BeginChangeCheck(); m_SphereHandle.DrawHull(true); m_SphereHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(new Object[] { tr, comp }, "Update Proxy Volume Size"); tr.position = tr.rotation * m_SphereHandle.center; prox.sphereRadius = m_SphereHandle.radius; } break; case ProxyShape.Infinite: break; } } } }
static void DrawGizmosSelected(DensityVolume densityVolume, GizmoType gizmoType) { using (new Handles.DrawingScope(Matrix4x4.TRS(densityVolume.transform.position, densityVolume.transform.rotation, Vector3.one))) { // Blend box HierarchicalBox blendBox = blendBoxes[densityVolume]; blendBox.center = CenterBlendLocalPosition(densityVolume); blendBox.size = BlendSize(densityVolume); Color baseColor = densityVolume.parameters.albedo; baseColor.a = 8 / 255f; blendBox.baseColor = baseColor; blendBox.DrawHull(EditMode.editMode == k_EditBlend); // Bounding box. HierarchicalBox shapeBox = shapeBoxes[densityVolume]; shapeBox.center = Vector3.zero; shapeBox.size = densityVolume.parameters.size; shapeBox.DrawHull(EditMode.editMode == k_EditShape); } }
static void DrawGizmosSelected(VolumeFalloff volumeFalloff, GizmoType gizmoType) { Matrix4x4 m = volumeFalloff.isTransformScaleUsed ? volumeFalloff.transform.localToWorldMatrix : Matrix4x4.TRS(volumeFalloff.transform.position, volumeFalloff.transform.rotation, Vector3.one); m = m * Matrix4x4.TRS(volumeFalloff.center, Quaternion.identity, Vector3.one); using (new Handles.DrawingScope(m)) { // Blend box s_BlendBox.center = ComputeCenterBlendLocalPosition(volumeFalloff); s_BlendBox.size = ComputeBlendSize(volumeFalloff); Color baseColor = volumeFalloff.debugColor; baseColor.a = 8.0f / 255.0f; s_BlendBox.baseColor = baseColor; s_BlendBox.DrawHull(editMode == VolumeFalloffEditMode.Falloff); // Bounding box. s_ShapeBox.center = new float3(0.0f, 0.0f, 0.0f); s_ShapeBox.size = volumeFalloff.size; s_ShapeBox.DrawHull(editMode == VolumeFalloffEditMode.Bounds); } }
static void DrawBoxHandle(SerializedInfluenceVolume serialized, Editor owner, Transform transform, HierarchicalBox box) { using (new Handles.DrawingScope(Matrix4x4.TRS(Vector3.zero, transform.rotation, Vector3.one))) { box.center = Quaternion.Inverse(transform.rotation) * transform.position; box.size = serialized.boxSize.vector3Value; EditorGUI.BeginChangeCheck(); box.DrawHull(true); box.DrawHandle(); if (EditorGUI.EndChangeCheck()) { var newPosition = transform.rotation * box.center; Undo.RecordObject(transform, "Moving Influence"); transform.position = newPosition; // Clamp blend distances var blendPositive = serialized.boxBlendDistancePositive.vector3Value; var blendNegative = serialized.boxBlendDistanceNegative.vector3Value; var blendNormalPositive = serialized.boxBlendNormalDistancePositive.vector3Value; var blendNormalNegative = serialized.boxBlendNormalDistanceNegative.vector3Value; var size = box.size; serialized.boxSize.vector3Value = size; var 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]); } serialized.boxBlendDistancePositive.vector3Value = blendPositive; serialized.boxBlendDistanceNegative.vector3Value = blendNegative; serialized.boxBlendNormalDistancePositive.vector3Value = blendNormalPositive; serialized.boxBlendNormalDistanceNegative.vector3Value = blendNormalNegative; if (serialized.editorAdvancedModeEnabled.boolValue) { serialized.editorAdvancedModeBlendDistancePositive.vector3Value = serialized.boxBlendDistancePositive.vector3Value; serialized.editorAdvancedModeBlendDistanceNegative.vector3Value = serialized.boxBlendDistanceNegative.vector3Value; serialized.editorAdvancedModeBlendNormalDistancePositive.vector3Value = serialized.boxBlendNormalDistancePositive.vector3Value; serialized.editorAdvancedModeBlendNormalDistanceNegative.vector3Value = serialized.boxBlendNormalDistanceNegative.vector3Value; } else { serialized.editorSimplifiedModeBlendDistance.floatValue = Mathf.Min( serialized.boxBlendDistancePositive.vector3Value.x, serialized.boxBlendDistancePositive.vector3Value.y, serialized.boxBlendDistancePositive.vector3Value.z, serialized.boxBlendDistanceNegative.vector3Value.x, serialized.boxBlendDistanceNegative.vector3Value.y, serialized.boxBlendDistanceNegative.vector3Value.z); serialized.boxBlendDistancePositive.vector3Value = serialized.boxBlendDistanceNegative.vector3Value = Vector3.one * serialized.editorSimplifiedModeBlendDistance.floatValue; serialized.editorSimplifiedModeBlendNormalDistance.floatValue = Mathf.Min( serialized.boxBlendNormalDistancePositive.vector3Value.x, serialized.boxBlendNormalDistancePositive.vector3Value.y, serialized.boxBlendNormalDistancePositive.vector3Value.z, serialized.boxBlendNormalDistanceNegative.vector3Value.x, serialized.boxBlendNormalDistanceNegative.vector3Value.y, serialized.boxBlendNormalDistanceNegative.vector3Value.z); serialized.boxBlendNormalDistancePositive.vector3Value = serialized.boxBlendNormalDistanceNegative.vector3Value = Vector3.one * serialized.editorSimplifiedModeBlendNormalDistance.floatValue; } } } }