コード例 #1
0
 public UnitNode(int JCATS_ID, string NAME, UnitNode superUnit)
 {
     this.JCATS_ID  = JCATS_ID;
     this.NAME      = NAME;
     this.SuperUnit = superUnit;
     Subunits       = new List <UnitNode>();
     Systems        = new List <SystemNode>();
 }
コード例 #2
0
        public static Dictionary <int, UnitNode> BuildTreeFromXML(string filename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            Dictionary <int, UnitNode> topUnits = new Dictionary <int, UnitNode>();
            Dictionary <int, UnitNode> allUnits = new Dictionary <int, UnitNode>();

            foreach (XmlNode node in doc.DocumentElement.ChildNodes)
            {
                if (node.Name == "UNIT")
                {
                    int    JCATS_ID = Convert.ToInt32(node["JCATS_ID"].InnerText);
                    string NAME     = node["NAME"].InnerText;

                    if (node["JCATS_ToeSuperID"] != null)
                    {
                        int superUnit_JCATS_ID = Convert.ToInt32(node["JCATS_ToeSuperID"].InnerText);

                        if (!allUnits.ContainsKey(superUnit_JCATS_ID))
                        {
                            continue;
                        }
                        UnitNode superUnit = allUnits[superUnit_JCATS_ID];
                        UnitNode newUnit   = new UnitNode(JCATS_ID, NAME, superUnit);
                        superUnit.AddSubunit(newUnit);
                        allUnits.Add(JCATS_ID, newUnit);
                    }
                    else
                    {
                        UnitNode unit = new UnitNode(JCATS_ID, NAME, null);
                        topUnits.Add(JCATS_ID, unit);
                        allUnits.Add(JCATS_ID, unit);
                    }
                }
                else if (node.Name == "SYSTEM")
                {
                    int    entityID             = Convert.ToInt32(node["JCATS_ID"].InnerText);
                    string NAME                 = node["NAME"].InnerText;
                    int    superUnit_JCATS_ID   = Convert.ToInt32(node["JCATS_ToeSuperID"].InnerText);
                    string JCATS_SystemCharName = node["JCATS_SystemCharName"].InnerText;

                    if (!allUnits.ContainsKey(superUnit_JCATS_ID))
                    {
                        continue;
                    }

                    SystemNode system = new SystemNode(entityID, NAME, JCATS_SystemCharName, allUnits[superUnit_JCATS_ID]);
                    allUnits[superUnit_JCATS_ID].AddSystem(system);
                }
            }

            return(topUnits);
        }
コード例 #3
0
        // Prints tree of units and systems.
        private static void printTree(UnitNode unit, string indent)
        {
            Debug.Log(indent + unit.NAME);

            foreach (var s in unit.Systems)
            {
                Debug.Log("   " + indent + s.NAME);
            }

            if (unit.Subunits.Count < 0)
            {
                return;
            }

            foreach (var u in unit.Subunits)
            {
                printTree(u, "   " + indent);
            }
        }
コード例 #4
0
 public void AddSubunit(UnitNode subunit)
 {
     Subunits.Add(subunit);
 }