Exemplo n.º 1
0
        public override void Serialize(SerializedAssets serializedAssets, object[] serializeOptions, NodeBase objNode, List <Action <NodeBase> > postSerializeActions)
        {
            //Make sure this is always 36 characters long.
            this.referenceID = this.rootNode.GenerateID();

            ComponentNode scriptNode = new ComponentNode(PCFResourceType.CLASS, referenceID, null, this.type.Name.ToString());

            //Parent top level scripts to ObjectNode.
            objNode.AddChildNode(scriptNode);

            FieldInfo[] fields = this.type.GetFields();

            for (int i = 0; i < fields.Length; i++)
            {
                if (fields[i].IsPublic && !fields[i].IsStatic)
                {
                    SerializeField(serializedAssets, serializeOptions, scriptNode, postSerializeActions, fields[i]);
                }
            }

            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = ProtocolBufferSerializer.SerializeFieldData(this.type, this.fieldName, this.arrayItem, this.type.Assembly);
            resource.Serialize(this.referenceID, MetaDataType.PROTOBUF, metaDataBuffer, null);

            serializedAssets.AddResource(referenceID, PCFResourceType.CLASS, resource);
        }
Exemplo n.º 2
0
        public override void Serialize(SerializedAssets serializedAssets, object[] serializeOptions, NodeBase objNode, List <Action <NodeBase> > postSerializeActions)
        {
            //Make sure this is always 36 characters long.
            this.referenceID = this.rootNode.GenerateID();

            byte[] bytes = null;

            if (this.type == typeof(string))
            {
                if (this.value != null)
                {
                    bytes = System.Text.Encoding.UTF8.GetBytes((string)this.value);
                }
            }
            else if (this.type == typeof(int))
            {
                bytes = BitConverter.GetBytes((int)this.value);
            }
            else if (this.type == typeof(float))
            {
                bytes = BitConverter.GetBytes((float)this.value);
            }
            else if (this.type == typeof(double))
            {
                bytes = BitConverter.GetBytes((double)this.value);
            }
            else if (this.type == typeof(bool))
            {
                bytes = BitConverter.GetBytes((bool)this.value);
            }
            else if (this.type == typeof(byte[]))
            {
                bytes = (byte[])this.value;
            }

            if (bytes != null)
            {
                ComponentNode componentNode = new ComponentNode(PCFResourceType.PRIMITIVE, referenceID, null, this.type.Name.ToString());
                objNode.AddChildNode(componentNode);

                AssetResource resource = new AssetResource(false);

                byte[] metaDataBuffer = ProtocolBufferSerializer.SerializeFieldData(this.type, this.fieldName, this.arrayItem, this.type.Assembly);
                resource.Serialize(this.referenceID, MetaDataType.PROTOBUF, metaDataBuffer, bytes);

                serializedAssets.AddResource(referenceID, PCFResourceType.PRIMITIVE, resource);
            }
        }
Exemplo n.º 3
0
        public override void Serialize(SerializedAssets serializedAssets, object[] serializeOptions, NodeBase objNode, List <Action <NodeBase> > postserializeActions)
        {
            //Make sure this is always 36 characters long.
            this.referenceID = this.rootNode.GenerateID();

            ComponentNode scriptNode = new ComponentNode(PCFResourceType.GRADIENT, referenceID, null, typeof(UnityEngine.Gradient).Name.ToString());

            objNode.AddChildNode(scriptNode);

            GradientColorKey[] colorKeys          = this.gradient.colorKeys;
            System.Object[]    convertedColorKeys = new System.Object[colorKeys.Length];

            for (int i = 0; i < colorKeys.Length; i++)
            {
                GradientColorKey colorKey = colorKeys[i];
                convertedColorKeys[i] = colorKey as System.Object;
            }

            UnitySerializeCollection colorKeySerializer = new UnitySerializeCollection(convertedColorKeys, typeof(UnityEngine.GradientColorKey), null, "colorKeys", rootNode);

            colorKeySerializer.Serialize(serializedAssets, serializeOptions, scriptNode, postserializeActions);


            GradientAlphaKey[] alphaKeys          = this.gradient.alphaKeys;
            System.Object[]    convertedAlphaKeys = new System.Object[alphaKeys.Length];

            for (int i = 0; i < alphaKeys.Length; i++)
            {
                GradientAlphaKey alphaKey = alphaKeys[i];
                convertedAlphaKeys[i] = alphaKey as System.Object;
            }

            UnitySerializeCollection alphaKeySerializer = new UnitySerializeCollection(convertedAlphaKeys, typeof(UnityEngine.GradientAlphaKey), null, "alphaKeys", rootNode);

            alphaKeySerializer.Serialize(serializedAssets, serializeOptions, scriptNode, postserializeActions);

            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = ProtocolBufferSerializer.SerializeFieldData(this.gradient.GetType(), this.fieldName, this.arrayItem, this.gradient.GetType().Assembly);
            resource.Serialize(this.referenceID, MetaDataType.PROTOBUF, metaDataBuffer, null);

            serializedAssets.AddResource(referenceID, PCFResourceType.GRADIENT, resource);
        }
        public override void Serialize(SerializedAssets serializedAssets, object[] serializeOptions, NodeBase objNode, List <Action <NodeBase> > postserializeActions)
        {
            this.referenceID = this.rootNode.GenerateID();

            ComponentNode componentNode = new ComponentNode(PCFResourceType.TRANSFORMPOINTER, referenceID, null, this.transform.GetType().Name.ToString());

            objNode.AddChildNode(componentNode);

            //Find the node this node points to in the tree.
            NodeBase transformNode = FindTransformInTree(rootNode, this.transform.name);
            UInt32   referencedID  = transformNode.GetReferenceID();

            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = ProtocolBufferSerializer.SerializeFieldData(this.transform.GetType(), this.fieldName, this.arrayItem, this.transform.GetType().Assembly);
            resource.Serialize(this.referenceID, MetaDataType.PROTOBUF, metaDataBuffer, BitConverter.GetBytes(referencedID));

            serializedAssets.AddResource(referenceID, PCFResourceType.TRANSFORMPOINTER, resource);

            this.pointedID = transformNode.GetReferenceID();
        }