public Dictionary <PCFResourceType, DataBlockBase> Serialize(object[] serializeOptions) { //Holds and indexes all serialized assets/resources. SerializedAssets serializedAssets = new SerializedAssets(this.destinationDirectory); //Allow serialized nodes to define actions to do after the entire tree has been serialized. List <Action <NodeBase> > postSerializeActions = new List <Action <NodeBase> >(); //Populate dataBlocks with stuff. SerializeRecursivly(this.selectedGameObject, serializedAssets, serializeOptions, this.rootNode, postSerializeActions); //Run all post serialize actions. foreach (Action <NodeBase> action in postSerializeActions) { action(this.rootNode); } //Tracking object, used to debug what happens during serialization. ISerializeLogging logger = new NodeCreationDebugger(); //Recursivly create serialized representations of node tree. (Aka NodeResource objects) NodeResource serializedRootNode = this.rootNode.Serialize(serializedAssets, null, logger); //Lets see... logger.PrintResult(); Dictionary <PCFResourceType, DataBlockBase> dataBlocks = serializedAssets.GetDataBlocks(); //Create nodeblock and set it to the datablocks dictionary. DataBlockBase nodeBlock = new NodeBlock(serializedRootNode); dataBlocks.Add(PCFResourceType.NODE, nodeBlock); return(dataBlocks); }
public void AddChildNode(NodeResource node) { //we cant add to it, if it doesn't exist now...can we. if (this.childNodes == null) { this.childNodes = new List <NodeResource>(); } this.childNodes.Add(node); }
void GetLengthRecursivly(NodeResource node, ref int length) { //Should be 68 or we have seriously f****d up. length += node.GetLength(); foreach (NodeResource child in node.GetChildren()) { GetLengthRecursivly(child, ref length); } }
void SerializeNodeTree(byte[] byteArray, ref int offset, NodeResource node) { byte[] nodeBytes = node.GetBytes(); Buffer.BlockCopy(nodeBytes, 0, byteArray, offset, nodeBytes.Length); offset += nodeBytes.Length; foreach (NodeResource child in node.GetChildren()) { SerializeNodeTree(byteArray, ref offset, child); } }
public virtual T RecreateNodeGraph <T>(NodeFactory nodeFactory) where T : UnityNodeBase { if (this.rootNodeResource != null) { NodeResource.SetNodeFactory(nodeFactory); T rootNode = this.rootNodeResource.Recreate <T>(null, this.loadFlags); return(rootNode); } return(default(T)); }
void DeserializeNodeTree(Stream file, NodeResource deserializedParentNode, ref int bytesRead, bool debug, bool assemblyMode) { int childCount = deserializedParentNode.GetNumberOfChildren(); for (int i = 0; i < childCount; i++) { NodeResource node = NodeResource.DeserializeNode(file, ref bytesRead, debug, assemblyMode); deserializedParentNode.AddChildNode(node); DeserializeNodeTree(file, node, ref bytesRead, debug, assemblyMode); } }
public override void SetBytes(Stream file, int chunkLength, long offsetPos, bool assemblyMode) { int bytesToRead = chunkLength - BlockTypeLength; int bytesRead = 0; #if DESERIALIZE_ALL_NODE_NAMES bool readNames = true; #else bool readNames = false; #endif this.rootNodeResource = NodeResource.DeserializeNode(file, ref bytesRead, readNames, assemblyMode); DeserializeNodeTree(file, this.rootNodeResource, ref bytesRead, readNames, assemblyMode); if (bytesToRead != bytesRead) { Debug.LogError("Malformed node tree"); } }
public override NodeResource Serialize(SerializedAssets serializedAssets, NodeResource serializedParent, ISerializeLogging logger) { NodeResource serializedNode = new NodeResource(this.resourceType, this.referenceID, this.name); logger.LogNode(this); if (serializedParent != null) { serializedParent.AddChildNode(serializedNode); } foreach (NodeBase child in this.ChildNodes) { child.Serialize(serializedAssets, serializedNode, logger); } if (serializedParent == null) { return(serializedNode); } return(null); }
public virtual NodeResource Serialize(SerializedAssets serializedAssets, NodeResource serializedParent, ISerializeLogging logger) { return(null); }
public NodeBlock() { this.blockType = BitConverter.GetBytes((int)PCFBlockTypes.NODEBLOCK); this.rootNodeResource = null; }
public NodeBlock(PCFResourceType loadFlags) { this.blockType = BitConverter.GetBytes((int)PCFBlockTypes.NODEBLOCK); this.rootNodeResource = null; this.loadFlags = loadFlags; }