<commit_before>﻿using System;
using System.Collections;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace Nuterra
{
	public static class UnityGraph
	{
		public static void LogGameObject(GameObject inst)
		{
			if (System.Object.ReferenceEquals(inst, null))
			{
				return;
			}
			LogGameObject(inst, string.Empty);
		}

		public static void LogGameObject(GameObject inst, string prefix)
		{
			if (System.Object.ReferenceEquals(inst, null))
			{
				return;
			}
			Console.WriteLine($"{prefix}GameObject name: ({inst.name}) pos: {inst.transform.localPosition}");
			prefix += "\t";
			Console.WriteLine($"{prefix}activeSelf: {inst.activeSelf} activeInHierarchy: {inst.activeInHierarchy}");
			Console.WriteLine($"{prefix}layer: ({inst.layer}) tag: ({inst.tag})");
			Console.WriteLine($"{prefix}Components:");
			Component[] components = inst.GetComponents<Component>();
			for (int i = 0; i < components.Length; i++)
			{
				Component component = components[i];
				LogComponent(component, prefix);
			}
			Console.WriteLine($"{prefix}GameObjects:");
			for (int j = 0; j < inst.transform.childCount; j++)
			{
				LogGameObject(inst.transform.GetChild(j).gameObject, prefix);
			}
		}

		public static void LogComponent(Component inst, string prefix)
		{
			if (inst == null)
			{
				return;
			}
			Console.Write($"{prefix}{inst.GetType().FullName} ");
			if (inst is TankBlock)
			{
				LogComponent_TankBlock((TankBlock)inst, prefix);
				return;
			}
			if (inst is Visible)
			{
				LogComponent_Visible((Visible)inst);
				return;
			}
			if (inst is MeshFilter)
			{
				LogComponent_MeshFilter((MeshFilter)inst);
				return;
			}
			if (inst is BoxCollider)
			{
				LogComponent_BoxCollider((BoxCollider)inst);
				return;
			}
			Console.WriteLine();
		}

		public static void LogComponent_TankBlock(TankBlock tankBlock, string prefix)
		{
			Console.WriteLine();
			Console.WriteLine($"{prefix}\tattachPoints:");
			foreach (Vector3 vec in tankBlock.attachPoints)
			{
				Console.WriteLine($"{prefix}\t\t- {vec}");
			}
			Console.WriteLine($"{prefix}\tfilledCells:");
			foreach (Vector3 vec in tankBlock.filledCells)
			{
				Console.WriteLine($"{prefix}\t\t- {vec}");
			}
			Console.WriteLine($"{prefix}\tpartialCells:");
			foreach (Vector3 vec in tankBlock.partialCells)
			{
				Console.WriteLine($"{prefix}\t\t- {vec}");
			}
			Console.WriteLine($"{prefix}\tapGroups:");
			foreach (TankBlock.APGroup group in tankBlock.apGroups)
			{
				Console.WriteLine($"{prefix}\t\t- Count: {group.Count}");
				foreach (int i in group.Enumerate())
				{
					Console.WriteLine($"{prefix}\t\t\t{i}");
				}
			}
		}

		public static void LogComponent_Visible(Visible visible)
		{
			Console.WriteLine(visible.Flags);
		}

		public static void LogComponent_MeshFilter(MeshFilter mesh)
		{
			Console.WriteLine(mesh.mesh.name);
		}

		public static void LogComponent_BoxCollider(BoxCollider box)
		{
			Console.WriteLine($"{box.center} {box.size}");
		}

		public static void LogPrivates(object obj, string prefix)
		{
			return;
			foreach (FieldInfo prop in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
			{
				object value = prop.GetValue(obj);
				if (value != null)
				{
					if (value.GetType().IsArray || typeof(ICollection).IsAssignableFrom(value.GetType()))
					{
						value = $"{((IEnumerable)value).Cast<object>().Count()} ({value.GetType()})";
					}
				}
				Console.WriteLine($"{prefix}{prop.Name} = {value}");
			}
			foreach (PropertyInfo prop in obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
			{
				object value;
				try
				{
					value = prop.GetValue(obj, null);
				}
				catch (Exception ex)
				{
					value = ex;
				}
				Console.WriteLine($"{prefix}{prop.Name} = {value}");
			}
		}
	}
}<commit_msg>Support for TerrainObject in UnityGraph<commit_after>﻿using System;
using System.Collections;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace Nuterra
{
	public static class UnityGraph
	{
		public static void LogGameObject(GameObject inst)
		{
			if (System.Object.ReferenceEquals(inst, null))
			{
				return;
			}
			LogGameObject(inst, string.Empty);
		}

		public static void LogGameObject(GameObject inst, string prefix)
		{
			if (System.Object.ReferenceEquals(inst, null))
			{
				return;
			}
			Console.WriteLine($"{prefix}GameObject name: ({inst.name}) pos: {inst.transform.localPosition}");
			prefix += "\t";
			Console.WriteLine($"{prefix}activeSelf: {inst.activeSelf} activeInHierarchy: {inst.activeInHierarchy}");
			Console.WriteLine($"{prefix}layer: ({inst.layer}) tag: ({inst.tag})");
			Console.WriteLine($"{prefix}Components:");
			Component[] components = inst.GetComponents<Component>();
			for (int i = 0; i < components.Length; i++)
			{
				Component component = components[i];
				LogComponent(component, prefix);
			}
			Console.WriteLine($"{prefix}GameObjects:");
			for (int j = 0; j < inst.transform.childCount; j++)
			{
				LogGameObject(inst.transform.GetChild(j).gameObject, prefix);
			}
		}

		public static void LogComponent(Component inst, string prefix)
		{
			if (inst == null)
			{
				return;
			}
			Console.Write($"{prefix}{inst.GetType().FullName} ");
			if (inst is TankBlock)
			{
				LogComponent_TankBlock((TankBlock)inst, prefix);
				return;
			}
			if (inst is Visible)
			{
				LogComponent_Visible((Visible)inst);
				return;
			}
			if (inst is MeshFilter)
			{
				LogComponent_MeshFilter((MeshFilter)inst);
				return;
			}
			if (inst is BoxCollider)
			{
				LogComponent_BoxCollider((BoxCollider)inst);
				return;
			}
			if (inst is TerrainObject)
			{
				LogComponent_TerrainObject((TerrainObject)inst, prefix);
				return;
			}
			Console.WriteLine();
		}

		private static void LogComponent_TerrainObject(TerrainObject obj, string prefix)
		{
			Console.WriteLine($"{{{obj.PrefabGUID}}} \"{obj.name}\"");
			Console.WriteLine($"{prefix} pos:{obj.transform.position} rot:{obj.transform.rotation}");
			//Console.WriteLine($"{prefix} sceneryType: {(SceneryTypes)obj.visible?.ItemType}");
		}

		public static void LogComponent_TankBlock(TankBlock tankBlock, string prefix)
		{
			Console.WriteLine();
			Console.WriteLine($"{prefix}\tattachPoints:");
			foreach (Vector3 vec in tankBlock.attachPoints)
			{
				Console.WriteLine($"{prefix}\t\t- {vec}");
			}
			Console.WriteLine($"{prefix}\tfilledCells:");
			foreach (Vector3 vec in tankBlock.filledCells)
			{
				Console.WriteLine($"{prefix}\t\t- {vec}");
			}
			Console.WriteLine($"{prefix}\tpartialCells:");
			foreach (Vector3 vec in tankBlock.partialCells)
			{
				Console.WriteLine($"{prefix}\t\t- {vec}");
			}
			Console.WriteLine($"{prefix}\tapGroups:");
			foreach (TankBlock.APGroup group in tankBlock.apGroups)
			{
				Console.WriteLine($"{prefix}\t\t- Count: {group.Count}");
				foreach (int i in group.Enumerate())
				{
					Console.WriteLine($"{prefix}\t\t\t{i}");
				}
			}
		}

		public static void LogComponent_Visible(Visible visible)
		{
			Console.WriteLine(visible.Flags);
		}

		public static void LogComponent_MeshFilter(MeshFilter mesh)
		{
			Console.WriteLine(mesh.mesh.name);
		}

		public static void LogComponent_BoxCollider(BoxCollider box)
		{
			Console.WriteLine($"{box.center} {box.size}");
		}

		public static void LogPrivates(object obj, string prefix)
		{
			return;
			foreach (FieldInfo prop in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
			{
				object value = prop.GetValue(obj);
				if (value != null)
				{
					if (value.GetType().IsArray || typeof(ICollection).IsAssignableFrom(value.GetType()))
					{
						value = $"{((IEnumerable)value).Cast<object>().Count()} ({value.GetType()})";
					}
				}
				Console.WriteLine($"{prefix}{prop.Name} = {value}");
			}
			foreach (PropertyInfo prop in obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
			{
				object value;
				try
				{
					value = prop.GetValue(obj, null);
				}
				catch (Exception ex)
				{
					value = ex;
				}
				Console.WriteLine($"{prefix}{prop.Name} = {value}");
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.15020676234492825, 'fraction_numerical': 0.0012162490878131842, 'mean_word_length': 3.706926159129937, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '631689', 'n_tokens_mistral': 3273, 'n_tokens_neox': 2645, 'n_words': 490}