示例#1
0
    private static bool GetUnityXRNodeStateVector3(Node nodeType, NodeStatePropertyType propertyType, out Vector3 retVec)
    {
        retVec = Vector3.zero;

        NodeState requestedNodeState = default(NodeState);

        if (!ValidateProperty(nodeType, ref requestedNodeState))
        {
            return(false);
        }

        if (propertyType == NodeStatePropertyType.Acceleration)
        {
            if (requestedNodeState.TryGetAcceleration(out retVec))
            {
                return(true);
            }
        }
        else if (propertyType == NodeStatePropertyType.AngularAcceleration)
        {
#if UNITY_2017_2_OR_NEWER
            if (requestedNodeState.TryGetAngularAcceleration(out retVec))
            {
                return(true);
            }
#endif
        }
        else if (propertyType == NodeStatePropertyType.Velocity)
        {
            if (requestedNodeState.TryGetVelocity(out retVec))
            {
                return(true);
            }
        }
        else if (propertyType == NodeStatePropertyType.AngularVelocity)
        {
#if UNITY_2017_2_OR_NEWER
            if (requestedNodeState.TryGetAngularVelocity(out retVec))
            {
                return(true);
            }
#endif
        }
        else if (propertyType == NodeStatePropertyType.Position)
        {
            if (requestedNodeState.TryGetPosition(out retVec))
            {
                return(true);
            }
        }

        return(false);
    }
    public Vector3 GetNodeStateProperty(Node nodeType, NodeStatePropertyType propertyType)
    {
        List <NodeState> nodeStateList = new List <NodeState>();

        InputTracking.GetNodeStates(nodeStateList);

        if (nodeStateList.Count == 0)
        {
            return(Vector3.zero);
        }

        bool      nodeStateFound     = false;
        NodeState requestedNodeState = nodeStateList[0];

        for (int i = 0; i < nodeStateList.Count; i++)
        {
            if (nodeStateList[i].nodeType == nodeType)
            {
                requestedNodeState = nodeStateList[i];
                nodeStateFound     = true;
                break;
            }
        }

        if (!nodeStateFound)
        {
            return(Vector3.zero);
        }

        Vector3 retVec;

        if (propertyType == NodeStatePropertyType.Acceleration)
        {
            if (requestedNodeState.TryGetAcceleration(out retVec))
            {
                return(retVec);
            }
        }
        else if (propertyType == NodeStatePropertyType.AngularAcceleration)
        {
#if UNITY_2017_2_OR_NEWER
            if (requestedNodeState.TryGetAngularAcceleration(out retVec))
            {
                retVec = retVec * Mathf.Rad2Deg;
                return(retVec);
            }
#endif
        }
        else if (propertyType == NodeStatePropertyType.Velocity)
        {
            if (requestedNodeState.TryGetVelocity(out retVec))
            {
                return(retVec);
            }
        }
        else if (propertyType == NodeStatePropertyType.AngularVelocity)
        {
#if UNITY_2017_2_OR_NEWER
            if (requestedNodeState.TryGetAngularVelocity(out retVec))
            {
                retVec = retVec * Mathf.Rad2Deg;
                return(retVec);
            }
#endif
        }

        return(Vector3.zero);
    }