예제 #1
0
    void Update()
    {
        if (Instance == null)
        {
            return;
        }
#if AVATAR_DEBUG
        // Call before ovrAvatarMessage_Pop which flushes the state
        CAPI.ovrAvatar_DrawDebugLines();
#endif

        // Dispatch waiting avatar spec request
        if (avatarSpecificationQueue.Count > 0 &&
            (avatarSpecRequestAvailable ||
             Time.time - lastDispatchedAvatarSpecRequestTime >= AVATAR_SPEC_REQUEST_TIMEOUT))
        {
            avatarSpecRequestAvailable = false;
            AvatarSpecRequestParams avatarSpec = avatarSpecificationQueue.Dequeue();
            DispatchAvatarSpecificationRequest(avatarSpec);
            lastDispatchedAvatarSpecRequestTime = Time.time;
            AvatarLogger.Log("Avatar spec request dispatched: " + avatarSpec._userId);
        }

        IntPtr message = CAPI.ovrAvatarMessage_Pop();
        if (message == IntPtr.Zero)
        {
            return;
        }

        ovrAvatarMessageType messageType = CAPI.ovrAvatarMessage_GetType(message);
        switch (messageType)
        {
        case ovrAvatarMessageType.AssetLoaded:
        {
            ovrAvatarMessage_AssetLoaded assetMessage = CAPI.ovrAvatarMessage_GetAssetLoaded(message);
            IntPtr             asset       = assetMessage.asset;
            UInt64             assetID     = assetMessage.assetID;
            ovrAvatarAssetType assetType   = CAPI.ovrAvatarAsset_GetType(asset);
            OvrAvatarAsset     assetData   = null;
            IntPtr             avatarOwner = IntPtr.Zero;

            switch (assetType)
            {
            case ovrAvatarAssetType.Mesh:
                assetData = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.Mesh);
                break;

            case ovrAvatarAssetType.Texture:
                assetData = new OvrAvatarAssetTexture(assetID, asset);
                break;

            case ovrAvatarAssetType.Material:
                assetData = new OvrAvatarAssetMaterial(assetID, asset);
                break;

            case ovrAvatarAssetType.CombinedMesh:
                avatarOwner = CAPI.ovrAvatarAsset_GetAvatar(asset);
                assetData   = new OvrAvatarAssetMesh(assetID, asset, ovrAvatarAssetType.CombinedMesh);
                break;

            case ovrAvatarAssetType.FailedLoad:
                AvatarLogger.LogWarning("Asset failed to load from SDK " + assetID);
                break;

            default:
                throw new NotImplementedException(string.Format("Unsupported asset type format {0}", assetType.ToString()));
            }

            HashSet <assetLoadedCallback> callbackSet;
            if (assetType == ovrAvatarAssetType.CombinedMesh)
            {
                if (!assetCache.ContainsKey(assetID))
                {
                    assetCache.Add(assetID, assetData);
                }

                combinedMeshLoadedCallback callback;
                if (combinedMeshLoadedCallbacks.TryGetValue(avatarOwner, out callback))
                {
                    callback(asset);
                    combinedMeshLoadedCallbacks.Remove(avatarOwner);
                }
                else
                {
                    AvatarLogger.LogWarning("Loaded a combined mesh with no owner: " + assetMessage.assetID);
                }
            }
            else
            {
                if (assetData != null && assetLoadedCallbacks.TryGetValue(assetMessage.assetID, out callbackSet))
                {
                    assetCache.Add(assetID, assetData);

                    foreach (var callback in callbackSet)
                    {
                        callback(assetData);
                    }

                    assetLoadedCallbacks.Remove(assetMessage.assetID);
                }
            }
            break;
        }

        case ovrAvatarMessageType.AvatarSpecification:
        {
            avatarSpecRequestAvailable = true;
            ovrAvatarMessage_AvatarSpecification spec = CAPI.ovrAvatarMessage_GetAvatarSpecification(message);
            HashSet <specificationCallback>      callbackSet;
            if (specificationCallbacks.TryGetValue(spec.oculusUserID, out callbackSet))
            {
                foreach (var callback in callbackSet)
                {
                    callback(spec.avatarSpec);
                }

                specificationCallbacks.Remove(spec.oculusUserID);
            }
            else
            {
                AvatarLogger.LogWarning("Error, got an avatar specification callback from a user id we don't have a record for: " + spec.oculusUserID);
            }
            break;
        }

        default:
            throw new NotImplementedException("Unhandled ovrAvatarMessageType: " + messageType);
        }
        CAPI.ovrAvatarMessage_Free(message);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        IntPtr message = CAPI.ovrAvatarMessage_Pop();

        if (message == IntPtr.Zero)
        {
            return;
        }

        ovrAvatarMessageType messageType = CAPI.ovrAvatarMessage_GetType(message);

        switch (messageType)
        {
        case ovrAvatarMessageType.AssetLoaded:
        {
            ovrAvatarMessage_AssetLoaded assetMessage = CAPI.ovrAvatarMessage_GetAssetLoaded(message);
            IntPtr             asset     = assetMessage.asset;
            UInt64             assetID   = assetMessage.assetID;
            ovrAvatarAssetType assetType = CAPI.ovrAvatarAsset_GetType(asset);
            OvrAvatarAsset     assetData;
            switch (assetType)
            {
            case ovrAvatarAssetType.Mesh:
                assetData = new OvrAvatarAssetMesh(assetID, asset);
                break;

            case ovrAvatarAssetType.Texture:
                assetData = new OvrAvatarAssetTexture(assetID, asset);
                break;

            case ovrAvatarAssetType.Material:
                assetData = new OvrAvatarAssetMaterial(assetID, asset);
                break;

            default:
                throw new NotImplementedException(string.Format("Unsupported asset type format {0}", assetType.ToString()));
            }

            HashSet <assetLoadedCallback> callbackSet;
            if (assetLoadedCallbacks.TryGetValue(assetMessage.assetID, out callbackSet))
            {
                assetCache.Add(assetID, assetData);

                foreach (var callback in callbackSet)
                {
                    callback(assetData);
                }

                assetLoadedCallbacks.Remove(assetMessage.assetID);
            }
            else
            {
                Debug.LogWarning("Loaded an asset with no owner: " + assetMessage.assetID);
            }

            break;
        }

        case ovrAvatarMessageType.AvatarSpecification:
        {
            ovrAvatarMessage_AvatarSpecification spec = CAPI.ovrAvatarMessage_GetAvatarSpecification(message);
            HashSet <specificationCallback>      callbackSet;
            if (specificationCallbacks.TryGetValue(spec.oculusUserID, out callbackSet))
            {
                foreach (var callback in callbackSet)
                {
                    callback(spec.avatarSpec);
                }

                specificationCallbacks.Remove(spec.oculusUserID);
            }
            else
            {
                Debug.LogWarning("Error, got an avatar specification callback from a user id we don't have a record for: " + spec.oculusUserID);
            }
            break;
        }

        default:
            throw new NotImplementedException("Unhandled ovrAvatarMessageType: " + messageType);
        }
        CAPI.ovrAvatarMessage_Free(message);
    }