Ejemplo n.º 1
0
        void OnSceneGUI()
        {
            if (monoBehaviour == null)
            {
                return;
            }

            if (is2D.boolValue)
            {
                Transform handlesTransform = monoBehaviour.transform;

                // handlesTransform.rotation = Quaternion.identity;
                Handles.matrix = handlesTransform.localToWorldMatrix;

                capsuleHandle.radius = bodySize.vector2Value.x / 2f;
                capsuleHandle.height = bodySize.vector2Value.y;

                capsuleHandle.center = Vector3.up * capsuleHandle.height / 2f;

                capsuleHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y;

                capsuleHandle.heightAxis = CapsuleBoundsHandle.HeightAxis.Y;
                capsuleHandle.DrawHandle();

                Handles.matrix = Matrix4x4.identity;
            }
            else
            {
                Handles.matrix = monoBehaviour.transform.localToWorldMatrix;

                capsuleHandle.radius = bodySize.vector2Value.x / 2f;
                capsuleHandle.height = bodySize.vector2Value.y;

                capsuleHandle.center = Vector3.up * capsuleHandle.height / 2f;

                capsuleHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y | PrimitiveBoundsHandle.Axes.Z;


                capsuleHandle.heightAxis = CapsuleBoundsHandle.HeightAxis.Y;
                capsuleHandle.DrawHandle();

                Handles.matrix = Matrix4x4.identity;
            }
        }
Ejemplo n.º 2
0
    public static void CapsuleBoundsHandle(Vector3 center, Quaternion rotation, Vector3 size, ref float height, ref float radius, CapsuleBoundsHandle.HeightAxis heightAxis, PrimitiveBoundsHandle.Axes handleAxes, Color handleColor, Color wireframeColor)
    {
        Matrix4x4 trs = Matrix4x4.TRS(center, rotation, size);

        using (new Handles.DrawingScope(trs)) {
            capsuleBoundsHandle.heightAxis     = heightAxis;
            capsuleBoundsHandle.axes           = handleAxes;
            capsuleBoundsHandle.radius         = radius;
            capsuleBoundsHandle.height         = height;
            capsuleBoundsHandle.handleColor    = handleColor;
            capsuleBoundsHandle.wireframeColor = wireframeColor;
            capsuleBoundsHandle.DrawHandle();
            radius = capsuleBoundsHandle.radius;
            height = capsuleBoundsHandle.height;
        }
    }
Ejemplo n.º 3
0
        protected override void DrawHandles()
        {
            CapsuleOverlapCollider script = (CapsuleOverlapCollider)target;

            //TODO there is a problem with bound position when rotate and offsets the collider

            //Rotate world so the bounds handle can fit the gizmo and selected axis
            Matrix4x4 initialMatrix = Handles.matrix;
            Matrix4x4 trs           = Matrix4x4.TRS(script.transform.position, script.transform.rotation, Vector3.one);

            Handles.matrix = trs;

            //Set bounds
            _boxBounds.radius = script.GetRadius();
            _boxBounds.height = script.GetHeight();
            _boxBounds.center = script.Offset;
            switch (script.Axis)
            {
            case CapsuleOverlapCollider.DirAxisEnum.XAxis: _boxBounds.heightAxis = CapsuleBoundsHandle.HeightAxis.X; break;

            case CapsuleOverlapCollider.DirAxisEnum.YAxis: _boxBounds.heightAxis = CapsuleBoundsHandle.HeightAxis.Y; break;

            case CapsuleOverlapCollider.DirAxisEnum.ZAxis: _boxBounds.heightAxis = CapsuleBoundsHandle.HeightAxis.Z; break;
            }
            _boxBounds.handleColor = _boxBounds.wireframeColor = Color.green;

            //Draw bounds
            EditorGUI.BeginChangeCheck();
            _boxBounds.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                //Record the target object before setting new values so changes can be undone/redone
                Undo.RecordObject(script, "Change Bounds");

                //Apply changes
                script.Radius = NewRadius(script, _boxBounds.radius);
                script.Height = NewHeight(script, _boxBounds.height);
                script.Offset = _boxBounds.center;
            }

            //Reset World
            Handles.matrix = initialMatrix;
        }
