microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Provide a StateChanged event in the ManipulationHandler #4911

Closed camnewnham closed 9 months ago

camnewnham commented 5 years ago

Describe the problem

PhysX.Bake gets called when scaling objects. When object colliders have high vertex counts (i.e. a convex mesh collider created from a CAD model), it is advantageous to disable the collider when scaling begins, and reapply it when it finishes to avoid this massive performance hit.

Describe the solution you'd like

A UnityEvent exposed when the state is changed, or even simply an editor toggle to disable the collider when scaling begins and re-enable it when it ends. Or both.

Describe alternatives you've considered

Copying and customizing the ManipulationHandler, making the State class public and providing an event triggered by the setter. https://gist.github.com/camnewnham/86da46211982b07c28d1be3e9dfa4ba9. Relevant lines:

        public event Action<State, State> CurrentStateChanged;
        public State CurrentState
        {
            get
            {
                return _currentState;
            }
            set
            {
                if (_currentState != value)
                {
                    CurrentStateChanged?.Invoke(_currentState, value);
                    _currentState = value;
                }
            }
        }
        private void _OnCurrentStateChanged(MyManipulationHandler.State oldstate, MyManipulationHandler.State newstate)
        {
            if (!oldstate.HasFlag(MyManipulationHandler.State.Scaling) && newstate.HasFlag(MyManipulationHandler.State.Scaling))
            {
                _meshCollider = this.GetComponent<MeshCollider>();
                if (_meshCollider != null && _meshCollider.enabled)
                {
                    _meshCollider.enabled = false;
                }
            }
            else if (oldstate.HasFlag(MyManipulationHandler.State.Scaling) && !newstate.HasFlag(MyManipulationHandler.State.Scaling))
            {
                if (_meshCollider != null && !_meshCollider.enabled)
                {
                    _meshCollider.enabled = true;
                }
            }
        }

Additional context

Reproduced for Julia at Hack Week.

Zee2 commented 3 years ago

Looking through backlog; is this specifically for ManipulationHandler or is for ObjectManipulator? We've deprecated ManipulationHandler for ObjectManipulator, so should this be closed won't-fix?

IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all-new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visit https://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!