示例#1
0
    public void UpdateComponents(CVRRenderModels renderModels)
    {
        if (renderModels == null)
        {
            return;
        }

        var t = transform;

        if (t.childCount == 0)
        {
            return;
        }

        var controllerState = (index != SteamVR_TrackedObject.EIndex.None) ?
                              SteamVR_Controller.Input((int)index).GetState() : new VRControllerState_t();

        if (nameCache == null)
        {
            nameCache = new Dictionary <int, string>();
        }

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

            // Cache names since accessing an object's name allocate memory.
            string name;
            if (!nameCache.TryGetValue(child.GetInstanceID(), out name))
            {
                name = child.name;
                nameCache.Add(child.GetInstanceID(), name);
            }

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

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


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

            bool visible = (componentState.uProperties & (uint)EVRComponentProperty.IsVisible) != 0;
            if (visible != child.gameObject.activeSelf)
            {
                child.gameObject.SetActive(visible);
            }
        }
    }
 private bool TryGetComponentState(CVRSystem vrSystem, CVRRenderModels vrRenderModels, string componentName, out RenderModel_ComponentState_t componentState)
 {
     componentState = default(RenderModel_ComponentState_t);
     var modeState = default(RenderModel_ControllerMode_State_t);
     var controllerState = default(VRControllerState_t);
     if (!vrSystem.GetControllerState(m_deviceIndex, ref controllerState, s_sizeOfControllerStats)) { return false; }
     if (!vrRenderModels.GetComponentState(loadedModelName, componentName, ref controllerState, ref modeState, ref componentState)) { return false; }
     return true;
 }
示例#3
0
    // Token: 0x06000DE8 RID: 3560 RVA: 0x00058868 File Offset: 0x00056A68
    public void UpdateComponents(CVRRenderModels renderModels)
    {
        if (renderModels == null)
        {
            return;
        }
        Transform transform = base.transform;

        if (transform.childCount == 0)
        {
            return;
        }
        VRControllerState_t vrcontrollerState_t = (this.index != SteamVR_TrackedObject.EIndex.None) ? SteamVR_Controller.Input((int)this.index).GetState() : default(VRControllerState_t);

        if (this.nameCache == null)
        {
            this.nameCache = new Dictionary <int, string>();
        }
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child = transform.GetChild(i);
            string    name;
            if (!this.nameCache.TryGetValue(child.GetInstanceID(), out name))
            {
                name = child.name;
                this.nameCache.Add(child.GetInstanceID(), name);
            }
            RenderModel_ComponentState_t renderModel_ComponentState_t = default(RenderModel_ComponentState_t);
            if (renderModels.GetComponentState(this.renderModelName, name, ref vrcontrollerState_t, ref this.controllerModeState, ref renderModel_ComponentState_t))
            {
                SteamVR_Utils.RigidTransform rigidTransform = new SteamVR_Utils.RigidTransform(renderModel_ComponentState_t.mTrackingToComponentRenderModel);
                child.localPosition = rigidTransform.pos;
                child.localRotation = rigidTransform.rot;
                Transform transform2 = child.Find("attach");
                if (transform2 != null)
                {
                    SteamVR_Utils.RigidTransform rigidTransform2 = new SteamVR_Utils.RigidTransform(renderModel_ComponentState_t.mTrackingToComponentLocal);
                    transform2.position = transform.TransformPoint(rigidTransform2.pos);
                    transform2.rotation = transform.rotation * rigidTransform2.rot;
                }
                bool flag = (renderModel_ComponentState_t.uProperties & 2U) > 0U;
                if (flag != child.gameObject.activeSelf)
                {
                    child.gameObject.SetActive(flag);
                }
            }
        }
    }