Ejemplo n.º 1
0
        public static UnityRootNode CreateNodeTree(Dictionary <PCFResourceType, DataBlockBase> dataBlocks, IFileHandle filePath, NodeFactory nodeFactory)
        {
            NodeBlock nodeBlock = dataBlocks[PCFResourceType.NODE] as NodeBlock;

            //Create and hook up node graph, but do no actual deserialization.
            UnityNodeBase node = nodeBlock.RecreateNodeGraph <UnityNodeBase>(nodeFactory);

            UnityRootNode rootNode = node as UnityRootNode;

            //Give rootnode a reference to the file we operate on, some nodes stream their data from this file.
            rootNode.SetFile(filePath);

            return(rootNode);
        }
Ejemplo n.º 2
0
        public override void Deserialize(Dictionary <PCFResourceType, DataBlockBase> dataBlocks,
                                         UnityNodeBase parentNode,
                                         ResourceResponse resourceResponse,
                                         List <Action <UnityNodeBase> > postInstallActions,
                                         bool optimizedLoad)
        {
            if (!this.isDeserialized)
            {
                ResourceBlock dataBlock = dataBlocks[resourceType] as ResourceBlock;
                AssetResource resource  = dataBlock.GetResource(this.referenceID);

                if (resource != null)
                {
                    this.resourceResponse = resourceResponse;

                    byte[]  metaDataBuffer = resource.GetMetaData();
                    JObject metaData       = JObject.Parse(System.Text.Encoding.UTF8.GetString(metaDataBuffer));

                    this.fieldName       = metaData.Value <string>("fieldName");
                    this.audioPlayerName = metaData.Value <string>("name");
                    this.arrayItem       = bool.Parse(metaData.Value <string>("arrayItem"));
                    this.samplesLength   = metaData.Value <int>("samples");

                    //Lets us know if this audioclip should be streamed directly from the main pcf file.
                    this.streamed = bool.Parse(metaData.Value <string>("streamed"));

                    if (resource.IsStreamed())
                    {
                        UnityNodeBase current = parentNode;
                        while (current.ParentNode != null)
                        {
                            current = current.ParentNode;
                        }

                        IFileHandle filePath = null;
                        if (current is UnityRootNode)
                        {
                            UnityRootNode rootNode = current as UnityRootNode;
                            filePath = rootNode.GetFile();
                        }

                        if (filePath != null & filePath.Exists)
                        {
                            int streamPosition = (int)resource.GetStreamPosition();
                            int streamLength   = (int)resource.GetStreamLength();

                            //Copy ogg file to temporary cache path for use.
                            this.cachePath = Application.temporaryCachePath + "/" + this.referenceID + ".ogg";

                            if (File.Exists(this.cachePath))
                            {
                                File.Delete(this.cachePath);
                            }

                            Stream     streamedFile = filePath.GetFileStream(FileMode.Open);
                            FileStream oggOutput    = new FileStream(this.cachePath, FileMode.Create, FileAccess.Write);

                            streamedFile.Seek(streamPosition, SeekOrigin.Begin);
                            int bytesLeft    = streamLength;
                            int bytesWritten = 0;

                            while (bytesLeft > 0)
                            {
                                int bytesRead    = streamedFile.Read(COPY_BUFFER, 0, Math.Min(bytesLeft, COPY_BUFFER.Length));
                                int bytesToWrite = COPY_BUFFER.Length;

                                //Should happen for the last buffer we write.
                                if (bytesLeft < COPY_BUFFER.Length)
                                {
                                    bytesToWrite = bytesLeft;
                                }

                                oggOutput.Write(COPY_BUFFER, 0, bytesToWrite);

                                bytesWritten += bytesToWrite;
                                bytesLeft    -= bytesRead;
                            }

                            oggOutput.Dispose();
                            oggOutput.Close();

                            streamedFile.Close();

                            if (bytesWritten != streamLength)
                            {
                                Debug.LogError("Missmatch in ogg cache file!");
                            }

                            if (streamed)
                            {
                                this.audioPlayer = new StreamedAudioPlayer(this.referenceID, this.audioPlayerName, this.cachePath, this.samplesLength);
                            }
                            else
                            {
                                this.audioPlayer = new BufferedAudioPlayer(this.referenceID, this.audioPlayerName, this.cachePath, this.samplesLength);
                            }
                        }
                    }

                    if (resourceResponse != null && this.audioPlayer != null)
                    {
                        if (arrayItem)
                        {
                            this.index = resourceResponse.GetFieldDeserializer.SetArrayItem(this.audioPlayer.GetAudioClip());
                        }
                        else
                        {
                            resourceResponse.GetFieldDeserializer.SetField(fieldName, this.audioPlayer.GetAudioClip());
                        }
                    }
                }

                this.isDeserialized = true;
            }
        }
Ejemplo n.º 3
0
        public UnityNodeBase CreateNodeImplementation(string nodeName, PCFResourceType resourceType, UInt32 referenceID)
        {
            UnityNodeBase recreatedNode = null;

            if (this.customCreators != null && this.customCreators.ContainsKey(resourceType))
            {
                recreatedNode = this.customCreators[resourceType](nodeName, resourceType, referenceID);
            }
            else
            {
                switch (resourceType)
                {
                case PCFResourceType.ROOT:
                    recreatedNode = new UnityRootNode(nodeName, referenceID);
                    break;

                case PCFResourceType.OBJECT:
                    recreatedNode = new UnityObjectNode(nodeName, referenceID);
                    break;

                case PCFResourceType.TRANSFORM:
                    recreatedNode = new UnityTransformNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.TRANSFORMPOINTER:
                    recreatedNode = new UnityTransformPointerNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.MESH:
                    recreatedNode = new UnityMeshNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.ANIMATOR:
                    recreatedNode = new UnityAnimatorNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.AUDIO:
                    recreatedNode = new UnityAudioNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.AVATAR:
                    recreatedNode = new UnityAvatarReferenceNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.SKINNEDMESH:
                    recreatedNode = new UnitySkinnedMeshNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.SCRIPT:
                    recreatedNode = new UnityScriptNode(nodeName, resourceType, referenceID, null);
                    break;

                case PCFResourceType.MATERIAL:
                    recreatedNode = new UnityMaterialNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.MATERIALPOINTER:
                    recreatedNode = new UnityMaterialPointerNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.TEXTURE:
                    recreatedNode = new UnityTextureNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.CAMERA:
                    recreatedNode = new UnityCameraNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.LIGHT:
                    recreatedNode = new UnityLightNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.LIGHTPROBES:
                    recreatedNode = new UnityLightProbesNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.COLLIDER:
                    recreatedNode = new UnityColliderNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.PRIMITIVE:
                    recreatedNode = new UnityPrimitiveNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.COLLECTION:
                    recreatedNode = new UnityCollectionNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.POINTERCOLLECTION:
                    recreatedNode = new UnityPointerCollectionNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.CLASS:
                    recreatedNode = new UnityClassNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.INTERNALBUNDLE:
                    recreatedNode = new UnityInternalBundleNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.GRADIENT:
                    recreatedNode = new UnityGradientNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.ANIMATION:
                    recreatedNode = new UnityAnimationNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.ANIMATIONCLIP:
                    recreatedNode = new UnityAnimationClipNode(nodeName, resourceType, referenceID);
                    break;

                case PCFResourceType.ANIMATIONCLIPREFERENCE:
                    recreatedNode = new UnityAnimationClipPointerNode(nodeName, resourceType, referenceID);
                    break;
                }
            }


            return(recreatedNode);
        }