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 componentNode = new ComponentNode(PCFResourceType.ANIMATOR, referenceID, null);

            //Component nodes must always be parented to objNodes.
            objNode.AddChildNode(componentNode);

            //Serialize child node ( the avatar )
            //We serialize as reference.
            UnitySerializeAvatar avatarReferenceSerializer = new UnitySerializeAvatar(this.animator, this.parentGO, this.rootNode);

            avatarReferenceSerializer.Serialize(serializedAssets, serializeOptions, componentNode, postSerializeActions);

            JObject metaData = new JObject();

            //Serialize apply root motion variable in the metadata.
            metaData["applyRootMotion"] = this.animator.applyRootMotion;

            //Serialize avatarReference in the metadata.
            metaData["avatarReferenceID"] = avatarReferenceSerializer.GetReferenceID();

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));
            resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, null);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }
Esempio 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();

            ComponentNode componentNode = new ComponentNode(PCFResourceType.TRANSFORM, referenceID, null, this.transform.name);

            //Component nodes must always be parented to objNodes.
            objNode.AddChildNode(componentNode);

            Vector3[] vectors = new Vector3[3];
            vectors[0] = this.transform.localPosition;
            vectors[1] = this.transform.localRotation.eulerAngles;
            vectors[2] = this.transform.localScale;

            byte[] bytes = WriteVector3ArrayToBytes(vectors);

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            resource.Serialize(referenceID, MetaDataType.UNKOWN, null, bytes);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }
        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 componentNode = new ComponentNode(PCFResourceType.MESH, referenceID, null);

            //Component nodes must always be parented to objNodes.
            objNode.AddChildNode(componentNode);

            //Serialize mesh into a byte array.
            byte[] bytes = MeshSerializeUtilities.WriteMesh(this.meshFilter.sharedMesh, true, false);

            //Serialize Material
            UnitySerializeMaterial materialSerializer = new UnitySerializeMaterial(this.meshRenderer.sharedMaterial, this.rootNode);

            materialSerializer.Serialize(serializedAssets, serializeOptions, componentNode, postSerializeActions);

            //Make sure mesh knows that material it needs.
            JObject metaData = new JObject();

            metaData["materialID"] = materialSerializer.GetPointerID();

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));
            resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, bytes);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }
        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 componentNode = new ComponentNode(PCFResourceType.SKINNEDMESH, referenceID, null);

            //Component nodes must always be parented to objNodes.
            objNode.AddChildNode(componentNode);

            byte[] bytes = MeshSerializeUtilities.WriteMesh(this.skinnedMesh.sharedMesh, true, true);

            //Serialize Material
            UnitySerializeMaterial materialSerializer = new UnitySerializeMaterial(this.skinnedMesh.sharedMaterial, this.rootNode);

            materialSerializer.Serialize(serializedAssets, serializeOptions, componentNode, postSerializeActions);

            //Make sure mesh knows that material it needs.
            JObject metaData = new JObject();

            metaData["materialID"] = materialSerializer.GetPointerID();
            metaData["rootBone"]   = skinnedMesh.rootBone.name;

            if (skinnedMesh.probeAnchor != null)
            {
                metaData["probeAnchor"] = skinnedMesh.probeAnchor.name;
            }

            metaData["quality"] = (int)skinnedMesh.quality;

            JArray bones = new JArray();

            for (int i = 0; i < skinnedMesh.bones.Length; i++)
            {
                bones.Add(skinnedMesh.bones[i].name);
            }
            metaData["bones"] = bones;

            JArray blendShapeWeights = new JArray();

            for (int i = 0; i < skinnedMesh.sharedMesh.blendShapeCount; i++)
            {
                blendShapeWeights.Add(skinnedMesh.GetBlendShapeWeight(i));
            }
            metaData["blendShapeWeights"] = blendShapeWeights;

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));
            resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, bytes);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }
        public override void Serialize(SerializedAssets serializedAssets, object[] serializeOptions, NodeBase objNode, List <Action <NodeBase> > postSerializeActions)
        {
                        #if UNITY_EDITOR
            //Make sure this is always 36 characters long.
            this.referenceID = this.rootNode.GenerateID();

            ComponentNode componentNode = new ComponentNode(PCFResourceType.TEXTURE, referenceID, null);

            //Component nodes must always be parented to objNodes.
            objNode.AddChildNode(componentNode);

            if (this.texture != null)
            {
                TextureSerializeOpts serializeOption = null;
                for (int i = 0; i < serializeOptions.Length; i++)
                {
                    object opt = serializeOptions[i];

                    if (opt is TextureSerializeOpts)
                    {
                        serializeOption = opt as TextureSerializeOpts;
                        break;
                    }
                }

                if (serializeOption == null)
                {
                    return;
                }

                //Create serialized asset by converting data to a bytearray and give it to the constructor.
                AssetResource resource = new AssetResource(false);

                TextureDataFormat format      = TextureDataFormat.Empty;
                byte[]            textureData = serializeOption.PackageTexture(this.texture, serializedAssets, referenceID, ref format);

                JObject metaData = new JObject();
                metaData["width"]         = this.texture.width;
                metaData["height"]        = this.texture.height;
                metaData["textureFormat"] = (int)format;

                byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));

                resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, textureData);

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

                //Nodes store their resource when serializing
                componentNode.SetSerializer(this);
            }
                        #endif
        }
        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 componentNode = new ComponentNode(PCFResourceType.COLLIDER, referenceID, null);

            //Material nodes can and are most likely to be children of other component nodes.
            objNode.AddChildNode(componentNode);

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            resource.Serialize(referenceID, MetaDataType.UNKOWN, null, null);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }
Esempio n. 7
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();

            AvatarSerializeOpts serializeOption = null;

            for (int i = 0; i < serializeOptions.Length; i++)
            {
                object opt = serializeOptions[i];

                if (opt is AvatarSerializeOpts)
                {
                    serializeOption = opt as AvatarSerializeOpts;
                    break;
                }
            }

            if (serializeOption == null)
            {
                return;
            }

            ComponentNode componentNode = new ComponentNode(PCFResourceType.AVATAR, referenceID, null);

            //Component nodes must always be parented to objNodes.
            objNode.AddChildNode(componentNode);

            JObject metaData = serializeOption.SerializeAvatar(this.parentGO, this.animator);

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));
            resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, null);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }
