static QuestTreeDirections ExtractQuestDirections(OneWayTreeNode node)
    {
        QuestTreeDirections dirs = new QuestTreeDirections();

        OneWayTreeNode[] nodes = node.rAsList();
        dirs.nodes = new IntSerializableArr[nodes.Length];
        for (int i = 0; i < dirs.nodes.Length; i++)
        {
            dirs.nodes[i]            = new IntSerializableArr();
            dirs.nodes[i].directions = new int[nodes[i].children.Count];
            for (int j = 0; j < dirs.nodes[i].directions.Length; j++)
            {
                dirs.nodes[i].directions[j] = i + j + 1;// untested
            }
        }
        return(dirs);
    }
 public static OneWayTreeNode ConstructQuestTree(object[] data, QuestTreeDirections directions)
 {
     if (data.Length == 0 || directions.nodes.Length != data.Length)
     {
         Debug.Log("err: " + (data.Length == 0) + " " + (directions.nodes.Length != data.Length));
         return(null);
     }
     OneWayTreeNode[] nodes = new OneWayTreeNode[data.Length];
     for (int i = 0; i < data.Length; i++)
     {
         nodes[i]      = new OneWayTreeNode();
         nodes[i].data = data[i] as QuestInfo;
         nodes[i].id   = i;
     }
     // put down directions and mark those who have any incoming.
     // to find root later(0 incoming).
     bool[] hasInc = new bool[data.Length];
     for (int i = 0; i < data.Length; i++)
     {
         for (int j = 0; j < directions.nodes[i].directions.Length; j++)
         {
             if (nodes[i] == nodes[directions.nodes[i].directions[j]])
             {
                 continue;
             }
             nodes[i].Add(nodes[directions.nodes[i].directions[j]]);
             hasInc[directions.nodes[i].directions[j]] = true;
         }
     }
     // paths.. just map who the child is. or connect them in linear fashion
     //
     // find root - node that has 0 incoming connections
     for (int i = 0; i < hasInc.Length; i++)
     {
         if (!hasInc[i])
         {
             return(nodes[i]);
         }
     }
     return(null);// err
 }