public override void SerializePCF(GameObject go, string outputDirectory, Action <bool, string> OnComplete) { Debug.Log("serialize generic object to directory: " + outputDirectory); DirectoryInfo outDir = new DirectoryInfo(outputDirectory); if (!outDir.Exists) { outDir.Create(); } //These export objects are custom to our project, override if specific behaviour needed. object[] opts = new object[4]; opts[0] = new TextureSerializeOpts(TexturePackageOptions.ASTCPackage); opts[1] = new AvatarSerializeOpts("Transform"); opts[2] = new AudioSerializeOpts(); opts[3] = new LightprobeSerializeOpts(Path.Combine(Application.dataPath, "LightingData")); string outputFile = Path.Combine(outputDirectory, go.name + ".pcf"); ExportUtils.AddVersionInfo(go); SerializeContent(go, opts, outputDirectory, outputFile, PCFfileType.Unknown); ExportUtils.AddChecksum(outputFile); OnComplete(true, "Success exporting content: " + go.name); }
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); }