Esempio n. 8
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 componentNode = new ComponentNode(PCFResourceType.LIGHT, referenceID, null);

            //Material nodes can and are most likely to be children of other component nodes.
            objNode.AddChildNode(componentNode);

            byte[] bytes = new byte[24];

            float[] data = new float[6];

            data[0] = this.light.color.r;
            data[1] = this.light.color.g;
            data[2] = this.light.color.b;
            data[3] = this.light.color.a;
            data[4] = (float)this.light.type;
            data[5] = this.light.intensity;

            for (int i = 0; i < data.Length; i++)
            {
                Buffer.BlockCopy(BitConverter.GetBytes(data[i]), 0, bytes, 4 * i, 4);
            }

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            resource.Serialize(referenceID, MetaDataType.UNKOWN, null, bytes);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }
Esempio n. 9
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();

                        #if UNITY_EDITOR
            string   assetPath     = AssetDatabase.GetAssetPath(animationClip);
            NodeBase animationNode = CheckSharedAnimationClip(this.rootNode, assetPath);

            if (animationNode != null)
            {
                UInt32 animationID = animationNode.GetReferenceID();

                ComponentNode componentNode = new ComponentNode(PCFResourceType.ANIMATIONCLIPREFERENCE, referenceID, null, typeof(UnityEngine.AnimationClip).Name.ToString());

                objNode.AddChildNode(componentNode);

                byte[] bytes = BitConverter.GetBytes(animationID);

                JObject metaData = new JObject();
                metaData["fieldName"] = this.fieldName;

                AssetResource resource = new AssetResource(false);

                byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));

                resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, bytes);

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

                this.pointedID = animationID;
            }
            else
            {
                ComponentNode componentNode = new ComponentNode(PCFResourceType.ANIMATIONCLIP, referenceID, assetPath, typeof(UnityEngine.AnimationClip).Name.ToString());

                objNode.AddChildNode(componentNode);

                EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(animationClip);

                AnimationCurve          initialCurve            = AnimationUtility.GetEditorCurve(animationClip, curveBindings[0]);
                SerializedAnimationClip serializedAnimationClip = new SerializedAnimationClip();

                serializedAnimationClip.PostWrapMode = (int)initialCurve.postWrapMode;
                serializedAnimationClip.PreWrapMode  = (int)initialCurve.preWrapMode;

                for (int i = 0; i < curveBindings.Length; i++)
                {
                    string propertyName = curveBindings[i].propertyName;

                    AnimationCurve animCurve = AnimationUtility.GetEditorCurve(animationClip, curveBindings[i]);

                    SerializedAnimationKeyFrame[] serializedKeyFrames = new SerializedAnimationKeyFrame[animCurve.keys.Length];
                    for (int j = 0; j < animCurve.keys.Length; j++)
                    {
                        serializedKeyFrames[j] = new SerializedAnimationKeyFrame();

                        serializedKeyFrames[j].InTagent   = animCurve.keys[j].inTangent;
                        serializedKeyFrames[j].OutTangent = animCurve.keys[j].outTangent;
                        serializedKeyFrames[j].Time       = animCurve.keys[j].time;
                        serializedKeyFrames[j].Value      = animCurve.keys[j].value;
                    }

                    serializedAnimationClip.AddChannel(AnimationClipUtils.GetAnimationClipChannelName(propertyName), serializedKeyFrames);
                }

                JObject metaData = new JObject();
                metaData["name"]      = animationClip.name;
                metaData["frameRate"] = animationClip.frameRate;
                metaData["wrapMode"]  = (int)animationClip.wrapMode;
                metaData["legacy"]    = animationClip.legacy;
                metaData["fieldName"] = this.fieldName;

                byte[] data = ProtocolBufferSerializer.SerializeAnimationClipData(serializedAnimationClip);

                AssetResource resource = new AssetResource(false);

                byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));
                resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, data);

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

                //Nodes store their resource when serializing
                componentNode.SetSerializer(this);

                //Make sure caller can get the actual material referenceID when serializing its metadata.
                this.pointedID = this.referenceID;
            }
                        #endif
        }
        public override void Serialize(SerializedAssets serializedAssets, object[] serializeOptions, NodeBase objNode, List <Action <NodeBase> > postSerializeActions)
        {
                        #if UNITY_EDITOR
            //Make sure this is always 36 characters long.
            this.referenceID = this.rootNode.GenerateID();

            //Check if node hierarchy contains this material already.
            string   path         = AssetDatabase.GetAssetPath(this.material);
            NodeBase materialNode = CheckSharedMaterial(this.rootNode, path);

            //If material is already serialized (aka shared we simply serialize a pointer to it.
            if (materialNode != null)
            {
                //Debug.Log("Shared Material: " + path);

                UInt32 materialID = materialNode.GetReferenceID();

                ComponentNode componentNode = new ComponentNode(PCFResourceType.MATERIALPOINTER, referenceID, null);

                objNode.AddChildNode(componentNode);

                byte[] bytes = BitConverter.GetBytes(materialID);

                //Create serialized asset by converting data to a bytearray and give it to the constructor.
                AssetResource resource = new AssetResource(false);
                resource.Serialize(referenceID, MetaDataType.UNKOWN, null, bytes);

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

                //Make sure caller can get the actual material referenceID when serializing its metadata.
                this.pointedID = materialID;
            }
            else
            {
                ComponentNode componentNode = new ComponentNode(PCFResourceType.MATERIAL, referenceID, path);

                //Material nodes can and are most likely to be children of other component nodes.
                objNode.AddChildNode(componentNode);

                SerializedMaterial serializedMaterial = new SerializedMaterial();
                serializedMaterial.DisplayName = this.material.name;
                serializedMaterial.ShaderName  = this.material.shader.name;

                Dictionary <string, SerializedMaterialProperty> materialProperties = new Dictionary <string, SerializedMaterialProperty>();

                // Iterate through children and get the textures of the material.
                Shader shader = this.material.shader;

                int count = ShaderUtil.GetPropertyCount(shader);
                for (int i = 0; i < count; i++)
                {
                    ShaderUtil.ShaderPropertyType propertyType = ShaderUtil.GetPropertyType(shader, i);
                    string propertyName = ShaderUtil.GetPropertyName(shader, i);

                    SerializedMaterialProperty property = null;

                    //Color property.
                    if (propertyType == ShaderUtil.ShaderPropertyType.Float || propertyType == ShaderUtil.ShaderPropertyType.Range)
                    {
                        SerializedMaterialFloatProperty prop = new SerializedMaterialFloatProperty();

                        prop.Val          = this.material.GetFloat(propertyName);
                        prop.PropertyType = (int)MaterialPropertyType.FloatType;

                        property = prop;
                    }
                    //Vector property.
                    if (propertyType == ShaderUtil.ShaderPropertyType.Vector)
                    {
                        SerializedMaterialVectorProperty prop = new SerializedMaterialVectorProperty();

                        Vector4 vector = this.material.GetVector(propertyName);
                        prop.X = vector.x;
                        prop.Y = vector.y;
                        prop.Z = vector.z;
                        prop.W = vector.w;

                        prop.PropertyType = (int)MaterialPropertyType.VectorType;

                        property = prop;
                    }
                    //Float property.
                    if (propertyType == ShaderUtil.ShaderPropertyType.Color)
                    {
                        SerializedMaterialColorProperty prop = new SerializedMaterialColorProperty();

                        Color color = this.material.GetColor(propertyName);

                        prop.R = color.r;
                        prop.G = color.g;
                        prop.B = color.b;
                        prop.A = color.a;

                        prop.PropertyType = (int)MaterialPropertyType.ColorType;

                        property = prop;
                    }

                    //Texture property.
                    if (propertyType == ShaderUtil.ShaderPropertyType.TexEnv)
                    {
                        Texture2D texture = (Texture2D)this.material.GetTexture(propertyName);

                        if (texture != null)
                        {
                            UnitySerializeTexture textureSerializer = new UnitySerializeTexture(texture, this.rootNode);
                            textureSerializer.Serialize(serializedAssets, serializeOptions, componentNode, postSerializeActions);

                            SerializedMaterialTextureProperty prop = new SerializedMaterialTextureProperty();

                            prop.ReferenceID  = textureSerializer.GetReferenceID();
                            prop.PropertyType = (int)MaterialPropertyType.TextureType;

                            property = prop;
                        }
                    }

                    materialProperties.Add(propertyName, property);
                }

                serializedMaterial.MaterialProperties = materialProperties;

                //Create serialized asset by converting data to a bytearray and give it to the constructor.
                AssetResource resource = new AssetResource(false);

                byte[] metaDataBuffer = ProtocolBufferSerializer.SerializedMaterial(serializedMaterial);
                resource.Serialize(this.referenceID, MetaDataType.PROTOBUF, metaDataBuffer, null);

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

                //Nodes store their resource when serializing
                componentNode.SetSerializer(this);

                //Make sure caller can get the actual material referenceID when serializing its metadata.
                this.pointedID = this.referenceID;
            }
                        #endif
        }
