public List<MethodInfo> GetBooleanMethodsFrom(GameObject gameObject)
 {
     List<MethodInfo> booleanMethods = new List<MethodInfo> ();
     //GameObject boolean methods
     foreach(MethodInfo mo in gameObject.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public)) {
         if(mo.GetParameters().Length==0
            && mo.ReturnType == typeof(Boolean)) {
             booleanMethods.Add(mo);
         }
     }
     //Component of gameObject boolean methods
     Component[] comps = gameObject.GetComponents<Component>();
     foreach (Component comp in comps) {
         if(comp==null)
             continue;
         MethodInfo[] methods = comp.GetType ().GetMethods (BindingFlags.Instance | BindingFlags.Public);
         foreach(MethodInfo mi in methods) {
             if(mi.GetParameters().Length==0
                && mi.ReturnType == typeof(Boolean))
                 booleanMethods.Add (mi);
         }
     }
     return booleanMethods;
 }
Example #2
0
 private object GetGamePropertyValue(GameObject game)
 {
     if (game == null) return null;
     Dictionary<string, object> objectInfo = new Dictionary<string, object>();
     objectInfo.Add("type", game.GetType().FullName);
     objectInfo.Add("id", GetID(game));
     objectInfo.Add("tag", game.tag);
     objectInfo.Add("name", game.name);
     objectInfo.Add("layer", game.layer);
     objectInfo.Add("isStatic", game.isStatic);
     objectInfo.Add("hideFlags", game.hideFlags.ToString());
     return objectInfo;
 }
		private void PrintUnityGameObject(GameObject o, IndentedTextWriter writer, Func<GameObject, bool> gameObjectFilter, Func<Component, bool> componentFilter) {
			if (o == null) {
				writer.WriteLine("(null)");
				return;
			}
			
			writer.WriteLine("{0} : {1}", o.GetType(), o.name);
			if (_visited.ContainsKey(o)) {
				writer.Write(" (already dumped)");
				return;
			}
			writer.Indent++;
			writer.WriteLine("Components:");
			writer.Indent++;
			
			_visited[o] = true;
			foreach (var component in o.GetComponents(typeof (Component))) {
				writer.WriteLine("[Component] {0}", component.GetType().Name);
				if (!componentFilter(component)) continue;
				writer.Indent++;
				PrintObjectMembers(writer, component);
				writer.Indent--;
			}
			writer.Indent--;
			writer.WriteLine("Children:");

			var numChildren = o.transform.childCount;
			for (int i = 0; i < numChildren; i++) {
				var child = o.transform.GetChild(i);
				writer.Indent++;
				writer.Write("{0}. [Child] ", i);
				if (gameObjectFilter(child.gameObject)) {
					PrintUnityGameObject(child.gameObject, writer, gameObjectFilter, componentFilter);	
				}
				
				writer.Indent--;
			}
			writer.Indent--;
		}
		private static Type GetPropertyTypeFromString(GameObject gameObj, string propertyPath)
		{
			if (propertyPath == "")
				return gameObj.GetType();

			var propsQueue = new Queue<string>(propertyPath.Split('.').Where(s => !string.IsNullOrEmpty(s)));

			if (propsQueue == null) throw new ArgumentException("Incorrent property path");

			Type result;
			if (char.IsLower(propsQueue.Peek()[0]))
			{
				result = gameObj.GetType();
			}
			else
			{
				var component = gameObj.GetComponent(propsQueue.Dequeue());

				if (component == null) throw new ArgumentException("Incorrent property path");

				result = component.GetType();
			}
			while (propsQueue.Count != 0)
			{
				var nameToFind = propsQueue.Dequeue();

				var property = result.GetProperty(nameToFind);
				if (property != null)
				{
					result = property.PropertyType;
				}
				else
				{
					var field = result.GetField(nameToFind);
					if (field == null) throw new ArgumentException("Incorrent property path");
					result = field.FieldType;
				}
			}
			return result;
		}
Example #5
0
			public void PrintUnityGameObject(GameObject o, int recursionDepth = 0) {
				if (o == null) {
					_writer.WriteLine("(null)");
					return;
				}
				_writer.Write("{0} : {1}", o.GetType(), o.name);
				if (_visited.ContainsKey(o)) {
					_writer.WriteLine(" (already dumped)");
					return;
				}
				if (recursionDepth >= _parent.MaxRecursionDepth) {
					_writer.WriteLine(" (recursion depth exceeded)");
					return;
				}
				_writer.WriteLine();
				_writer.Indent++;
				_writer.WriteLine($"Parent: {o.transform.parent?.name}");
				_writer.WriteLine("Components:");
				_writer.Indent++;

				_visited[o] = true;
				foreach (var component in o.Components(typeof (Component))) {
					_writer.WriteLine("[Component] {0}", component.GetType().Name);
					if (!_parent.ComponentFilter(component)) continue;
					_writer.Indent++;
					PrintObjectMembers(component);
					_writer.Indent--;
				}
				_writer.Indent--;
				_writer.WriteLine("Children:");

				var numChildren = o.transform.childCount;
				for (int i = 0; i < numChildren; i++) {
					var child = o.transform.GetChild(i);
					_writer.Write("{0}.\t [Child] ", i);
					if (_parent.GameObjectFilter(child.gameObject)) {
						PrintUnityGameObject(child.gameObject, recursionDepth + 1);
					}
				}
				_writer.Indent--;
			}