Esempio n. 1
0
        public override void Reconstruct()
        {
            Debug.Log("reconstruct audio node");

            if (this.audioPlayer != null)
            {
                this.audioPlayer.Destroy();
            }

            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)
                {
                    FieldDeserializer field = resourceResponse.GetFieldDeserializer;
                    field.SetArrayItem(this.audioPlayer.GetAudioClip(), this.index);
                }
                else
                {
                    resourceResponse.GetFieldDeserializer.SetField(fieldName, this.audioPlayer.GetAudioClip());
                }
            }
        }
        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);

                byte[] metaDataBuffer         = resource.GetMetaData();
                SerializedFieldData fieldData = ProtocolBufferSerializer.DeserializeFieldData(metaDataBuffer);
                string assemblyName           = ProtocolBufferSerializer.GetAssemblyName(fieldData.assemblyType);
                string scriptTypeName         = fieldData.typeName;
                string fieldName = fieldData.fieldName;

                Type scriptType = null;

                //Qualify type check with assembly name, GetType only looks in current assembly otherwise.
                if (!string.IsNullOrEmpty(assemblyName))
                {
                    scriptType = Type.GetType(scriptTypeName + ", " + assemblyName);
                }
                else
                {
                    scriptType = Type.GetType(scriptTypeName);
                }

                if (scriptType != null)
                {
                    Gradient gradient = new Gradient();

                    PropertySetter colorKeySetter = new PropertySetter("colorKeys", (System.Object val) => { gradient.colorKeys = val as GradientColorKey[]; });
                    PropertySetter alphaKeySetter = new PropertySetter("alphaKeys", (System.Object val) => { gradient.alphaKeys = val as GradientAlphaKey[]; });

                    List <PropertySetter> customValueSetters = new List <PropertySetter>();
                    customValueSetters.Add(colorKeySetter);
                    customValueSetters.Add(alphaKeySetter);

                    FieldDeserializer fieldDeserializer = new FieldDeserializer(customValueSetters, gradient);
                    ResourceResponse  response          = new ResourceResponse();
                    response.SetFieldDeserializer(fieldDeserializer);

                    for (int i = 0; i < this.ChildNodes.Count; i++)
                    {
                        UnityNodeBase child = this.ChildNodes[i];

                        child.Deserialize(dataBlocks, this, response, postInstallActions, optimizedLoad);
                    }

                    if (resourceResponse != null)
                    {
                        resourceResponse.GetFieldDeserializer.SetField(fieldName, gradient);
                    }
                }

                this.isDeserialized = true;
            }
        }
Esempio n. 3
0
        public override void Deserialize(Dictionary <PCFResourceType, DataBlockBase> dataBlocks,
                                         UnityNodeBase parentNode,
                                         ResourceResponse resourceResponse,
                                         List <Action <UnityNodeBase> > postInstallActions,
                                         bool optimizedLoad)
        {
            if (!this.isDeserialized)
            {
                Type scriptType = typeof(Animation);

                if (scriptType != null)
                {
                    Animation animation = parentNode.GetGameObject().AddComponent(scriptType) as Animation;

                    PropertySetter clipSetter = new PropertySetter("clip", (System.Object val) => { animation.clip = val as AnimationClip; });

                    List <PropertySetter> customValueSetters = new List <PropertySetter>();
                    customValueSetters.Add(clipSetter);

                    FieldDeserializer fieldDeserializer = new FieldDeserializer(customValueSetters, animation);

                    ResourceResponse response = new ResourceResponse();
                    response.SetFieldDeserializer(fieldDeserializer);

                    foreach (UnityNodeBase node in this.ChildNodes)
                    {
                        node.Deserialize(dataBlocks, this, response, postInstallActions, optimizedLoad);
                    }
                }

                this.isDeserialized = true;
            }
        }
        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)
                {
                    byte[] metaDataBuffer = resource.GetMetaData();
                    SerializedCollectionData collectionData = ProtocolBufferSerializer.DeserializeCollectionData(metaDataBuffer);
                    string assemblyName   = ProtocolBufferSerializer.GetAssemblyName(collectionData.assemblyType);
                    string scriptTypeName = collectionData.typeName;
                    string fieldName      = collectionData.fieldName;
                    int    itemCount      = collectionData.count;
                    Type   scriptType     = null;

                    //Qualify type check with assembly name, GetType only looks in current assembly otherwise.
                    if (!string.IsNullOrEmpty(assemblyName))
                    {
                        scriptType = Type.GetType(scriptTypeName + ", " + assemblyName);
                    }
                    else
                    {
                        scriptType = Type.GetType(scriptTypeName);
                    }

                    if (scriptType != null)
                    {
                        Array array = Array.CreateInstance(scriptType, itemCount);

                        if (array != null)
                        {
                            FieldDeserializer arrayDeserializer = new FieldDeserializer(array);
                            ResourceResponse  response          = new ResourceResponse();
                            response.SetFieldDeserializer(arrayDeserializer);

                            foreach (UnityNodeBase node in this.ChildNodes)
                            {
                                node.Deserialize(dataBlocks, this, response, postInstallActions, optimizedLoad);
                                arrayDeserializer.IncrementIndex();
                            }
                        }

                        if (resourceResponse != null)
                        {
                            resourceResponse.GetFieldDeserializer.SetField(fieldName, array);
                        }
                    }
                }

                this.isDeserialized = true;
            }
        }
