/// <summary> /// Collects the field reference. /// </summary> /// <param name="component">Component.</param> /// <param name="referenceInfoList">Reference info list.</param> static void CollectFieldReference(System.Object component, ref List <ReferenceInfo> referenceInfoList, System.Object baseObject, int depth) { if (component == null) { return; } Type type = component.GetType(); foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)) { var value = ReferenceExplorerUtility.GetObject(field.GetValue(component)); if (value == null) { continue; } if (value is Component || value is GameObject) { referenceInfoList.Add(new ReferenceInfo() { fromObject = (System.Object)baseObject, referenceName = field.Name, referenceTarget = (System.Object)value }); continue; } if (value is IEnumerable) { foreach (var element in value as IEnumerable) { if (element is GameObject || element is Component) { referenceInfoList.Add(new ReferenceInfo() { fromObject = (System.Object)baseObject, referenceName = field.Name, referenceTarget = (System.Object)element }); } else if (IgnoreComponents.IsNotAnalyticsTypes(element)) { referenceInfoList.AddRange(FindReferenceInfo(element, baseObject, depth)); } } continue; } else if (value is System.Object) { referenceInfoList.AddRange(FindReferenceInfo(value, baseObject, depth)); continue; } } }
/// <summary> /// Collects all component. /// </summary> static void CollectAllComponent() { // collect all component. List <Component> allComponentOverlap = new List <Component> (); foreach (var sceneObject in allObjects) { if (sceneObject == null) { continue; } allComponentOverlap.AddRange(sceneObject.GetComponents <Component> ()); } allComponents = allComponentOverlap .Where(item => item != null) .Where(item => !IgnoreComponents.IsNotAnalyticsTypes(item)) .Distinct() .ToList(); }
private byte[] EncodeGameObject(GameObject inObject) { var goParameters = new Hashtable { { "name", inObject.name }, { "layer", inObject.layer }, { "active", inObject.active }, { "tag", inObject.tag }, { "childcount", 0 }, { "componentscount", 0 } }; #region Child var childCount = inObject.transform.childCount; goParameters["childcount"] = childCount; //Debug.Log(inObject.name+" find " + inObject.transform.childCount+" child"); var childsBytes = new byte[inObject.transform.childCount * 5]; var childNames = new List <string>(); var pos = 0; for (var i = 0; i < childCount; i++) { var child = inObject.transform.GetChild(i).gameObject; //Debug.Log("Find children "+child); if (childNames.Contains(child.name)) { child.name += _nameKey.ToString(); _nameKey++; } childNames.Add(child.name); var childBytes = Encoding(child); Buffer.BlockCopy(childBytes, 0, childsBytes, pos, 5);//Get 5 bytes : X-252 X..X resource index pos += 5; } /*foreach (Transform child in inObject.transform) * { * if (childNames.Contains(child.name)) * { * child.name += _nameKey.ToString(); * _nameKey++; * } * childNames.Add(child.name); * var childBytes = Encoding(child.gameObject); * Buffer.BlockCopy(childBytes, 0, childsBytes, pos, 5);//Get 5 bytes : X-252 X..X resource index * pos += 5; * }*/ #endregion #region Components var components = inObject.GetComponents <Component>(); var componentList = new List <Component>(); foreach (var srcComponent in components) { if (IgnoreComponents.Contains(srcComponent.GetType().FullName)) { continue; } componentList.Add(srcComponent); } goParameters["componentscount"] = componentList.Count; var componentsBytes = new byte[componentList.Count * 5]; pos = 0; foreach (var component in componentList) { Buffer.BlockCopy(EncodeComponent(component), 0, componentsBytes, pos, 5); //Get 5 bytes : X-252 X..X resource index pos += 5; } //Debug.Log(BitConverter.ToString(componentsBytes)); #endregion var parameterBytes = EncodeHashtable(goParameters); var startPos = parameterBytes.Length; var result = new byte[startPos + childsBytes.Length + componentsBytes.Length]; Buffer.BlockCopy(parameterBytes, 0, result, 0, startPos); Buffer.BlockCopy(childsBytes, 0, result, startPos, childsBytes.Length); startPos += childsBytes.Length; Buffer.BlockCopy(componentsBytes, 0, result, startPos, componentsBytes.Length); //Debug.Log(BitConverter.ToString(result)); return(result); }