Esempio n. 1
0
            public void Parse(string key, OnPopulate populate)
            {
                XmlDbData careerFile = XmlDbData.ReadData(key);

                if ((careerFile != null) && (careerFile.Tables != null) && (careerFile.Tables.ContainsKey("CareerData")))
                {
                    XmlDbTable table = careerFile.Tables["CareerData"];

                    foreach (XmlDbRow row in table.Rows)
                    {
                        string guid = row.GetString("Career");

                        string branch = row.GetString("Branch");
                        if (string.IsNullOrEmpty(branch))
                        {
                            branch = "Base";
                        }

                        int level = row.GetInt("Level");
                        if (level == 1)
                        {
                            continue;
                        }

                        OccupationNames careerGuid = OccupationNames.Undefined;
                        ParserFunctions.TryParseEnum <OccupationNames>(guid, out careerGuid, OccupationNames.Undefined);

                        if (careerGuid == OccupationNames.Undefined)
                        {
                            careerGuid = unchecked ((OccupationNames)ResourceUtils.HashString64(guid));
                        }

                        Dictionary <int, Dictionary <string, TData> > levels;
                        if (!mLevels.TryGetValue(careerGuid, out levels))
                        {
                            levels = new Dictionary <int, Dictionary <string, TData> >();
                            mLevels.Add(careerGuid, levels);
                        }

                        Dictionary <string, TData> branches;
                        if (!levels.TryGetValue(level, out branches))
                        {
                            branches = new Dictionary <string, TData>();
                            levels.Add(level, branches);
                        }

                        if (branches.ContainsKey(branch))
                        {
                            continue;
                        }

                        branches.Add(branch, populate(row));
                    }
                }
            }
Esempio n. 2
0
    public void Populate <T>(IEnumerable <T> data, Action <GameObject, T> populater)
    {
        var index = 0;

        foreach (var datum in data)
        {
            GameObject gameObject;
            if (index >= transform.childCount)
            {
                gameObject = Instantiate(prefab);
                gameObject.transform.SetParent(transform, worldPositionStays: false);
            }
            else
            {
                var child = transform.GetChild(index);
                gameObject = child.gameObject;
            }

            populater(gameObject, datum);

            index += 1;
        }

        int dataSize = index;

        // destroy extra children
        List <GameObject> toDestroy = new List <GameObject>();

        for (; index < transform.childCount; index += 1)
        {
            toDestroy.Add(transform.GetChild(index).gameObject);
        }
        foreach (var obj in toDestroy)
        {
            DestroyImmediate(obj);
        }

        OnPopulate?.Invoke(dataSize);
    }