Esempio n. 5
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);

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

                string scriptName = metaData["scriptname"].ToString();
                Type   scriptType = null;

                if (scriptMask == null)
                {
                    scriptType = Type.GetType(scriptName);
                }
                else if (this.scriptMask != null && this.scriptMask.Contains(scriptName))
                {
                    scriptType = Type.GetType(scriptName);
                }

                if (scriptType != null)
                {
                    this.script = parentNode.GetGameObject().AddComponent(scriptType) as MonoBehaviour;
                    FieldDeserializer fieldDeserializer = new FieldDeserializer(scriptType.GetFields(), this.script);

                    ResourceResponse response = new ResourceResponse();
                    response.SetFieldDeserializer(fieldDeserializer);

                    foreach (UnityNodeBase node in this.ChildNodes)
                    {
                        node.Deserialize(dataBlocks, this, response, postInstallActions, optimizedLoad);
                    }
                }

                this.isDeserialized = true;
            }
        }
Esempio n. 6
0
 public void SetFieldDeserializer(FieldDeserializer fieldDeserializer)
 {
     this.fieldDeserializer = fieldDeserializer;
 }
Esempio n. 7
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)
                {
                    byte[] metaDataBuffer         = resource.GetMetaData();
                    SerializedFieldData fieldData = ProtocolBufferSerializer.DeserializeFieldData(metaDataBuffer);

                    string assemblyName = ProtocolBufferSerializer.GetAssemblyName(fieldData.assemblyType);

                    if (assemblyName != null)
                    {
                        Type scriptType = null;

                        //Qualify type check with assembly name, GetType only looks in current assembly otherwise.
                        if (!string.IsNullOrEmpty(assemblyName))
                        {
                            scriptType = Type.GetType(fieldData.typeName + ", " + assemblyName);
                        }
                        else
                        {
                            scriptType = Type.GetType(fieldData.typeName);
                        }

                        if (scriptType != null)
                        {
                            System.Object objectInstance = Activator.CreateInstance(scriptType);

                            FieldDeserializer fieldDeserializer = new FieldDeserializer(scriptType.GetFields(), objectInstance);
                            ResourceResponse  response          = new ResourceResponse();
                            response.SetFieldDeserializer(fieldDeserializer);

                            foreach (UnityNodeBase node in this.ChildNodes)
                            {
                                node.Deserialize(dataBlocks, this, response, postInstallActions, optimizedLoad);
                            }

                            //if fieldname is empty its an array item.
                            if (resourceResponse != null)
                            {
                                if (fieldData.arrayItem)
                                {
                                    resourceResponse.GetFieldDeserializer.SetArrayItem(objectInstance);
                                }
                                else
                                {
                                    resourceResponse.GetFieldDeserializer.SetField(fieldData.fieldName, objectInstance);
                                }
                            }
                        }
                    }
                }

                this.isDeserialized = true;
            }
        }