internal List <GameEvent> GenerateMany(string type, int amount, int level) { List <GameEvent> list = new List <GameEvent>(); PREventType prEventType = FromStringToEventType(type); dict.TryGetValue(prEventType, out GameEvent[][] bluePrints); if (bluePrints == null) { throw new Exception("Can't find the specified type"); } if (GetRange(bluePrints, level) > 0) { for (int i = 0; i < amount; i++) { list.Add(GenerateOneRandomely(prEventType, level)); } } return(list); //int range = GetRange(level); //int r = UnityEngine.Random.Range(0, range); //for(int i=0; i<r; i++) //{ // list.AddLast(GenerateOne(level)); //} //return list; }
private string FromEventTypeToString(PREventType type) { switch (type) { case PREventType.Goods: return("Goods"); case PREventType.Obstacles: return("Obstacles"); } return(null); }
/// <summary> /// This method will get the level and generate one blueprint. /// </summary> /// <param name="level"></param> /// <returns></returns> public GameEvent GenerateOne(PREventType type, int level, int index) { dict.TryGetValue(type, out GameEvent[][] bluePrints); if (bluePrints == null) { throw new Exception("Can't find the specified type"); } GameEvent gameEvent = bluePrints[level][index]; return(gameEvent); }
/// <summary> /// This method will get the level and generate one object randomely chosen from /// the bluprint level options. /// </summary> /// <param name="level"></param> /// <returns></returns> private GameEvent GenerateOneRandomely(PREventType type, int level) { dict.TryGetValue(type, out GameEvent[][] bluePrints); if (bluePrints == null) { throw new Exception("Can't find the specified type"); } int random = UnityEngine.Random.Range(0, GetRange(bluePrints, level)); GameEvent gameEvent = bluePrints[level][random]; return(gameEvent); }
private void LoadResourcesToBlueprints(PREventType type, int level) { //Get dict.TryGetValue(type, out GameEvent[][] bluePrints); if (bluePrints == null) { throw new Exception("Can't find the specified blueprint"); } string resourcesPath = ConfigHolder.GetInstance().RESOURCES_PATH + level + "/" + FromEventTypeToString(type); //string resourcesPath = "TestConstructs/Level_" + level + "/"+type; Dictionary <string, string> resourcesPrefabs = Utils.LoadResourceTextfilesWithName(resourcesPath); int length = resourcesPrefabs.Count; bluePrints[level] = new GameEvent[length]; if (length <= 0) { return; } Dictionary <string, string> .Enumerator iter = resourcesPrefabs.GetEnumerator(); int j = 0; while (iter.MoveNext()) { string fname = iter.Current.Key; string data = iter.Current.Value; m_ObjectToCostDict.TryGetValue(fname, out int cost); bluePrints[level][j] = new GameEvent(fname, data, level, cost, FromEventTypeToString(type)); //bluePrints[level][j].mJsonData = data; bluePrints[level][j].mCost = cost; //search name in map and edit cost j++; } }