using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class FieldPrint { public static string PrintFields(object _object) { if (_object == null) { return string.Empty; } var fields = _object.GetType().GetFields(); var contents = new string[fields.Length]; for (int i = 0; i < fields.Length; i++) { var field = fields[i]; var fieldContent = field.GetValue(_object); contents[i] = string.Format("\"{0}\":{1}", field.Name, fieldContent); } return string.Join("; ", contents); } public static List PrintFieldsExpand(object _object, bool _includeArray) { if (_object == null) { return null; } var fields = _object.GetType().GetFields(); var contents = new List(); for (int i = 0; i < fields.Length; i++) { var field = fields[i]; var fieldContent = field.GetValue(_object); if (fieldContent is Array) { contents.AddRange(PrintArray(field.Name, fieldContent)); } else { contents.Add(string.Format("\"{0}\":{1}", field.Name, fieldContent)); } } return contents; } private static string[] PrintArray(string _name, object _object) { var objects = _object as Array; var contents = new string[objects.Length]; for (int i = 0; i < objects.Length; i++) { var o = objects.GetValue(i); var type = o.GetType(); if (type.Name == "String") { contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (String)o); } else if (type.Name == "UInt32") { contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (UInt32)o); } else if (type.Name == "Byte") { contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (Byte)o); } else if (type.Name == "UInt16") { contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (UInt16)o); } else if (type.Name == "Single") { contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (float)o); } else if (type.Name == "Boolean") { contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (bool)o); } else if (type.Name == "Int32") { contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (int)o); } else { contents[i] = string.Format("\"{0}\"[{1}]-->{2}", _name, i, PrintFields(o)); } } return contents; } }