SerializableTree< T > Class Template Reference

This is the Class version of SerializableTree that is recommended for use in Unity. It will automatically perform serialization callbacks for use in Unity's editor, by implementing the ISerializationCallbackReceiver interface. Note: you must define a class that derives from this one, using a specific T, AND mark it with the [System.Serializable] attribute in order for the class to serialize properly. (Unity does not support attributes on classes using generic types.) Also note: the type T, that is used, must be serializable.

Detailed Description

Template Parameters
TThis is the data type that will be stored in the tree.

Public Member Functions

void OnAfterDeserialize ()
 This function is required by the ISerializationCallbackReceiver Interface. Called automatically via the interface, it will deserialize the stored data into the runtime structure.
 
void OnBeforeSerialize ()
 This function is required by the ISerializationCallbackReceiver Interface. Called automatically via the interface, it will serialize the runtime data for storage.
 
- Public Member Functions inherited from SerializableTreeBase< T >
 SerializableTreeBase ()
 Constructor. Creates a new instance with the root Node set to null.
 
bool AddChild (Node parent, T data)
 called by both the UI and runtime users of the tree. This function will instantiate a new node, and add the provided data to it.
The new node will be added as a child of the provided parent node, making it part of the run-time tree. If null is provided for the parent, and a root node does not already exist, it will be stored as the root node. If a root node exists, specifying null for the parent will fail, and return false.
 
bool AddChild (Node parent, T data, out Node newNode)
 called by both the UI and runtime users of the tree. This function will instantiate a new node, and add the provided data to it.
The new node will be added as a child of the provided parent node, making it part of the run-time tree. If null is provided for the parent, and a root node does not already exist, it will be stored as the root node. If a root node exists, specifying null for the parent will fail, and return false.
 
bool AddChildren (Node parent, T[] data)
 Convenience function used to store an array of data as new nodes. The new nodes will be added as children of the provided parent node.
 
bool CopyNode (Node sourceNode, Node destinationParent)
 recursive function used to copy the data contained in the provided sourceNode, and its descendants, as new Nodes that are children of the provided destinationParent.
 
virtual T DefaultNodeData ()
 This virtual function should be overridden by descendants, to provide a default value for data objects of type T.
 
void Deserialize ()
 this function is used to read the two serialized lists; serializedNodes and dataList, and generate a runtime tree of nodes, based on the data therein.
 
virtual IEnumerator< T > GetEnumerator ()
 default generic enumerator
 
bool RemoveNode (Node nodeToRemove)
 Remove this node from tree, by removing it from it's parent's children list. Does not destroy the Node, nor the Data it references.
 
void ReSerialize ()
 This function will take the runtime tree nodes, and their data, and store them into the two serialized lists; serializedNodes and dataList. These two lists, being serializable, can then be stored and eventually DEserialzied, back into the runtime tree.
 
override string ToString ()
 general ToString override- useful for debugging
 
int TotalLeafCount ()
 Counts the total number of leaves (childless-nodes) it the entire tree.
 
int TotalNodeCount ()
 Counts the total number of nodes it the entire tree.
 

Additional Inherited Members

- Public Attributes inherited from SerializableTreeBase< T >
List< T > dataList
 This list is serialized and stores the data of each node, an object of type T.
 
Node root
 the root of the runtime tree. not serialized.
 
List< SerializableTreeNodeserializedNodes
 this List is serialized and stores the relationships between nodes, which defines the shape of the tree
 
+ Inheritance diagram for SerializableTree< T >:
+ Collaboration diagram for SerializableTree< T >: