Ejemplo n.º 1
0
        public object Visit(QueryAstBase node, object currentData)
        {
            if (currentData is IEnumerable enumerable)
            {
                return(enumerable.Cast <object>().FirstOrDefault());
            }

            if (currentData is GameObject gameObject)
            {
                return(gameObject.transform
                       .Cast <Transform>()
                       .Select(t => t.gameObject)
                       .ToArray());
            }

            if (currentData is Component component)
            {
                return(currentData.GetType()
                       .GetTypeInfo()
                       .GetMembers(BindingFlags.Instance | BindingFlags.GetField | BindingFlags.GetProperty)
                       .ToArray());
            }

            if (currentData is Scene scene)
            {
                return(scene.GetRootGameObjects());
            }

            return(null);
        }
Ejemplo n.º 2
0
        public object Visit(QueryAstBase node, object currentData)
        {
            if (node.Value.Equals("Scenes"))
            {
                return(Enumerable.Range(0, SceneManager.sceneCount).Select(i => SceneManager.GetSceneAt(i)));
            }

            if (node.Value.Equals("Components"))
            {
                return(Object.FindObjectsOfType <Component>());
            }

            if (node.Value.Equals("RootGameObjects"))
            {
                return(Enumerable
                       .Range(0, SceneManager.sceneCount)
                       .Select(i => SceneManager.GetSceneAt(i))
                       .SelectMany(s => s.GetRootGameObjects()));
            }

            if (node.Value.Equals("GameObjects"))
            {
                return(Object.FindObjectsOfType <Transform>()
                       .Select(o => o.gameObject));
            }

            return(null);
        }
Ejemplo n.º 3
0
        public object Visit(QueryAstBase node, object currentData)
        {
            if (currentData is IEnumerable enumerable)
            {
                return(enumerable.Cast <object>().Where(i => {
                    if (i is GameObject iGo)
                    {
                        return iGo.name.Equals(node.Value);
                    }

                    if (i is Scene iScene)
                    {
                        return iScene.name.Equals(node.Value);
                    }

                    if (i is TypeMemberInstance iMI)
                    {
                        return iMI.Name.Equals(node.Value);
                    }

                    return false;
                }));
            }

            if (currentData is Scene Scene)
            {
                return(Scene.GetRootGameObjects()
                       .Where(g => g.name.Equals(node))
                       .ToArray());
            }

            if (currentData is GameObject gameObject)
            {
                return(gameObject.transform
                       .Cast <Transform>()
                       .Select(t => t.gameObject)
                       .Where(g => g.name == node.Value.ToString())
                       .ToArray());
            }

            if (currentData is Component component)
            {
                return(currentData.GetType()
                       .GetTypeInfo()
                       .GetMembers(BindingFlags.Instance | BindingFlags.GetField | BindingFlags.GetProperty)
                       .Where(s => s.Name == node.Value.ToString())
                       .Select(s => new TypeMemberInstance(s, currentData))
                       .ToArray());
            }

            return(null);
        }
Ejemplo n.º 4
0
        public object Visit(QueryAstBase node, object currentData)
        {
            var type = Type.GetType(node.Value.ToString(), true, true);

            if (currentData is IEnumerable enumerable)
            {
                return(enumerable.Cast <object>().Where(comp => type == comp.GetType()));
            }

            if (currentData is GameObject go)
            {
                return(go.GetComponents(type));
            }

            return(null);
        }
Ejemplo n.º 5
0
        public object Visit(QueryAstBase node, object currentData)
        {
            if (!(currentData is IEnumerable dataEnumerable))
            {
                return(null);
            }

            var casted = dataEnumerable.OfType <object>();
            var index  = (int)node.Value;

            if (index < 0)
            {
                var reversed = casted.Reverse();
                return(reversed.ElementAt(index));
            }
            return(casted.ElementAt(index));
        }