public void RefreshBodyParts() { OvrAvatarComponent component; if (trackedComponents.TryGetValue("body", out component) && Body != null) { foreach (var part in component.RenderParts) { Destroy(part.gameObject); } component.RenderParts.Clear(); ovrAvatarBodyComponent?sdkBodyComponent = CAPI.ovrAvatarPose_GetBodyComponent(sdkAvatar); if (sdkBodyComponent != null) { ovrAvatarComponent sdKComponent = (ovrAvatarComponent)Marshal.PtrToStructure(sdkBodyComponent.Value.renderComponent, typeof(ovrAvatarComponent)); AddRenderParts(component, sdKComponent, Body.gameObject.transform); } else { throw new Exception("Destroyed the body component, but didn't find a new one in the SDK"); } } }
private void UpdateSDKAvatarUnityState() { //Iterate through all the render components UInt32 componentCount = CAPI.ovrAvatarComponent_Count(sdkAvatar); HashSet <string> componentsThisRun = new HashSet <string>(); for (UInt32 i = 0; i < componentCount; i++) { IntPtr ptr = CAPI.ovrAvatarComponent_Get_Native(sdkAvatar, i); ovrAvatarComponent component = (ovrAvatarComponent)Marshal.PtrToStructure(ptr, typeof(ovrAvatarComponent)); componentsThisRun.Add(component.name); if (!trackedComponents.ContainsKey(component.name)) { GameObject componentObject = null; Type specificType = null; if ((Capabilities & ovrAvatarCapabilities.Base) != 0) { ovrAvatarBaseComponent?baseComponent = CAPI.ovrAvatarPose_GetBaseComponent(sdkAvatar); if (baseComponent.HasValue && ptr == baseComponent.Value.renderComponent) { specificType = typeof(OvrAvatarBase); if (Base != null) { componentObject = Base.gameObject; } } } if (specificType == null && (Capabilities & ovrAvatarCapabilities.Body) != 0) { ovrAvatarBodyComponent?bodyComponent = CAPI.ovrAvatarPose_GetBodyComponent(sdkAvatar); if (bodyComponent.HasValue && ptr == bodyComponent.Value.renderComponent) { specificType = typeof(OvrAvatarBody); if (Body != null) { componentObject = Body.gameObject; } } } if (specificType == null && (Capabilities & ovrAvatarCapabilities.Hands) != 0) { ovrAvatarControllerComponent?controllerComponent = CAPI.ovrAvatarPose_GetLeftControllerComponent(sdkAvatar); if (specificType == null && controllerComponent.HasValue && ptr == controllerComponent.Value.renderComponent) { specificType = typeof(OvrAvatarTouchController); if (ControllerLeft != null) { componentObject = ControllerLeft.gameObject; } } controllerComponent = CAPI.ovrAvatarPose_GetRightControllerComponent(sdkAvatar); if (specificType == null && controllerComponent.HasValue && ptr == controllerComponent.Value.renderComponent) { specificType = typeof(OvrAvatarTouchController); if (ControllerRight != null) { componentObject = ControllerRight.gameObject; } } ovrAvatarHandComponent?handComponent = CAPI.ovrAvatarPose_GetLeftHandComponent(sdkAvatar); if (specificType == null && handComponent.HasValue && ptr == handComponent.Value.renderComponent) { specificType = typeof(OvrAvatarHand); if (HandLeft != null) { componentObject = HandLeft.gameObject; } } handComponent = CAPI.ovrAvatarPose_GetRightHandComponent(sdkAvatar); if (specificType == null && handComponent.HasValue && ptr == handComponent.Value.renderComponent) { specificType = typeof(OvrAvatarHand); if (HandRight != null) { componentObject = HandRight.gameObject; } } } // If this is an unknown type, just create an object for the rendering if (componentObject == null && specificType == null) { componentObject = new GameObject(); componentObject.name = component.name; componentObject.transform.SetParent(transform); } if (componentObject != null) { AddAvatarComponent(componentObject, component); } } UpdateAvatarComponent(component); } HashSet <string> deletableNames = new HashSet <string>(trackedComponents.Keys); deletableNames.ExceptWith(componentsThisRun); //deletableNames contains the name of all components which are tracked and were //not present in this run foreach (var name in deletableNames) { RemoveAvatarComponent(name); } UpdateVoiceBehavior(); }