Example #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.rootComponent.gameObject || isAllowSameObject == true)
                {
                    objectList.Add(refObject);
                }
            }
            else if (value is Component)
            {
                Component component = (Component)value;

                if (component == null)
                {
                    return;
                }

                if (component.gameObject != refObject.rootComponent.gameObject || isAllowSameObject == true)
                {
                    objectList.Add(refObject);
                }
            }
            else if (value is ICollection)
            {
                foreach (var item in (ICollection)value)
                {
                    var nestItem = new ReferenceObject()
                    {
                        rootComponent = refObject.rootComponent,
                        value         = item,
                        memberName    = refObject.memberName,
                    };
                    AddObject(nestItem, objectList, isAllowSameObject);
                }
            }
        }
        static void CollectObjectParameter(object obj, Component component, List<ReferenceObject>objectList)
        {
            if( obj == null)
                return;
            var type = obj.GetType ();

            if (IsIgnoreType (type))
                return;
            if (obj == null)
                return;
            if (type.IsPrimitive)
                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 (field.FieldType.GetCustomAttributes (typeof(System.SerializableAttribute), false).Length != 0) {
                    CollectObjectParameter (value, component, objectList);

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

            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);
                if(fi == null){
                    continue;
                }
                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 (){
                            rootComponent = component,
                            value = c,
                            memberName = 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 (){
                            rootComponent = component,
                            value = go,
                            memberName = ev.Name + "(" + item.Method.Name + ")",
                        };
                        AddObject (refObject, objectList, true);
                    }
                }

            }

            // property Instability

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

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

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

                    AddObject (item, objectList, false);

                } catch {
                }
            }
        }
Example #3
0
        static void CollectObjectParameter(object obj, Component component, List <ReferenceObject> objectList)
        {
            if (obj == null)
            {
                return;
            }
            var type = obj.GetType();

            if (IsIgnoreType(type))
            {
                return;
            }
            if (obj == null)
            {
                return;
            }
            if (type.IsPrimitive)
            {
                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 (field.FieldType.GetCustomAttributes(typeof(System.SerializableAttribute), false).Length != 0)
                {
                    CollectObjectParameter(value, component, objectList);
                }
                else
                {
                    var item = new ReferenceObject()
                    {
                        rootComponent = component,
                        value         = value,
                        memberName    = field.Name,
                    };
                    AddObject(item, objectList, true);
                }
            }

            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);
                if (fi == null)
                {
                    continue;
                }
                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()
                        {
                            rootComponent = component,
                            value         = c,
                            memberName    = 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()
                        {
                            rootComponent = component,
                            value         = go,
                            memberName    = ev.Name + "(" + item.Method.Name + ")",
                        };
                        AddObject(refObject, objectList, true);
                    }
                }
            }



            // property Instability

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

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

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

                    AddObject(item, objectList, false);
                } catch {
                }
            }
        }
        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.rootComponent.gameObject || isAllowSameObject == true)
                    objectList.Add (refObject);

            } else if (value is Component) {

                Component component = (Component)value;

                if (component == null)
                    return;

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

            } else if (value is ICollection) {

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