コード例 #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 NinjaData(string id, Hashtable hashAttr, IXMLNode nodeEntries, string strError)
    {
        // set id
        strID = id;

        // get the weight for this group
        string strWeight = HashUtils.GetHashValue <string>(hashAttr, "Weight", "1");

        nWeight = int.Parse(strWeight);

        // get the scoring categories
        string strScoring = HashUtils.GetHashValue <string>(hashAttr, "Scoring", "Med", strError);

        string[] arrayScoring = strScoring.Split(","[0]);
        for (int i = 0; i < arrayScoring.Length; ++i)
        {
            NinjaScoring eScoring = (NinjaScoring)System.Enum.Parse(typeof(NinjaScoring), arrayScoring[i]);
            listScoring.Add(eScoring);
        }

        // go through the list of entries and add them to our list
        List <IXMLNode> listEntries = XMLUtils.GetChildrenList(nodeEntries);

        for (int i = 0; i < listEntries.Count; ++i)
        {
            Hashtable      hashEntryAttr = XMLUtils.GetAttributes(listEntries[i]);
            NinjaDataEntry entry         = new NinjaDataEntry(hashEntryAttr, strError);
            this.listEntries.Add(entry);
        }
    }
コード例 #3
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);
                }
            }
        }
    }