Ejemplo n.º 4
0
    protected virtual void OnSceneGUI()
    {
        CapsuleBoundsExample boundsExample = (CapsuleBoundsExample)target;

        m_CapsuleBoundsHandle.center         = boundsExample.transform.position + boundsExample.Center;
        m_CapsuleBoundsHandle.radius         = boundsExample.Radius;
        m_CapsuleBoundsHandle.height         = boundsExample.Height;
        m_CapsuleBoundsHandle.handleColor    = Color.green;
        m_CapsuleBoundsHandle.wireframeColor = Color.green;

        EditorGUI.BeginChangeCheck();
        m_CapsuleBoundsHandle.DrawHandle();
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(boundsExample, "Change Bounds");
            boundsExample.Center = m_CapsuleBoundsHandle.center;
            boundsExample.Radius = m_CapsuleBoundsHandle.radius;
            boundsExample.Height = m_CapsuleBoundsHandle.height;
        }
    }
Ejemplo n.º 5
0
        void OnSceneGUI()
        {
            if (monoBehaviour == null)
            {
                return;
            }

            Handles.matrix = monoBehaviour.transform.localToWorldMatrix;

            capsuleHandle.radius = bodySize.vector2Value.x / 2f;
            capsuleHandle.height = bodySize.vector2Value.y;

            capsuleHandle.center = Vector3.up * capsuleHandle.height / 2f;

            capsuleHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y | PrimitiveBoundsHandle.Axes.Z;


            capsuleHandle.heightAxis = CapsuleBoundsHandle.HeightAxis.Y;
            capsuleHandle.DrawHandle();

            Handles.matrix = Matrix4x4.identity;
        }
        public override void OnSceneGUI()
        {
            if (!action.debug.Value)
            {
                return;
            }

            var color = Handles.color;

            Handles.color = action.debugColor.Value;

            EditorGUI.BeginChangeCheck();

            action.InitShapeCenter();

            var transform = action.cachedTransform;

            var newCenter = Handles.PositionHandle(action.center, transform != null ? transform.rotation : Quaternion.identity);

            Handles.matrix = Matrix4x4.TRS(action.center, transform != null ? transform.rotation : Quaternion.identity, Vector3.one);

            switch (action.shape)
            {
            case FindOverlaps.Shape.Box:

                if (boxBoundsHandle == null)
                {
                    boxBoundsHandle = new BoxBoundsHandle();
                }

                boxBoundsHandle.center = Vector3.zero;
                boxBoundsHandle.size   = action.box.Value;

                EditorGUI.BeginChangeCheck();
                boxBoundsHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    action.box.Value = boxBoundsHandle.size;
                }

                break;

            case FindOverlaps.Shape.Sphere:

                action.radius.Value = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, action.radius.Value);

                break;

            case FindOverlaps.Shape.Capsule:

                if (capsuleBoundsHandle == null)
                {
                    capsuleBoundsHandle = new CapsuleBoundsHandle();
                }

                capsuleBoundsHandle.center     = Vector3.zero;
                capsuleBoundsHandle.height     = action.height.Value;
                capsuleBoundsHandle.radius     = action.radius.Value;
                capsuleBoundsHandle.heightAxis = CapsuleBoundsHandle.HeightAxis.Y;

                EditorGUI.BeginChangeCheck();
                capsuleBoundsHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    action.radius.Value = capsuleBoundsHandle.radius;
                    action.height.Value = capsuleBoundsHandle.height;
                }

                break;
            }

            Handles.color = color;

            if (EditorGUI.EndChangeCheck())
            {
                action.offset.Value = transform == null ?
                                      newCenter : transform.InverseTransformPoint(newCenter);

                GUI.changed = true;
            }
        }
