コード例 #1
0
    //---------------------------------------------------
    // GetGroupToSpawn()
    // Will return the data for a group to spawn given
    // a mode and a scoring key.
    //---------------------------------------------------
    public static NinjaData GetGroupToSpawn(NinjaModes eMode, NinjaScoring eScoring)
    {
        if (hashData == null)
        {
            SetupData();
        }

        NinjaData data = null;

        // get the mode data
        if (hashData.Contains(eMode))
        {
            Hashtable hashMode = (Hashtable)hashData[eMode];

            // get the list of entries for the scoring key
            if (hashMode.Contains(eScoring))
            {
                List <NinjaData> listData = (List <NinjaData>)hashMode[eScoring];
                data = GetRandomData(listData);
            }
        }

        if (data == null)
        {
            Debug.LogError("Something going wrong with picking a group for the ninja game to spawn");
        }

        return(data);
    }
コード例 #2
0
    public static void SetupData()
    {
        hashData = new Hashtable();

        //Load all data xml files
        UnityEngine.Object[] files = Resources.LoadAll("Ninja/Modes", typeof(TextAsset));
        foreach (TextAsset file in files)
        {
            string xmlString = file.text;

            // error message
            string strErrorFile = "Error in file " + file.name;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            // we store the data per mode of the ninja game.  the name of the file is the mode.
            NinjaModes eMode = (NinjaModes)System.Enum.Parse(typeof(NinjaModes), file.name);
            hashData[eMode] = new Hashtable();
            Hashtable hashMode = (Hashtable)hashData[eMode];

            //Go through all child node of xmlElement (the parent of the file)
            for (int i = 0; i < xmlElement.Children.Count; i++)
            {
                IXMLNode childNode = xmlElement.Children[i];

                // Get id
                Hashtable hashAttr = XMLUtils.GetAttributes(childNode);
                string    id       = (string)hashAttr["ID"];
                string    strError = strErrorFile + "(" + id + "): ";

                NinjaData data = new NinjaData(id, hashAttr, childNode, strError);

                // we want to stuff the data in each of its scoring categories
                List <NinjaScoring> listScoring = data.GetScoringCategories();
                for (int j = 0; j < listScoring.Count; ++j)
                {
                    NinjaScoring eScoring = listScoring[j];

                    // if the mode doesn't contain this scoring key yet, add it
                    if (!hashMode.ContainsKey(eScoring))
                    {
                        hashMode[eScoring] = new List <NinjaData>();
                    }

                    // add the data to the list of data for this mode/scoring key
                    List <NinjaData> listData = (List <NinjaData>)hashMode[eScoring];
                    listData.Add(data);
                }
            }
        }
    }