少年修仙传客户端代码仓库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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<string> PrintFieldsExpand(object _object, bool _includeArray)
    {
        if (_object == null)
        {
            return null;
        }
 
        var fields = _object.GetType().GetFields();
        var contents = new List<string>();
        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;
    }
 
}