public bool GetManagedResources(out List <Component> components, out List <string> componentNames) { components = new List <Component>(); componentNames = new List <string>(); var fields = GetType().GetAllFields(false, true); foreach (var f in fields) { var at = f.GetCustomAttribute <CGResourceManagerAttribute>(); if (at != null) { #if NETFX_CORE if (typeof(ICGResourceCollection).GetTypeInfo().IsAssignableFrom(f.FieldType.GetTypeInfo())) #else if (typeof(ICGResourceCollection).IsAssignableFrom(f.FieldType)) #endif { ICGResourceCollection col = f.GetValue(this) as ICGResourceCollection; if (col != null) { var items = col.ItemsArray; foreach (var c in items) { if (c.transform.parent == transform) { components.Add(c); componentNames.Add(at.ResourceName); } } } } else { Component cmp = f.GetValue(this) as Component; if (cmp && cmp.transform.parent == transform) { components.Add(cmp); componentNames.Add(at.ResourceName); } } } } return(components.Count > 0); }
public bool GetManagedResources(out List <Component> components, out List <string> componentNames) { components = new List <Component>(); componentNames = new List <string>(); var fields = GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (var f in fields) { var attribs = f.GetCustomAttributes(typeof(CGResourceManagerAttribute), true); if (attribs.Length > 0) { if (typeof(ICGResourceCollection).IsAssignableFrom(f.FieldType)) { ICGResourceCollection col = f.GetValue(this) as ICGResourceCollection; if (col != null) { var items = col.ItemsArray; foreach (var c in items) { if (c.transform.parent == transform) { components.Add(c); componentNames.Add(((CGResourceManagerAttribute)attribs[0]).ResourceName); } } } } else { Component cmp = f.GetValue(this) as Component; if (cmp && cmp.transform.parent == transform) { components.Add(cmp); componentNames.Add(((CGResourceManagerAttribute)attribs[0]).ResourceName); } } } } return(components.Count > 0); }