Ejemplo n.º 7
0
        void OnSceneGUI()
        {
            var hotControl = GUIUtility.hotControl;

            switch (Event.current.GetTypeForControl(hotControl))
            {
            case EventType.MouseDrag:
                m_DraggingControlID = hotControl;
                return;

            case EventType.MouseUp:
                m_DraggingControlID = 0;
                return;

            case EventType.Repaint:
                break;

            default:
                return;
            }

            var shape = target as PhysicsShapeAuthoring;

            var handleColor  = shape.enabled ? k_ShapeHandleColor : k_ShapeHandleColorDisabled;
            var handleMatrix = shape.GetShapeToWorldMatrix();

            using (new Handles.DrawingScope(handleColor, handleMatrix))
            {
                switch (shape.ShapeType)
                {
                case ShapeType.Box:
                    var boxGeometry = shape.GetBakedBoxProperties();
                    s_Box.BevelRadius = boxGeometry.BevelRadius;
                    s_Box.center      = float3.zero;
                    s_Box.size        = boxGeometry.Size;
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(boxGeometry.Center, boxGeometry.Orientation, 1f))))
                        s_Box.DrawHandle();
                    break;

                case ShapeType.Capsule:
                    s_Capsule.center = float3.zero;
                    s_Capsule.height = s_Capsule.radius = 0f;
                    var capsuleGeometry = shape.GetBakedCapsuleProperties(out var center, out var height, out var orientation);
                    s_Capsule.height = height;
                    s_Capsule.radius = capsuleGeometry.Radius;
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(center, orientation, 1f))))
                        s_Capsule.DrawHandle();
                    break;

                case ShapeType.Sphere:
                    var sphereGeometry = shape.GetBakedSphereProperties(out orientation);
                    s_Sphere.center = float3.zero;
                    s_Sphere.radius = sphereGeometry.Radius;
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(sphereGeometry.Center, orientation, 1f))))
                        s_Sphere.DrawHandle();
                    break;

                case ShapeType.Cylinder:
                    var cylinderGeometry = shape.GetBakedCylinderProperties();
                    s_Cylinder.center      = float3.zero;
                    s_Cylinder.Height      = cylinderGeometry.Height;
                    s_Cylinder.Radius      = cylinderGeometry.Radius;
                    s_Cylinder.SideCount   = cylinderGeometry.SideCount;
                    s_Cylinder.BevelRadius = cylinderGeometry.BevelRadius;
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(cylinderGeometry.Center, cylinderGeometry.Orientation, 1f))))
                        s_Cylinder.DrawHandle();
                    break;

                case ShapeType.Plane:
                    shape.GetPlaneProperties(out center, out var size2, out orientation);
                    s_Plane.center = float3.zero;
                    s_Plane.size   = new float3(size2.x, 0f, size2.y);
                    var m = math.mul(shape.transform.localToWorldMatrix, float4x4.TRS(center, orientation, 1f));
                    using (new Handles.DrawingScope(m))
                        s_Plane.DrawHandle();
                    var right = math.mul(m, new float4 {
                        x = 1f
                    }).xyz;
                    var forward = math.mul(m, new float4 {
                        z = 1f
                    }).xyz;
                    var normal = math.cross(math.normalizesafe(forward), math.normalizesafe(right))
                                 * 0.5f * math.lerp(math.length(right) * size2.x, math.length(forward) * size2.y, 0.5f);
                    using (new Handles.DrawingScope(float4x4.identity))
                        Handles.DrawLine(m.c3.xyz, m.c3.xyz + normal);
                    break;

                case ShapeType.ConvexHull:
                    if (Event.current.type != EventType.Repaint)
                    {
                        break;
                    }
                    var points = GetPreviewData(shape).Edges;
                    // TODO: follow transformation until new preview is generated if e.g., user is dragging handles
                    if (points.Length > 0)
                    {
                        Handles.DrawLines(points);
                    }
                    break;

                case ShapeType.Mesh:
                    if (Event.current.type != EventType.Repaint)
                    {
                        break;
                    }
                    points = GetPreviewData(shape).Edges;
                    if (points.Length > 0)
                    {
                        Handles.DrawLines(points);
                    }
                    break;

                default:
                    throw new UnimplementedShapeException(shape.ShapeType);
                }
            }
        }
