예제 #1
0
    // Token: 0x060000C7 RID: 199 RVA: 0x00008BFA File Offset: 0x00006DFA
    private global::System.Collections.IEnumerator SetModelAsync(string renderModelName)
    {
        bool flag = string.IsNullOrEmpty(renderModelName);

        if (flag)
        {
            yield break;
        }
        using (global::SteamVR_RenderModel.RenderModelInterfaceHolder holder = new global::SteamVR_RenderModel.RenderModelInterfaceHolder())
        {
            global::Valve.VR.CVRRenderModels renderModels = holder.instance;
            bool flag2 = renderModels == null;
            if (flag2)
            {
                yield break;
            }
            uint     count = renderModels.GetComponentCount(renderModelName);
            bool     flag3 = count > 0U;
            string[] renderModelNames;
            if (flag3)
            {
                renderModelNames = new string[count];
                int i = 0;
                while ((long)i < (long)((ulong)count))
                {
                    uint capacity = renderModels.GetComponentName(renderModelName, (uint)i, null, 0U);
                    bool flag4    = capacity == 0U;
                    if (!flag4)
                    {
                        global::System.Text.StringBuilder componentName = new global::System.Text.StringBuilder((int)capacity);
                        bool flag5 = renderModels.GetComponentName(renderModelName, (uint)i, componentName, capacity) == 0U;
                        if (!flag5)
                        {
                            capacity = renderModels.GetComponentRenderModelName(renderModelName, componentName.ToString(), null, 0U);
                            bool flag6 = capacity == 0U;
                            if (!flag6)
                            {
                                global::System.Text.StringBuilder name = new global::System.Text.StringBuilder((int)capacity);
                                bool flag7 = renderModels.GetComponentRenderModelName(renderModelName, componentName.ToString(), name, capacity) == 0U;
                                if (!flag7)
                                {
                                    string s = name.ToString();
                                    global::SteamVR_RenderModel.RenderModel model = global::SteamVR_RenderModel.models[s] as global::SteamVR_RenderModel.RenderModel;
                                    bool flag8 = model == null || model.mesh == null;
                                    if (flag8)
                                    {
                                        renderModelNames[i] = s;
                                    }
                                    componentName = null;
                                    name          = null;
                                    s             = null;
                                    model         = null;
                                }
                            }
                        }
                    }
                    int num = i;
                    i = num + 1;
                }
            }
            else
            {
                global::SteamVR_RenderModel.RenderModel model2 = global::SteamVR_RenderModel.models[renderModelName] as global::SteamVR_RenderModel.RenderModel;
                bool flag9 = model2 == null || model2.mesh == null;
                if (flag9)
                {
                    renderModelNames = new string[]
                    {
                        renderModelName
                    };
                }
                else
                {
                    renderModelNames = new string[0];
                }
                model2 = null;
            }
            for (;;)
            {
                bool loading = false;
                foreach (string name2 in renderModelNames)
                {
                    bool flag10 = string.IsNullOrEmpty(name2);
                    if (!flag10)
                    {
                        global::System.IntPtr pRenderModel         = global::System.IntPtr.Zero;
                        global::Valve.VR.EVRRenderModelError error = renderModels.LoadRenderModel_Async(name2, ref pRenderModel);
                        bool flag11 = error == global::Valve.VR.EVRRenderModelError.Loading;
                        if (flag11)
                        {
                            loading = true;
                        }
                        else
                        {
                            bool flag12 = error == global::Valve.VR.EVRRenderModelError.None;
                            if (flag12)
                            {
                                global::Valve.VR.RenderModel_t renderModel = (global::Valve.VR.RenderModel_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(pRenderModel, typeof(global::Valve.VR.RenderModel_t));
                                global::UnityEngine.Material   material    = global::SteamVR_RenderModel.materials[renderModel.diffuseTextureId] as global::UnityEngine.Material;
                                bool flag13 = material == null || material.mainTexture == null;
                                if (flag13)
                                {
                                    global::System.IntPtr pDiffuseTexture = global::System.IntPtr.Zero;
                                    error = renderModels.LoadTexture_Async(renderModel.diffuseTextureId, ref pDiffuseTexture);
                                    bool flag14 = error == global::Valve.VR.EVRRenderModelError.Loading;
                                    if (flag14)
                                    {
                                        loading = true;
                                    }
                                }
                                material = null;
                            }
                        }
                        name2 = null;
                    }
                }
                string[] array  = null;
                bool     flag15 = loading;
                if (!flag15)
                {
                    break;
                }
                yield return(new global::UnityEngine.WaitForSeconds(0.1f));
            }
            renderModels     = null;
            renderModelNames = null;
        }
        global::SteamVR_RenderModel.RenderModelInterfaceHolder holder = null;
        bool success = this.SetModel(renderModelName);

        global::SteamVR_Utils.Event.Send("render_model_loaded", new object[]
        {
            this,
            success
        });
        yield break;
        yield break;
    }
예제 #2
0
    // Token: 0x060000CD RID: 205 RVA: 0x000092E8 File Offset: 0x000074E8
    private bool LoadComponents(global::SteamVR_RenderModel.RenderModelInterfaceHolder holder, string renderModelName)
    {
        global::UnityEngine.Transform transform = base.transform;
        for (int i = 0; i < transform.childCount; i++)
        {
            global::UnityEngine.Transform child = transform.GetChild(i);
            child.gameObject.SetActive(false);
            this.StripMesh(child.gameObject);
        }
        bool flag = string.IsNullOrEmpty(renderModelName);
        bool result;

        if (flag)
        {
            result = true;
        }
        else
        {
            global::Valve.VR.CVRRenderModels instance = holder.instance;
            bool flag2 = instance == null;
            if (flag2)
            {
                result = false;
            }
            else
            {
                uint componentCount = instance.GetComponentCount(renderModelName);
                bool flag3          = componentCount == 0U;
                if (flag3)
                {
                    result = false;
                }
                else
                {
                    int num = 0;
                    while ((long)num < (long)((ulong)componentCount))
                    {
                        uint num2  = instance.GetComponentName(renderModelName, (uint)num, null, 0U);
                        bool flag4 = num2 == 0U;
                        if (!flag4)
                        {
                            global::System.Text.StringBuilder stringBuilder = new global::System.Text.StringBuilder((int)num2);
                            bool flag5 = instance.GetComponentName(renderModelName, (uint)num, stringBuilder, num2) == 0U;
                            if (!flag5)
                            {
                                transform = this.FindComponent(stringBuilder.ToString());
                                bool flag6 = transform != null;
                                if (flag6)
                                {
                                    transform.gameObject.SetActive(true);
                                }
                                else
                                {
                                    transform                  = new global::UnityEngine.GameObject(stringBuilder.ToString()).transform;
                                    transform.parent           = base.transform;
                                    transform.gameObject.layer = base.gameObject.layer;
                                    global::UnityEngine.Transform transform2 = new global::UnityEngine.GameObject("attach").transform;
                                    transform2.parent           = transform;
                                    transform2.localPosition    = global::UnityEngine.Vector3.zero;
                                    transform2.localRotation    = global::UnityEngine.Quaternion.identity;
                                    transform2.localScale       = global::UnityEngine.Vector3.one;
                                    transform2.gameObject.layer = base.gameObject.layer;
                                }
                                transform.localPosition = global::UnityEngine.Vector3.zero;
                                transform.localRotation = global::UnityEngine.Quaternion.identity;
                                transform.localScale    = global::UnityEngine.Vector3.one;
                                num2 = instance.GetComponentRenderModelName(renderModelName, stringBuilder.ToString(), null, 0U);
                                bool flag7 = num2 == 0U;
                                if (!flag7)
                                {
                                    global::System.Text.StringBuilder stringBuilder2 = new global::System.Text.StringBuilder((int)num2);
                                    bool flag8 = instance.GetComponentRenderModelName(renderModelName, stringBuilder.ToString(), stringBuilder2, num2) == 0U;
                                    if (!flag8)
                                    {
                                        global::SteamVR_RenderModel.RenderModel renderModel = global::SteamVR_RenderModel.models[stringBuilder2] as global::SteamVR_RenderModel.RenderModel;
                                        bool flag9 = renderModel == null || renderModel.mesh == null;
                                        if (flag9)
                                        {
                                            bool flag10 = this.verbose;
                                            if (flag10)
                                            {
                                                string text = "Loading render model ";
                                                global::System.Text.StringBuilder stringBuilder3 = stringBuilder2;
                                                global::UnityEngine.Debug.Log(text + ((stringBuilder3 != null) ? stringBuilder3.ToString() : null));
                                            }
                                            renderModel = this.LoadRenderModel(instance, stringBuilder2.ToString(), renderModelName);
                                            bool flag11 = renderModel == null;
                                            if (flag11)
                                            {
                                                goto IL_2BD;
                                            }
                                            global::SteamVR_RenderModel.models[stringBuilder2] = renderModel;
                                        }
                                        transform.gameObject.AddComponent <global::UnityEngine.MeshFilter>().mesh             = renderModel.mesh;
                                        transform.gameObject.AddComponent <global::UnityEngine.MeshRenderer>().sharedMaterial = renderModel.material;
                                    }
                                }
                            }
                        }
IL_2BD:
                        num++;
                    }
                    result = true;
                }
            }
        }
        return(result);
    }