예제 #1
0
파일: OvrAvatar.cs 프로젝트: Geli25/COPA
    private void BuildRenderComponents()
    {
        var leftHand        = CAPI.ovrAvatarPose_GetLeftHandComponent(sdkAvatar);
        var rightHand       = CAPI.ovrAvatarPose_GetRightHandComponent(sdkAvatar);
        var body            = CAPI.ovrAvatarPose_GetBodyComponent(sdkAvatar);
        var leftController  = CAPI.ovrAvatarPose_GetLeftControllerComponent(sdkAvatar);
        var rightController = CAPI.ovrAvatarPose_GetRightControllerComponent(sdkAvatar);
        var baseComponent   = CAPI.ovrAvatarPose_GetBaseComponent(sdkAvatar);

        UInt32 componentCount = CAPI.ovrAvatarComponent_Count(sdkAvatar);

        for (UInt32 i = 0; i < componentCount; i++)
        {
            IntPtr             ptr       = CAPI.ovrAvatarComponent_Get_Native(sdkAvatar, i);
            ovrAvatarComponent component = (ovrAvatarComponent)Marshal.PtrToStructure(ptr, typeof(ovrAvatarComponent));
            if (!trackedComponents.ContainsKey(component.name))
            {
                GameObject componentObject = new GameObject();
                componentObject.name = component.name;
                componentObject.transform.SetParent(transform);
                AddAvatarComponent(componentObject, component);

                if (leftHand.HasValue && ptr == leftHand.Value.renderComponent)
                {
                    HandLeft = componentObject.AddComponent <OvrAvatarHand>();
                }

                if (rightHand.HasValue && ptr == rightHand.Value.renderComponent)
                {
                    HandRight = componentObject.AddComponent <OvrAvatarHand>();
                }

                if (body.HasValue && ptr == body.Value.renderComponent)
                {
                    Body = componentObject.AddComponent <OvrAvatarBody>();
                }

                if (leftController.HasValue && ptr == leftController.Value.renderComponent)
                {
                    ControllerLeft = componentObject.AddComponent <OvrAvatarTouchController>();
                }

                if (rightController.HasValue && ptr == rightController.Value.renderComponent)
                {
                    ControllerRight = componentObject.AddComponent <OvrAvatarTouchController>();
                }

                if (baseComponent.HasValue && ptr == baseComponent.Value.renderComponent)
                {
                    Base = componentObject.AddComponent <OvrAvatarBase>();
                }
            }
        }
    }
        public void SetDeviceIndex(uint index)
        {
            //Debug.Log(transform.parent.parent.name + " SetDeviceIndex " + index);
            m_deviceIndex = index;
#if (VIU_OCULUSVR_1_32_0_OR_NEWER || VIU_OCULUSVR_1_36_0_OR_NEWER) && VIU_OCULUSVR_AVATAR
            ovrController = this.GetComponent <OvrAvatarTouchController>();
#endif
#if VIU_OCULUSVR && VIU_OCULUSVR_AVATAR
            var headsetType = OVRPlugin.GetSystemHeadsetType();
            switch (headsetType)
            {
#if !VIU_OCULUSVR_19_0_OR_NEWER
            case OVRPlugin.SystemHeadset.GearVR_R320:
            case OVRPlugin.SystemHeadset.GearVR_R321:
            case OVRPlugin.SystemHeadset.GearVR_R322:
            case OVRPlugin.SystemHeadset.GearVR_R323:
            case OVRPlugin.SystemHeadset.GearVR_R324:
            case OVRPlugin.SystemHeadset.GearVR_R325:
                m_controllerType = ovrAvatarControllerType.Malibu;
                break;

            case OVRPlugin.SystemHeadset.Oculus_Go:
                m_controllerType = ovrAvatarControllerType.Go;
                break;
#endif
#if VIU_OCULUSVR_16_0_OR_NEWER
            case OVRPlugin.SystemHeadset.Oculus_Link_Quest:
#endif
            case OVRPlugin.SystemHeadset.Oculus_Quest:
#if VIU_OCULUSVR_1_37_0_OR_NEWER
            case OVRPlugin.SystemHeadset.Rift_S:
                m_controllerType = ovrAvatarControllerType.Quest;
                break;
#endif
            case OVRPlugin.SystemHeadset.Rift_DK1:
            case OVRPlugin.SystemHeadset.Rift_DK2:
            case OVRPlugin.SystemHeadset.Rift_CV1:
            default:
                m_controllerType = ovrAvatarControllerType.Touch;
                break;
            }
#endif
            LoadPreferedModel();
        }
        private void UpdateSDKAvatarUnityState()
        {
#if VIU_OCULUSVR_1_37_0_OR_NEWER && VIU_OCULUSVR_AVATAR
            ovrAvatarControllerComponent controllerComponent = new ovrAvatarControllerComponent();
            ovrAvatarComponent           dummyComponent      = new ovrAvatarComponent();
            OvrAvatarTouchController     controller          = null;

            if (m_deviceIndex == LEFT_INDEX)
            {
                if (CAPI.ovrAvatarPose_GetLeftControllerComponent(sdkAvatar, ref controllerComponent))
                {
                    CAPI.ovrAvatarComponent_Get(controllerComponent.renderComponent, true, ref dummyComponent);
                    AddAvatarComponent(ref controller, dummyComponent);
                    controller.isLeftHand = true;
                }
            }
            else if (m_deviceIndex == RIGHT_INDEX)
            {
                if (CAPI.ovrAvatarPose_GetRightControllerComponent(sdkAvatar, ref controllerComponent))
                {
                    CAPI.ovrAvatarComponent_Get(controllerComponent.renderComponent, true, ref dummyComponent);
                    AddAvatarComponent(ref controller, dummyComponent);
                    controller.isLeftHand = false;
                }
            }
#elif (VIU_OCULUSVR_1_32_0_OR_NEWER || VIU_OCULUSVR_1_36_0_OR_NEWER) && VIU_OCULUSVR_AVATAR
            //Iterate through all the render components
            UInt32 componentCount = CAPI.ovrAvatarComponent_Count(sdkAvatar);

            for (UInt32 i = 0; i < componentCount; i++)
            {
                IntPtr ptr = CAPI.ovrAvatarComponent_Get_Native(sdkAvatar, i);

                ovrAvatarComponent component = (ovrAvatarComponent)Marshal.PtrToStructure(ptr, typeof(ovrAvatarComponent));

                if (!trackedComponents.ContainsKey(component.name))
                {
                    GameObject componentObject = null;
                    Type       specificType    = null;


                    if (specificType == null && (ovrAvatarCapabilities.All & ovrAvatarCapabilities.Hands) != 0)
                    {
                        if (m_deviceIndex == LEFT_INDEX)
                        {
                            ovrAvatarControllerComponent?controllerComponent = CAPI.ovrAvatarPose_GetLeftControllerComponent(sdkAvatar);
                            if (specificType == null && controllerComponent.HasValue && ptr == controllerComponent.Value.renderComponent)
                            {
                                specificType = typeof(OvrAvatarTouchController);
                                if (ovrController != null)
                                {
                                    componentObject = ovrController.gameObject;
                                }
                            }
                        }
                        else if (m_deviceIndex == RIGHT_INDEX)
                        {
                            ovrAvatarControllerComponent?controllerComponent = CAPI.ovrAvatarPose_GetRightControllerComponent(sdkAvatar);
                            if (specificType == null && controllerComponent.HasValue && ptr == controllerComponent.Value.renderComponent)
                            {
                                specificType = typeof(OvrAvatarTouchController);
                                if (ovrController != null)
                                {
                                    componentObject = ovrController.gameObject;
                                }
                            }
                        }
                    }

                    if (componentObject != null)
                    {
                        AddAvatarComponent(componentObject, component);
                    }
                }

                UpdateAvatarComponent(component);
            }
#endif
        }