Ejemplo n.º 8
0
        private void DrawColliderHandles()
        {
            if (!tgt.showColliderSettings)
            {
                return;
            }

            PreviewBone bone = tgt.previewBones[tgt.selectedBoneID];

            Quaternion globalRot = tgt.transform.rotation * bone.rotation;

            if (tgt.rotationHandle)
            {
                EditorGUI.BeginChangeCheck();
                Quaternion rot = Handles.RotationHandle(globalRot, bone.tr.position);
                if (EditorGUI.EndChangeCheck())
                {
                    bone.rotation = Quaternion.Inverse(tgt.transform.rotation) * rot;
                }
            }

            Matrix4x4 handleMatrix = Matrix4x4.TRS(bone.tr.position, globalRot, Vector3.one);

            using (new Handles.DrawingScope(handleMatrix)) {
                switch (bone.colliderType)
                {
                case ColliderType.Box:
                    boxBoundsHandle.center = bone.bounds.center;
                    boxBoundsHandle.size   = bone.bounds.size;
                    EditorGUI.BeginChangeCheck();
                    boxBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        bone.bounds.center = boxBoundsHandle.center;
                        bone.bounds.size   = boxBoundsHandle.size;
                    }
                    break;

                case ColliderType.Capsule:
                    capsuleBoundsHandle.center     = bone.bounds.center;
                    capsuleBoundsHandle.height     = bone.capsuleBounds.height;
                    capsuleBoundsHandle.radius     = bone.capsuleBounds.radius;
                    capsuleBoundsHandle.heightAxis = (CapsuleBoundsHandle.HeightAxis)bone.capsuleBounds.direction;
                    EditorGUI.BeginChangeCheck();
                    capsuleBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        bone.bounds.center           = capsuleBoundsHandle.center;
                        bone.capsuleBounds.height    = capsuleBoundsHandle.height;
                        bone.capsuleBounds.radius    = capsuleBoundsHandle.radius;
                        bone.capsuleBounds.direction = (CapsuleDirection)capsuleBoundsHandle.heightAxis;
                    }
                    break;

                case ColliderType.Sphere:
                    sphereBoundsHandle.center = bone.bounds.center;
                    sphereBoundsHandle.radius = bone.capsuleBounds.radius;
                    EditorGUI.BeginChangeCheck();
                    sphereBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        bone.bounds.center        = sphereBoundsHandle.center;
                        bone.capsuleBounds.radius = sphereBoundsHandle.radius;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 9
0
        void OnSceneGUI()
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            var shape = target as PhysicsShape;

            shape.GetBakeTransformation(out var linearScalar, out var radiusScalar);

            var handleColor  = shape.enabled ? k_ShapeHandleColor : k_ShapeHandleColorDisabled;
            var handleMatrix = new float4x4(new RigidTransform(shape.transform.rotation, shape.transform.position));

            using (new Handles.DrawingScope(handleColor, handleMatrix))
            {
                switch (shape.ShapeType)
                {
                case ShapeType.Box:
                    shape.GetBoxProperties(out var center, out var size, out EulerAngles orientation);
                    s_Box.ConvexRadius = shape.ConvexRadius * radiusScalar;
                    s_Box.center       = float3.zero;
                    s_Box.size         = math.abs(size * linearScalar);
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(center * linearScalar, orientation, 1f))))
                        s_Box.DrawHandle();
                    break;

                case ShapeType.Capsule:
                    s_Capsule.center = float3.zero;
                    s_Capsule.height = s_Capsule.radius = 0f;
                    shape.GetCapsuleProperties(out center, out var height, out var radius, out orientation);
                    shape.GetCapsuleProperties(out var v0, out var v1, out radius);
                    var ax = (v0 - v1) * linearScalar;
                    s_Capsule.height = math.length(ax) + radius * radiusScalar * 2f;
                    s_Capsule.radius = radius * radiusScalar;
                    ax = math.normalizesafe(ax, new float3(0f, 0f, 1f));
                    var up = math.mul(orientation, math.up());
                    var m  = float4x4.TRS(center * linearScalar, quaternion.LookRotationSafe(ax, up), 1f);
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, m)))
                        s_Capsule.DrawHandle();
                    break;

                case ShapeType.Sphere:
                    shape.GetSphereProperties(out center, out radius, out orientation);
                    s_Sphere.center = float3.zero;
                    s_Sphere.radius = radius;
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(center * linearScalar, orientation, radiusScalar))))
                        s_Sphere.DrawHandle();
                    break;

                case ShapeType.Cylinder:
                    shape.GetCylinderProperties(out center, out height, out radius, out orientation);
                    s_ConvexCylinder.ConvexRadius = shape.ConvexRadius * radiusScalar;
                    s_ConvexCylinder.center       = float3.zero;
                    var s = math.abs(math.mul(math.inverse(orientation), linearScalar));
                    s_ConvexCylinder.Height = height * s.z;
                    s_ConvexCylinder.Radius = radius * math.cmax(s.xy);
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(center * linearScalar, orientation, 1f))))
                        s_ConvexCylinder.DrawHandle();
                    break;

                case ShapeType.Plane:
                    shape.GetPlaneProperties(out center, out var size2, out orientation);
                    s_Plane.center = float3.zero;
                    s_Plane.size   = new float3(size2.x, 0, size2.y) * linearScalar;
                    using (new Handles.DrawingScope(math.mul(Handles.matrix, float4x4.TRS(center * linearScalar, orientation, 1f))))
                    {
                        Handles.DrawLine(
                            new float3(0f),
                            new float3(0f, math.lerp(math.cmax(size2), math.cmin(size2), 0.5f), 0) * 0.5f
                            );
                        s_Plane.DrawHandle();
                    }
                    break;

                case ShapeType.ConvexHull:
                case ShapeType.Mesh:
                    if (Event.current.type != EventType.Repaint)
                    {
                        break;
                    }
                    var mesh = GetPreviewMesh(shape);
                    if (mesh == null || mesh.vertexCount == 0)
                    {
                        break;
                    }
                    var localToWorld = new RigidTransform(shape.transform.rotation, shape.transform.position);
                    DrawMesh(mesh, float4x4.TRS(localToWorld.pos, localToWorld.rot, linearScalar));
                    break;

                default:
                    throw new UnimplementedShapeException(shape.ShapeType);
                }
            }
        }
