コード例 #1
0
        /// <summary>
        /// Fills in gltfTexture.unityTexture with a Texture2D.
        /// </summary>
        /// <param name="gltfTexture">The glTF texture to convert.</param>
        /// <param name="loader">The IUriLoader to use for loading image files.</param>
        /// <returns>On completion of the coroutine, gltfTexture.unityTexture will be non-null
        /// on success.</returns>
        private static IEnumerable ConvertTextureCoroutine(
            GltfTextureBase gltfTexture, IUriLoader loader)
        {
            if (gltfTexture.unityTexture != null)
            {
                throw new InvalidOperationException("Already converted");
            }

            if (gltfTexture.SourcePtr == null)
            {
                Debug.LogErrorFormat("No image for texture {0}", gltfTexture.GltfId);
                yield break;
            }

            Texture2D tex;

            if (gltfTexture.SourcePtr.data != null)
            {
                // This case is hit if the client code hooks up its own threaded
                // texture-loading mechanism.
                var data = gltfTexture.SourcePtr.data;
                tex = new Texture2D(data.colorWidth, data.colorHeight, data.format, true);
                yield return(null);

                tex.SetPixels32(data.colorData);
                yield return(null);

                tex.Apply();
                yield return(null);
            }
            else
            {
#if UNITY_EDITOR
                // Prefer to load the Asset rather than create a new Texture2D;
                // that lets the resulting prefab reference the texture rather than
                // embedding it inside the prefab.
                tex = loader.LoadAsAsset(gltfTexture.SourcePtr.uri);
#else
                tex = null;
#endif
                if (tex == null)
                {
                    byte[] textureBytes;
                    using (IBufferReader r = loader.Load(gltfTexture.SourcePtr.uri)) {
                        textureBytes = new byte[r.GetContentLength()];
                        r.Read(textureBytes, destinationOffset: 0, readStart: 0, readSize: textureBytes.Length);
                    }
                    tex = new Texture2D(1, 1);
                    tex.LoadImage(textureBytes, markNonReadable: false);
                    yield return(null);
                }
            }

            tex.name = SanitizeName(gltfTexture.SourcePtr.uri);
            gltfTexture.unityTexture = tex;
        }
コード例 #2
0
        private int Read(IBufferReader reader)
        {
            if (_lookAhead != char.MinValue)
            {
                var tmp = _lookAhead;
                _lookAhead = char.MinValue;
                return(tmp);
            }

            return(reader.Read());
        }
コード例 #3
0
        private int Read(IBufferReader reader)
        {
            if (_parseThisFirst != char.MinValue)
            {
                var tmp = _parseThisFirst;
                _parseThisFirst = char.MinValue;
                return tmp;
            }

            return reader.Read();
        }
コード例 #4
0
        private int Read(IBufferReader reader)
        {
            if (_lookAhead != char.MinValue)
            {
                var tmp = _lookAhead;
                _lookAhead = char.MinValue;
                return tmp;
            }

            return reader.Read();
        }
コード例 #5
0
        /// <summary>
        /// Read all header bytes from the incoming buffer 
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns><c>false</c> if we have not received all bytes yet; otherwise <c>true</c>.</returns>
        protected virtual bool ReadHeaderBytes(IBufferReader stream)
        {
            var bytesLeftInStream = stream.Count - stream.Position;
            var bytesToCopy = bytesLeftInStream < _bytesLeft
                                  ? bytesLeftInStream
                                  : _bytesLeft;

            stream.Read(_header, 0, bytesToCopy);

            _bytesLeft -= bytesToCopy;
            if (_bytesLeft > 0)
                return false;

            _packet = CreatePacket(_header);

            _bytesLeft = _packet.ContentLength;
            _parserMethod = ReadBodyBytes;
            return true;
        }
コード例 #6
0
        /// <summary>
        /// Read all header bytes from the incoming buffer
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns><c>false</c> if we have not received all bytes yet; otherwise <c>true</c>.</returns>
        protected virtual bool ReadHeaderBytes(IBufferReader stream)
        {
            var bytesLeftInStream = stream.Count - stream.Position;
            var bytesToCopy       = bytesLeftInStream < _bytesLeft
                                  ? bytesLeftInStream
                                  : _bytesLeft;

            stream.Read(_header, 0, bytesToCopy);

            _bytesLeft -= bytesToCopy;
            if (_bytesLeft > 0)
            {
                return(false);
            }

            _packet = CreatePacket(_header);

            _bytesLeft    = _packet.ContentLength;
            _parserMethod = ReadBodyBytes;
            return(true);
        }
コード例 #7
0
        internal static void ReadBufferAsync(IForwarder forwarder, IBufferReader bufferReader)
        {
            var buffer = bufferReader.Read();
            var packet = Deserialize(buffer, out var bytesConsumed);

            if (bytesConsumed == 0)
            {
                return;
            }

            switch (packet)
            {
            case Connect connect:
                forwarder.Dispatch(connect);
                break;

            case ConnAck connAck:
                forwarder.Dispatch(connAck);
                break;

            case Disconnect disconnect:
                forwarder.Dispatch(disconnect);
                break;

            case PubAck pubAck:
                forwarder.Dispatch(pubAck);
                break;

            case PubRel pubRel:
                forwarder.Dispatch(pubRel);
                break;

            case PubRec pubRec:
                forwarder.Dispatch(pubRec);
                break;

            case PubComp pubComp:
                forwarder.Dispatch(pubComp);
                break;

            case PingReq pingReq:
                forwarder.Dispatch(pingReq);
                break;

            case PingResp pingResp:
                forwarder.Dispatch(pingResp);
                break;

            case Subscribe subscribe:
                forwarder.Dispatch(subscribe);
                break;

            case SubAck subAck:
                forwarder.Dispatch(subAck);
                break;

            case Unsubscribe unsubscribe:
                forwarder.Dispatch(unsubscribe);
                break;

            case UnsubAck unsubAck:
                forwarder.Dispatch(unsubAck);
                break;
            }

            bufferReader.Advance(bytesConsumed);
        }