Exemplo n.º 1
0
        private static void AddObject(ReferenceObject refObject, List <ReferenceObject> objectList, bool isAllowSameObject)
        {
            var value = refObject.value;

            if (value == null)
            {
                return;
            }

            if (value is GameObject)
            {
                var obj = value as GameObject;
                if (obj != refObject.referenceComponent.gameObject || isAllowSameObject == true)
                {
                    objectList.Add(refObject);
                }
            }
            else if (value is Component)
            {
                Component component = (Component)value;

                if (component == null)
                {
                    return;
                }

                if (component.gameObject != refObject.referenceComponent.gameObject || isAllowSameObject == true)
                {
                    objectList.Add(refObject);
                }
            }
            else if (value is ICollection)
            {
                foreach (var item in (ICollection)value)
                {
                    var nestItem = new ReferenceObject()
                    {
                        referenceComponent = refObject.referenceComponent,
                        value = item,
                        referenceMemberName = refObject.referenceMemberName,
                    };
                    AddObject(nestItem, objectList, isAllowSameObject);
                }
            }
        }
        static void CollectObjectParameter(object obj, Component component, List<ReferenceObject>objectList, int hierarchy)
        {
            try {
                hierarchy ++;
                if( hierarchy > 3 )
                    return;

                if (obj == null)
                    return;
                var type = obj.GetType ();

                if (IsIgnoreType (type))
                    return;
                if (obj == null)
                    return;
                if (type.IsPrimitive || type.IsEnum)
                    return;

                foreach (var field in type.GetFields(
                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                    BindingFlags.Static | BindingFlags.DeclaredOnly)) {

                    if (IsIgnoreMember (field.FieldType, field.Name))
                        continue;

                    var value = field.GetValue (obj);
                    if (value == null)
                        continue;

                    if( value is GameObject || value is Component )
                    {
                        var item = GetGameObject(value);
                        if( item == null )
                            continue;
                    }

                    if( System.Array.Exists<System.Type>( primitive, item => item == value.GetType() ) )
                        continue;

                    if (field.FieldType.GetCustomAttributes (typeof(System.SerializableAttribute), false).Length != 0) {
                        CollectObjectParameter (value, component, objectList, hierarchy);

                    } else {
                        var item = new ReferenceObject (){
                        referenceComponent = component,
                        value = value,
                        referenceMemberName = field.Name,
                    };
                        AddObject (item, objectList, true);
                    }
                    continue;
                }

                foreach (var ev in type.GetEvents()) {

                    if (System.Array.AsReadOnly<string> (ignoreEvents).Contains (ev.Name)) {
                        continue;
                    }

                    var fi = type.GetField (ev.Name,
                        BindingFlags.Static |
                        BindingFlags.NonPublic |
                        BindingFlags.Instance |
                        BindingFlags.Public |
                        BindingFlags.FlattenHierarchy);

                    var del = (System.Delegate)fi.GetValue (obj);

                    if (del == null) {
                        continue;
                    }

                    var list = del.GetInvocationList ();

                    foreach (var item in list) {
                        if (item.Target is Component) {
                            var c = item.Target as Component;
                            if (c == null)
                                continue;

                            var refObject = new ReferenceObject (){
                            referenceComponent = component,
                            value = c,
                            referenceMemberName = ev.Name + "(" + item.Method.Name + ")",
                        };
                            AddObject (refObject, objectList, true);
                        }
                        if (item.Target is GameObject) {
                            var go = item.Target as GameObject;
                            if (go == null)
                                continue;

                            var refObject = new ReferenceObject (){
                            referenceComponent = component,
                                value = go,
                                referenceMemberName = ev.Name + "(" + item.Method.Name + ")",
                            };
                            AddObject (refObject, objectList, true);
                            continue;
                        }
                    }

                }

                // property Instability

                foreach (var property in type.GetProperties(
                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance )) {
                    if (IsIgnoreMember (property.PropertyType, property.Name))
                        continue;

                    if (IsIgnoreType (property.PropertyType))
                        continue;

                    var value = property.GetValue (obj, null);
                    if (value == null)
                        continue;

                    var item = new ReferenceObject (){
                        referenceComponent = component,
                        value = value,
                        referenceMemberName = property.Name,
                    };

                    AddObject (item, objectList, false);
                    continue;
                }

            }catch (System.ArgumentException){
            } catch (System.Exception e) {
                Debug.LogWarning (e.ToString ());

            }
        }