Ejemplo n.º 10
0
    public void OnSceneGUI()
    {
        if (list.index != -1 && target != null)
        {
            EnRaycastManager   manager = (EnRaycastManager)target;
            SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(list.index);
            if (manager.m_Editable)
            {
                //EnRaycast enRaycast = element.
                var typeProp         = element.FindPropertyRelative("m_Type");
                var raycastTypeValue = (EnRaycast.RaycastType)typeProp.enumValueIndex;

                var origin          = element.FindPropertyRelative("m_Origin");
                var direction       = element.FindPropertyRelative("m_Direction");
                var maxDistance     = element.FindPropertyRelative("m_MaxDistance");
                var radius          = element.FindPropertyRelative("m_Radius");
                var height          = element.FindPropertyRelative("m_Height");
                var size            = element.FindPropertyRelative("m_Size");
                var heightAxis      = element.FindPropertyRelative("m_HeightAxis");
                var heightAxisValue = (CapsuleBoundsHandle.HeightAxis)heightAxis.enumValueIndex;

                GUIStyle style = new GUIStyle();
                style.normal.textColor = Color.black;

                var worldOrigin =
                    EnDebugExtension.RotatePoint(manager.transform, manager.transform.position + origin.vector3Value);
                var worldDirection = EnDebugExtension.RotateDirection(manager.transform, direction.vector3Value);

                var position1 = worldOrigin; //go.transform.position + origin.vector3Value;
                var position2 =
                    worldOrigin +
                    worldDirection *
                    maxDistance
                    .floatValue;     //go.transform.position + origin.vector3Value + (go.transform.rotation * direction.vector3Value) * maxDistance.floatValue;

                Vector3 destination = Vector3.zero;
                Vector3 heading     = Vector3.zero;

                //Origin
                Handles.Label(position1, manager.m_DrawText ? "Origin " + origin.vector3Value : "", style);
                origin.vector3Value =
                    EnDebugExtension.RotatePointInverse(manager.transform,
                                                        Handles.PositionHandle(position1, Quaternion.identity)) - manager.transform.position;

                //Destination
                Handles.Label(position2, manager.m_DrawText ? "Destination " + position2 : "", style);
                destination =
                    EnDebugExtension.RotatePointInverse(manager.transform,
                                                        Handles.PositionHandle(position2, Quaternion.identity)) - manager.transform.position;
                heading = destination - origin.vector3Value;
                maxDistance.floatValue = heading.magnitude;
                direction.vector3Value = heading / maxDistance.floatValue; //This is now the normalized direction.

                switch (raycastTypeValue)
                {
                case EnRaycast.RaycastType.Raycast:
                case EnRaycast.RaycastType.RaycastAll:
                case EnRaycast.RaycastType.RaycastNonAlloc:
                    break;

                case EnRaycast.RaycastType.CapsuleCast:
                case EnRaycast.RaycastType.CapsuleCastAll:
                case EnRaycast.RaycastType.CapsuleCastNonAlloc:
                    m_CapsuleBoundsHandle.center     = worldOrigin;
                    m_CapsuleBoundsHandle.radius     = radius.floatValue;
                    m_CapsuleBoundsHandle.height     = height.floatValue;
                    m_CapsuleBoundsHandle.heightAxis = (CapsuleBoundsHandle.HeightAxis)heightAxis.enumValueIndex;
                    EditorGUI.BeginChangeCheck();
                    m_CapsuleBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        //Undo.RecordObject(element, "Change Bounds");
                        origin.vector3Value =
                            EnDebugExtension.RotatePointInverse(manager.transform, m_CapsuleBoundsHandle.center) -
                            manager.transform.position;
                        radius.floatValue = m_CapsuleBoundsHandle.radius;
                        height.floatValue = m_CapsuleBoundsHandle.height;
                    }

                    break;

                case EnRaycast.RaycastType.SphereCast:
                case EnRaycast.RaycastType.SphereCastAll:
                case EnRaycast.RaycastType.SphereCastNonAlloc:
                    m_SphereBoundsHandle.center = worldOrigin;
                    m_SphereBoundsHandle.radius = radius.floatValue;
                    EditorGUI.BeginChangeCheck();
                    m_SphereBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        //Undo.RecordObject(element, "Change Bounds");
                        origin.vector3Value =
                            EnDebugExtension.RotatePointInverse(manager.transform, m_SphereBoundsHandle.center) -
                            manager.transform.position;
                        radius.floatValue = m_SphereBoundsHandle.radius;
                    }

                    break;

                case EnRaycast.RaycastType.BoxCast:
                case EnRaycast.RaycastType.BoxCastAll:
                case EnRaycast.RaycastType.BoxCastNonAlloc:
                    // copy the target object's data to the handle
                    m_BoxBoundsHandle.center = worldOrigin;
                    m_BoxBoundsHandle.size   = size.vector3Value;
                    // draw the handle
                    EditorGUI.BeginChangeCheck();
                    m_BoxBoundsHandle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        // record the target object before setting new values so changes can be undone/redone
                        //Undo.RecordObject((Object)element, "Change Bounds");
                        // copy the handle's updated data back to the target object
                        origin.vector3Value =
                            EnDebugExtension.RotatePointInverse(manager.transform, m_BoxBoundsHandle.center) -
                            manager.transform.position;
                        size.vector3Value = m_BoxBoundsHandle.size;
                        //boundsExample.bounds = newBounds;
                    }

                    break;

                default:
                    break;
                }

                serializedObject.ApplyModifiedProperties();
            }

            if (target != null)
            {
                Handles.BeginGUI();
                Rect windowRect = new Rect(Screen.width - 215, Screen.height - 180, 200,
                                           EditorGUIUtility.singleLineHeight * 2f);
                GUILayout.Window(667, windowRect, DrawWindowInspector, "Raycast Tool");
                Handles.EndGUI();
            }
        }
    }
