Exemplo n.º 1
0
        public IList <string> GetFieldsAndPropertiesUnderPath(GameObject go, string propertPath)
        {
            propertPath = propertPath.Trim();
            if (!PropertyPathIsValid(propertPath))
            {
                throw new ArgumentException("Incorrect property path: " + propertPath);
            }

            var idx = propertPath.LastIndexOf('.');

            if (idx < 0)
            {
                var components = GetFieldsAndPropertiesFromGameObject(go, 2, null);
                return(components);
            }

            var  propertyToSearch = propertPath;
            Type type;

            if (MemberResolver.TryGetMemberType(go, propertyToSearch, out type))
            {
                idx = propertPath.Length - 1;
            }
            else
            {
                propertyToSearch = propertPath.Substring(0, idx);
                if (!MemberResolver.TryGetMemberType(go, propertyToSearch, out type))
                {
                    var components = GetFieldsAndPropertiesFromGameObject(go, 2, null);
                    return(components.Where(s => s.StartsWith(propertPath.Substring(idx + 1))).ToArray());
                }
            }

            var resultList = new List <string>();
            var path       = "";

            if (propertyToSearch.EndsWith("."))
            {
                propertyToSearch = propertyToSearch.Substring(0, propertyToSearch.Length - 1);
            }
            foreach (var c in propertyToSearch)
            {
                if (c == '.')
                {
                    resultList.Add(path);
                }
                path += c;
            }
            resultList.Add(path);
            foreach (var prop in type.GetProperties().Where(info => info.GetIndexParameters().Length == 0))
            {
                if (prop.Name.StartsWith(propertPath.Substring(idx + 1)))
                {
                    resultList.Add(propertyToSearch + "." + prop.Name);
                }
            }
            foreach (var prop in type.GetFields())
            {
                if (prop.Name.StartsWith(propertPath.Substring(idx + 1)))
                {
                    resultList.Add(propertyToSearch + "." + prop.Name);
                }
            }
            return(resultList.ToArray());
        }