Exemplo n.º 3
0
        static void CollectObjectParameter(object obj, Component component, List <ReferenceObject> objectList, int hierarchy)
        {
            try {
                hierarchy++;
                if (hierarchy > 3)
                {
                    return;
                }

                if (obj == null)
                {
                    return;
                }
                var type = obj.GetType();

                if (IsIgnoreType(type))
                {
                    return;
                }
                if (obj == null)
                {
                    return;
                }
                if (type.IsPrimitive || type.IsEnum)
                {
                    return;
                }



                foreach (var field in type.GetFields(
                             BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                             BindingFlags.Static | BindingFlags.DeclaredOnly))
                {
                    if (IsIgnoreMember(field.FieldType, field.Name))
                    {
                        continue;
                    }

                    var value = field.GetValue(obj);
                    if (value == null)
                    {
                        continue;
                    }

                    if (value is GameObject || value is Component)
                    {
                        var item = GetGameObject(value);
                        if (item == null)
                        {
                            continue;
                        }
                    }

                    if (System.Array.Exists <System.Type>(primitive, item => item == value.GetType()))
                    {
                        continue;
                    }



                    if (field.FieldType.GetCustomAttributes(typeof(System.SerializableAttribute), false).Length != 0)
                    {
                        CollectObjectParameter(value, component, objectList, hierarchy);
                    }
                    else
                    {
                        var item = new ReferenceObject()
                        {
                            referenceComponent = component,
                            value = value,
                            referenceMemberName = field.Name,
                        };
                        AddObject(item, objectList, true);
                    }
                    continue;
                }

                foreach (var ev in type.GetEvents())
                {
                    if (System.Array.AsReadOnly <string> (ignoreEvents).Contains(ev.Name))
                    {
                        continue;
                    }

                    var fi = type.GetField(ev.Name,
                                           BindingFlags.Static |
                                           BindingFlags.NonPublic |
                                           BindingFlags.Instance |
                                           BindingFlags.Public |
                                           BindingFlags.FlattenHierarchy);

                    var del = (System.Delegate)fi.GetValue(obj);


                    if (del == null)
                    {
                        continue;
                    }

                    var list = del.GetInvocationList();

                    foreach (var item in list)
                    {
                        if (item.Target is Component)
                        {
                            var c = item.Target as Component;
                            if (c == null)
                            {
                                continue;
                            }

                            var refObject = new ReferenceObject()
                            {
                                referenceComponent = component,
                                value = c,
                                referenceMemberName = ev.Name + "(" + item.Method.Name + ")",
                            };
                            AddObject(refObject, objectList, true);
                        }
                        if (item.Target is GameObject)
                        {
                            var go = item.Target as GameObject;
                            if (go == null)
                            {
                                continue;
                            }

                            var refObject = new ReferenceObject()
                            {
                                referenceComponent = component,
                                value = go,
                                referenceMemberName = ev.Name + "(" + item.Method.Name + ")",
                            };
                            AddObject(refObject, objectList, true);
                            continue;
                        }
                    }
                }


                // property Instability

                foreach (var property in type.GetProperties(
                             BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    if (IsIgnoreMember(property.PropertyType, property.Name))
                    {
                        continue;
                    }

                    if (IsIgnoreType(property.PropertyType))
                    {
                        continue;
                    }

                    var value = property.GetValue(obj, null);
                    if (value == null)
                    {
                        continue;
                    }

                    var item = new ReferenceObject()
                    {
                        referenceComponent = component,
                        value = value,
                        referenceMemberName = property.Name,
                    };

                    AddObject(item, objectList, false);
                    continue;
                }
            }catch (System.ArgumentException) {
            } catch (System.Exception e) {
                Debug.LogWarning(e.ToString());
            }
        }
        private static void AddObject(ReferenceObject refObject, List<ReferenceObject> objectList, bool isAllowSameObject)
        {
            var value = refObject.value;
            if (value == null)
                return;

            if (value is GameObject) {

                var obj = value as GameObject;
                if (obj != refObject.referenceComponent.gameObject || isAllowSameObject == true)
                    objectList.Add (refObject);

            } else if (value is Component) {

                Component component = (Component)value;

                if (component == null)
                    return;

                if (component.gameObject != refObject.referenceComponent.gameObject || isAllowSameObject == true)
                    objectList.Add (refObject);

            } else if (value is ICollection) {

                foreach (var item in (ICollection)value) {
                    var nestItem = new ReferenceObject (){
                        referenceComponent = refObject.referenceComponent,
                        value = item,
                        referenceMemberName = refObject.referenceMemberName,
                    };
                    AddObject (nestItem, objectList, isAllowSameObject);
                }
            }
        }