Ejemplo n.º 11
0
        private void OnSceneGUI()
        {
            if (!script.enabled || !script.showGizmos)
            {
                return;
            }

            Handles.matrix             = script.transform.localToWorldMatrix;
            Handles.color              = script.gizmosColor;
            textStyle.normal.textColor = script.gizmosColor;

            boxBoundsHandle.size           = script.boxAreaBounds.size;
            sphereBoundsHandle.radius      = script.sphereAreaRadius;
            capsuleBoundsHandle.radius     = script.capsuleAreaRadius;
            capsuleBoundsHandle.height     = script.capsuleHeight;
            capsuleBoundsHandle.heightAxis = (CapsuleBoundsHandle.HeightAxis)script.capsuleHeightAxis;

            EditorGUI.BeginChangeCheck();

            switch (script.areaType)
            {
            case AreaType.Box:
                Handles.Label(boxBoundsHandle.center + boxBoundsHandle.size / 2, script.AreaName, textStyle);
                if (!script.lockCenter)
                {
                    boxBoundsHandle.center = Handles.PositionHandle(script.boxAreaBounds.center, Quaternion.identity);
                }
                else
                {
                    boxBoundsHandle.center = script.boxAreaBounds.center;
                }
                boxBoundsHandle.DrawHandle();
                break;

            case AreaType.Sphere:
                Handles.Label(Vector3.up * script.sphereAreaRadius, script.AreaName, textStyle);
                if (!script.lockCenter)
                {
                    sphereBoundsHandle.center = Handles.PositionHandle(script.sphereCenter, Quaternion.identity);
                }
                else
                {
                    sphereBoundsHandle.center = script.sphereCenter;
                }
                sphereBoundsHandle.DrawHandle();
                break;

            case AreaType.Capsule:
                Handles.Label(capsuleBoundsHandle.center, script.AreaName, textStyle);
                if (!script.lockCenter)
                {
                    capsuleBoundsHandle.center = Handles.PositionHandle(script.capsuleCenter, Quaternion.identity);
                }
                else
                {
                    capsuleBoundsHandle.center = script.capsuleCenter;
                }
                capsuleBoundsHandle.DrawHandle();
                break;
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Changed Detection Area");
                Bounds newBounds = new Bounds();
                if (!script.lockCenter)
                {
                    script.sphereCenter  = sphereBoundsHandle.center;
                    script.capsuleCenter = capsuleBoundsHandle.center;
                    newBounds.center     = boxBoundsHandle.center;
                }
                else
                {
                    newBounds.center = script.boxAreaBounds.center;
                }
                newBounds.size           = boxBoundsHandle.size;
                script.boxAreaBounds     = newBounds;
                script.sphereAreaRadius  = sphereBoundsHandle.radius;
                script.capsuleHeight     = capsuleBoundsHandle.height;
                script.capsuleAreaRadius = capsuleBoundsHandle.radius;
                script.capsuleHeightAxis = (DetectionArea.Axis)capsuleBoundsHandle.heightAxis;
                EditorUtility.SetDirty(target);
            }
        }