private void treeView1_MouseDown(object sender, MouseEventArgs e) { TreeNode node = treeView1.GetNodeAt(e.X, e.Y); if (node != null) { treeView1.SelectedNode = node; ulong guid = ulong.Parse(node.Tag.ToString()); UnityObject obj = PrefabAnalyzer.GetObjectById(guid); GameObject go = obj as GameObject; if (go != null && go.mComponents != null) { for (int i = 0; i < go.mComponents.Count; i++) { Console.WriteLine(go.mComponents[i].GetType()); } } } }
public static void DoAnalyze(string content) { InitData(); string[] lineArr = content.Split('\n'); string line = null; UnityObject currentObj = null; PropertyInfo[] propArr = null; object[] propPatterns = null; Match match; UnityAttribute attr; for (int i = 2, lineLen = lineArr.Length; i < lineLen; i++) { line = lineArr[i].TrimStart(); // start with a new object if (line.StartsWith("--- ")) { currentObj = null; } //init new object foreach (Type t in mClassPatterns.Keys) { attr = mClassPatterns[t]; match = Regex.Match(line, attr.titlePattern); if (match.Success) { currentObj = (UnityObject)Activator.CreateInstance(t, true); currentObj.guid = ulong.Parse(match.Groups[1].Value); propArr = currentObj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); if (currentObj.ObjType == enmObjectType.Prefab) { mPrefabObjects[currentObj.guid] = currentObj as Prefab; } else { mDicObjects[currentObj.guid] = currentObj; } break; } } //add children ids if (currentObj != null) { match = Regex.Match(line, @"^- component: {fileID: (.+)}$"); if (match.Success) { currentObj.AddComponentId(ulong.Parse(match.Groups[1].Value)); continue; } match = Regex.Match(line, @"^- {fileID: (.+)}$"); if (match.Success) { currentObj.AddComponentId(ulong.Parse(match.Groups[1].Value)); continue; } } // analyze properties if (currentObj != null && propArr != null) { for (int j = 0, fieldLen = propArr.Length; j < fieldLen; j++) { propPatterns = propArr[j].GetCustomAttributes(typeof(UnityAttribute), false); if (propPatterns != null && propPatterns.Length > 0) { match = Regex.Match(line, (propPatterns[0] as UnityAttribute).titlePattern); if (match.Success) { if (match.Groups.Count > 1) { propArr[j].SetValue(currentObj, ParsePropValue(propArr[j], match.Groups[1].Value)); } else { propArr[j].SetValue(currentObj, ParsePropValue(propArr[j], "1")); } break; } } } } } // build tree struct with each object GenerateTreeStruct(); Console.WriteLine("Fin"); }