SteamVR_Controller.Input C# (CSharp) Method

Input() public static method

public static Input ( int deviceIndex ) : Device,
deviceIndex int
return Device,
    public static Device Input(int deviceIndex)
    {
        if (devices == null)
        {
            devices = new Device[OpenVR.k_unMaxTrackedDeviceCount];
            for (uint i = 0; i < devices.Length; i++)
                devices[i] = new Device(i);
        }

        return devices[deviceIndex];
    }

Usage Example

Ejemplo n.º 1
0
    void Update()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            // See if anything has changed since this gets called whenever anything gets touched.
            var fields = GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            bool modified = false;

            if (values == null)
            {
                modified = true;
            }
            else
            {
                foreach (var f in fields)
                {
                    if (!values.Contains(f) || !f.GetValue(this).Equals(values[f]))
                    {
                        modified = true;
                        break;
                    }
                }
            }

            if (modified)
            {
                SetModel(modelOverride);

                values = new Hashtable();
                foreach (var f in fields)
                {
                    values[f] = f.GetValue(this);
                }
            }

            return;             // Do not update transforms (below) when not playing in Editor (to avoid keeping OpenVR running all the time).
        }
#endif
        // Update component transforms dynamically.
        if (updateDynamically)
        {
            using (var holder = new RenderModelInterfaceHolder())
            {
                var controllerState = SteamVR_Controller.Input((int)index).GetState();

                var t             = transform;
                var baseTransform = new SteamVR_Utils.RigidTransform(t);

                for (int i = 0; i < t.childCount; i++)
                {
                    var child = t.GetChild(i);

                    var renderModels = holder.instance;
                    if (renderModels == null)
                    {
                        break;
                    }

                    var componentState = new RenderModel_ComponentState_t();
                    if (!renderModels.GetComponentState(renderModelName, child.name, ref controllerState, ref componentState))
                    {
                        continue;
                    }

                    var componentTransform = new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentRenderModel);
                    child.localPosition = componentTransform.pos;
                    child.localRotation = componentTransform.rot;

                    var attach = child.FindChild(k_localTransformName);
                    if (attach != null)
                    {
                        var attachTransform = baseTransform * new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentLocal);
                        attach.position = attachTransform.pos;
                        attach.rotation = attachTransform.rot;
                    }

                    bool visible = (componentState.uProperties & (uint)EVRComponentProperty.VRComponentProperty_IsVisible) != 0;
                    if (visible != child.gameObject.activeSelf)
                    {
                        child.gameObject.SetActive(visible);
                    }
                }
            }
        }
    }
All Usage Examples Of SteamVR_Controller::Input