我如何修改GrabPointer预制件,以允许场景中的默认对撞机超过64个?

问题描述 投票:0回答:2

我对this有类似的问题,但是对于SpherePointer。

使用由NuGet for Unity收购的MRTK 2.2,我几乎在每一帧都收到此警告:

Maximum number of 64 colliders found in SpherePointer overlap query. Consider increasing the query buffer size in the pointer profile.
UnityEngine.Debug:LogWarning(Object)
Microsoft.MixedReality.Toolkit.Input.SpherePointerQueryInfo:TryUpdateQueryBufferForLayerMask(LayerMask, Vector3, QueryTriggerInteraction)
Microsoft.MixedReality.Toolkit.Input.SpherePointer:OnPreSceneQuery()
Microsoft.MixedReality.Toolkit.Input.FocusProvider:UpdatePointer(PointerData)
Microsoft.MixedReality.Toolkit.Input.FocusProvider:UpdatePointers()
Microsoft.MixedReality.Toolkit.Input.FocusProvider:Update()
Microsoft.MixedReality.Toolkit.<>c:<UpdateAllServices>b__63_0(IMixedRealityService)
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:ExecuteOnAllServices(IEnumerable`1, Action`1)
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:ExecuteOnAllServicesInOrder(Action`1)
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:UpdateAllServices()
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:Update()

我能够使用@Julia's响应成功删除PokePointer的类似警告,但我对GrabPointer预制件的使用方法感到困惑。

此预制件附加了SpherePointer脚本,但是不会在检查器中显示SceneQueryBufferSize属性,因为SpherePointer的自定义检查器(ShperePointerInspector.cs)无法公开它。

mrtk
2个回答
0
投票

很好的问题!看来您实际上已经发现了一个错误。请暂时使用以下代码解决此问题,我们将在短期内发布修复程序。跟踪此问题的位置在这里:[issue 6878] 9https://github.com/microsoft/MixedRealityToolkit-Unity/issues/6878)

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.MixedReality.Toolkit.Input.Editor;
using Microsoft.MixedReality.Toolkit.Input;
using UnityEditor;

namespace Microsoft.MixedReality.Toolkit.Input
{
    [CustomEditor(typeof(SpherePointer))]
    public class SpherePointerInspector : BaseControllerPointerInspector
    {
        private SerializedProperty sphereCastRadius;
        private SerializedProperty nearObjectMargin;
        private SerializedProperty grabLayerMasks;
        private SerializedProperty triggerInteraction;
        private SerializedProperty sceneQueryBufferSize;

        private bool spherePointerFoldout = true;

        protected override void OnEnable()
        {
            base.OnEnable();

            sphereCastRadius = serializedObject.FindProperty("sphereCastRadius");
            sceneQueryBufferSize = serializedObject.FindProperty("sceneQueryBufferSize");
            nearObjectMargin = serializedObject.FindProperty("nearObjectMargin");
            grabLayerMasks = serializedObject.FindProperty("grabLayerMasks");
            triggerInteraction = serializedObject.FindProperty("triggerInteraction");
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            spherePointerFoldout = EditorGUILayout.Foldout(spherePointerFoldout, "Sphere Pointer Settings", true);

            if (spherePointerFoldout)
            {
                using (new EditorGUI.IndentLevelScope())
                {
                    EditorGUILayout.PropertyField(sphereCastRadius);
                    EditorGUILayout.PropertyField(sceneQueryBufferSize);
                    EditorGUILayout.PropertyField(nearObjectMargin);
                    EditorGUILayout.PropertyField(triggerInteraction);
                    EditorGUILayout.PropertyField(grabLayerMasks, true);
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
    }
}

0
投票

感谢朱莉娅,

这是我想出的解决方案,因为我无法在项目中修改SpherePointerInspector.cs,因为MRTK是从NuGet获得的。我在GrabPointer.prefab的副本上用MySpherePointer.cs替换了SpherePointer.cs。

MySpherePointer.cs

using Microsoft.MixedReality.Toolkit.Input;

/// <summary>
/// This class exists soley to expose SpherePointer.queryBufferPointerSize which is
/// masked by the default SpherePointerInspector.
/// </summary>
public class MySpherePointer : SpherePointer
{
}

MySpherePointerInspector.cs

using Microsoft.MixedReality.Toolkit.Input;
using UnityEditor;

/// <summary>
/// This class exists soley to expose SpherePointer.queryBufferPointerSize which is
/// masked by the default SpherePointerInspector.
/// </summary>
[CustomEditor(typeof(MySpherePointer))]
public class MySpherePointerInspector : SpherePointerInspector
{
    private SerializedProperty sceneQueryBufferSize;
    private bool hiddenSpherePointerFoldout = true;
    protected override void OnEnable()
    {
        base.OnEnable();
        sceneQueryBufferSize = serializedObject.FindProperty("sceneQueryBufferSize");
    }

    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        hiddenSpherePointerFoldout = EditorGUILayout.Foldout(hiddenSpherePointerFoldout, "Hidden Sphere Pointer Settings", true);

        if (hiddenSpherePointerFoldout)
        {
            using (new EditorGUI.IndentLevelScope())
            {
                EditorGUILayout.PropertyField(sceneQueryBufferSize);
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.