예제 #1
0
        public static T GetDescription <T>(IContext context, string path, IRandom random) where T : class, IDescription
        {
            var          parts   = GetParts(path);
            IDescription current = null;

            for (int i = 0; i < parts.Count; i++)
            {
                current = current == null?context.dataSources.GetChild(parts[i][0]) : current.GetChild(parts[i][0]);

                if (SelectPathUtil.IsSimple(parts[i][1]))
                {
                    current = current.GetChild(parts[i][1]);
                }
                else
                {
                    var allKeys = new List <string>();
                    allKeys.AddRange(current.GetNode().GetSortedKeys());
                    var affectedKeys = SelectPathUtil.GetAffectedKeys(parts[i][1], allKeys);
                    if (affectedKeys.Count == 0)
                    {
                        return(null);
                    }

                    var selectedKey = affectedKeys[random.Range(0, affectedKeys.Count)];
                    current = current.GetChild(selectedKey);
                }
            }

            return((T)current);
        }