Esempio n. 11
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();

            LightprobeSerializeOpts serializeOption = null;

            for (int i = 0; i < serializeOptions.Length; i++)
            {
                object opt = serializeOptions[i];

                if (opt is LightprobeSerializeOpts)
                {
                    serializeOption = opt as LightprobeSerializeOpts;
                    break;
                }
            }

            if (serializeOption == null)
            {
                return;
            }

            ComponentNode componentNode = new ComponentNode(PCFResourceType.LIGHTPROBES, referenceID, null);

            //Material nodes can and are most likely to be children of other component nodes.
            objNode.AddChildNode(componentNode);

            //Manually serialize SH components,.
            //However unity does not currently expose any way to generate the probes at runtime.
            //So we cannot set them directly unless the probes exist. (Fix it unity :D)
            byte[] serializedProbes = SerializeLightProbes(this.lightProbes);

            Dictionary <string, FileInfo> internalBundles = serializeOption.ListInternalBundles();

            JArray bundleReferences = new JArray();

            foreach (KeyValuePair <string, FileInfo> pair in internalBundles)
            {
                UnitySerializeInternalBundle bundleSerializer = new UnitySerializeInternalBundle(pair.Key, pair.Value.FullName, string.Empty, this.rootNode);
                bundleSerializer.Serialize(serializedAssets, serializeOptions, componentNode, postSerializeActions);

                JObject item = new JObject();
                item["platform"]    = pair.Key;
                item["referenceID"] = bundleSerializer.GetReferenceID();

                bundleReferences.Add(item);
            }

            JObject metaData = new JObject();

            metaData["numberOfProbes"]   = this.lightProbes != null ? this.lightProbes.bakedProbes.Length : 0;
            metaData["bundleReferences"] = bundleReferences;

            //Create serialized asset by converting data to a bytearray and give it to the constructor.
            AssetResource resource = new AssetResource(false);

            byte[] metaDataBuffer = System.Text.Encoding.UTF8.GetBytes(metaData.ToString(Formatting.None));
            resource.Serialize(referenceID, MetaDataType.JSON, metaDataBuffer, serializedProbes);

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

            //Nodes store their resource when serializing
            componentNode.SetSerializer(this);
        }