Ejemplo n.º 1
0
 private static string GetRenderPartName(ovrAvatarComponent component, uint renderPartIndex)
 {
     return(component.name + "_renderPart_" + (int)renderPartIndex);
 }
Ejemplo n.º 2
0
    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 (ptr == CAPI.ovrAvatarPose_GetBaseComponent(sdkAvatar).renderComponent)
                {
                    specificType = typeof(OvrAvatarBase);
                    if (Base != null)
                    {
                        componentObject = Base.gameObject;
                    }
                }
                else if (ptr == CAPI.ovrAvatarPose_GetBodyComponent(sdkAvatar).renderComponent)
                {
                    specificType = typeof(OvrAvatarBody);
                    if (Body != null)
                    {
                        componentObject = Body.gameObject;
                    }
                }
                else if (ptr == CAPI.ovrAvatarPose_GetLeftControllerComponent(sdkAvatar).renderComponent)
                {
                    specificType = typeof(OvrAvatarTouchController);
                    if (ControllerLeft != null)
                    {
                        componentObject = ControllerLeft.gameObject;
                    }
                }
                else if (ptr == CAPI.ovrAvatarPose_GetRightControllerComponent(sdkAvatar).renderComponent)
                {
                    specificType = typeof(OvrAvatarTouchController);
                    if (ControllerRight != null)
                    {
                        componentObject = ControllerRight.gameObject;
                    }
                }
                else if (ptr == CAPI.ovrAvatarPose_GetLeftHandComponent(sdkAvatar).renderComponent)
                {
                    specificType = typeof(OvrAvatarHand);
                    if (HandLeft != null)
                    {
                        componentObject = HandLeft.gameObject;
                    }
                }
                else if (ptr == CAPI.ovrAvatarPose_GetRightHandComponent(sdkAvatar).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);
                    if (specificType != null)
                    {
                        IAvatarPart part = componentObject.GetComponent(specificType) as IAvatarPart;
                        if (part != null)
                        {
                            part.OnAssetsLoaded();
                        }
                    }
                }
            }
            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);
        }
    }