public NinjaDataEntry(Hashtable hashAttr, string strError) { // pattern this entry spawns string strPattern = HashUtils.GetHashValue <string>(hashAttr, "Pattern", "Separate", strError); ePattern = (NinjaPatterns)System.Enum.Parse(typeof(NinjaPatterns), strPattern); // number of objects in this entry nTriggers = int.Parse(HashUtils.GetHashValue <string>(hashAttr, "Triggers", "0")); // # of bombs in the entry nBombs = int.Parse(HashUtils.GetHashValue <string>(hashAttr, "Bombs", "0")); // # of bombs in the entry nPowUp = int.Parse(HashUtils.GetHashValue <string>(hashAttr, "PowerUp", "0")); // time this entry should be spawned fTime = float.Parse(HashUtils.GetHashValue <string>(hashAttr, "Time", "0", strError)); }
/// <summary> /// Spawns the group. /// </summary> /// <param name="entry">Entry.</param> private void SpawnGroup(NinjaDataEntry entry) { // create the proper list of objects to spawn int numOfTriggers = entry.GetTriggers(); int numOfBombs = entry.GetBombs(); int numOfPowUps = entry.GetPowUp(); List <string> listObjects = new List <string>(); for (int i = 0; i < numOfTriggers; ++i) { // NOTE: if want to add variation over time, use GetRandomTrigger(n to choose from) string randomTrigger = DataLoaderNinjaTriggersAndBombs.GetRandomTrigger(DataLoaderNinjaTriggersAndBombs.numTriggers); listObjects.Add(randomTrigger); } for (int i = 0; i < numOfBombs; ++i) { // NOTE: if want to add variation over time, use GetRandomBomb(n to choose from) string randomBomb = DataLoaderNinjaTriggersAndBombs.GetRandomBomb(DataLoaderNinjaTriggersAndBombs.numBombs); listObjects.Add(randomBomb); } for (int i = 0; i < numOfPowUps; ++i) { // NOTE: if want to add variation over time, use GetRandomBomb(n to choose from) string randomPowUps = DataLoaderNinjaTriggersAndBombs.GetRandomPowUp(DataLoaderNinjaTriggersAndBombs.numPowUps); listObjects.Add(randomPowUps); } // shuffle the list so everything is nice and mixed up listObjects.Shuffle(); // create the proper object based off the entry's pattern NinjaPatterns patternType = entry.GetPattern(); switch (patternType) { case NinjaPatterns.Separate: new SpawnGroupSeparate(listObjects); break; case NinjaPatterns.Clustered: new SpawnGroupCluster(listObjects); break; case NinjaPatterns.Meet: new SpawnGroupMeet(listObjects); break; case NinjaPatterns.Cross: new SpawnGroupCross(listObjects); break; case NinjaPatterns.Split: new SpawnGroupSplit(listObjects); break; case NinjaPatterns.Swarms: // Random is ambiguous need to specify unity engine int rand = UnityEngine.Random.Range(2, 5); StartCoroutine(WaitASec(rand, listObjects)); break; default: Debug.LogError("Unhandled group type: " + patternType); break; } }