示例#1
0
    static string[] LoadRenderModelNames()
    {
        var results = new List <string>();

        results.Add("None");

        var error = HmdError.None;

        if (!SteamVR.active)
        {
            OpenVR.Init(ref error);
            if (error != HmdError.None)
            {
                return(results.ToArray());
            }
        }

        var pRenderModels = OpenVR.GetGenericInterface(OpenVR.IVRRenderModels_Version, ref error);

        if (pRenderModels == System.IntPtr.Zero || error != HmdError.None)
        {
            if (!SteamVR.active)
            {
                OpenVR.Shutdown();
            }
            return(results.ToArray());
        }

        var renderModels = new CVRRenderModels(pRenderModels);

        uint count = renderModels.GetRenderModelCount();

        for (uint i = 0; i < count; i++)
        {
            var buffer       = new StringBuilder();
            var requiredSize = renderModels.GetRenderModelName(i, buffer, 0);
            if (requiredSize == 0)
            {
                continue;
            }

            buffer.EnsureCapacity((int)requiredSize);
            renderModels.GetRenderModelName(i, buffer, requiredSize);
            results.Add(buffer.ToString());
        }

        if (!SteamVR.active)
        {
            OpenVR.Shutdown();
        }

        return(results.ToArray());
    }