Exemple #1
0
        public override IEnumerator Refresh()
        {
            var mine = this.mine;

            if (mine)
            {
                mySO = new SerializedObject(mine);
            }

            var theirs = this.theirs;

            if (theirs)
            {
                theirSO = new SerializedObject(theirs);
            }

            var enumerator = PropertyHelper.UpdatePropertyList(properties, mySO, theirSO, null, this, null, objectMerge, sceneMerge, this, window);

            while (enumerator.MoveNext())
            {
                yield return(null);
            }

            Same = enumerator.Current;
        }
Exemple #2
0
        /// <summary>
        ///     Refresh is a very crucial function.  Not only does it refresh the abstracted lists of ObjectHelpers and
        ///     ComponentHelpers to reflect the actual scene,
        ///     it is responsible for actually comparing objects
        /// </summary>
        /// <returns>IEnumerator for coroutine progress</returns>
        public IEnumerator DoRefresh()
        {
            Same = true;
            MyChildren.Clear();
            TheirChildren.Clear();
            MyComponents.Clear();
            TheirComponents.Clear();
            //Get lists of components and children
            if (mine)
            {
                window.updateCount++;
                MyChildren.AddRange(from Transform t in mine.transform select t.gameObject);
#if UNITY_4_6 || UNITY_4_7 || UNITY_5 || UNITY_5_3_OR_NEWER
                mine.GetComponents(MyComponents);
#else
                MyComponents.AddRange(mine.GetComponents <Component>());
#endif
            }
            if (theirs)
            {
                window.updateCount++;
                TheirChildren.AddRange(from Transform t in theirs.transform select t.gameObject);
#if UNITY_4_6 || UNITY_4_7 || UNITY_5 || UNITY_5_3_OR_NEWER
                theirs.GetComponents(TheirComponents);
#else
                TheirComponents.AddRange(theirs.GetComponents <Component>());
#endif
            }

            // Clear empty components
            components.RemoveAll(helper => helper.mine == null && helper.theirs == null);

            //TODO: turn these two chunks into one function... somehow
            //Merge Components
            ComponentHelper ch;
            for (var i = 0; i < MyComponents.Count; i++)
            {
                var component = MyComponents[i];
                // Missing scripts show up as null
                if (component == null)
                {
                    continue;
                }

                var match = TheirComponents.Where(g => g != null).FirstOrDefault(g => component.GetType() == g.GetType());

                ch = components.Find(helper => helper.mine == component || match != null && helper.theirs == match);

                if (ch == null)
                {
                    ch = new ComponentHelper(component, match, this, window);
                    components.Add(ch);
                }
                else
                {
                    ch.mine   = component;
                    ch.theirs = match;
                }

                var enumerator = ch.Refresh();
                while (enumerator.MoveNext())
                {
                    yield return(null);
                }

                if (!ComponentIsFiltered(ch.type) && !ch.Same)
                {
                    Same = false;
                }

                TheirComponents.Remove(match);
            }

            if (TheirComponents.Count > 0)
            {
                foreach (var g in TheirComponents)
                {
                    // Missing scripts show up as null
                    if (g == null)
                    {
                        continue;
                    }

                    ch = components.Find(helper => helper.theirs == g);

                    if (ch == null)
                    {
                        ch = new ComponentHelper(null, g, this, window);
                        var enumerator = ch.Refresh();
                        while (enumerator.MoveNext())
                        {
                            yield return(null);
                        }

                        components.Add(ch);
                    }

                    if (!ComponentIsFiltered(ch.type) && !ch.Same)
                    {
                        Same = false;
                    }
                }
            }

            // Clear empty components
            if (children != null)
            {
                children.RemoveAll(helper => helper.mine == null && helper.theirs == null);
            }

            //Merge Children
            GameObjectHelper oh = null;
            foreach (var child in MyChildren)
            {
                var match = TheirChildren.FirstOrDefault(g => SameObject(child, g));

                if (children != null)
                {
                    oh = children.Find(helper => helper.mine == child || match != null && helper.theirs == match);
                }

                if (oh == null)
                {
                    oh = new GameObjectHelper(window, this)
                    {
                        mine = child, theirs = match
                    };

                    if (children == null)
                    {
                        children = new List <GameObjectHelper>();
                    }

                    children.Add(oh);
                }
                else
                {
                    oh.mine   = child;
                    oh.theirs = match;
                }
                TheirChildren.Remove(match);
            }

            if (TheirChildren.Count > 0)
            {
                Same = false;
                foreach (var g in TheirChildren)
                {
                    if (children != null)
                    {
                        oh = children.Find(helper => helper.theirs == g);
                    }

                    if (oh == null)
                    {
                        if (children == null)
                        {
                            children = new List <GameObjectHelper>();
                        }

                        children.Add(new GameObjectHelper(window, this)
                        {
                            theirs = g
                        });
                    }
                }
            }

            tmpList.Clear();
            if (children != null)
            {
                tmpList.AddRange(children);
                foreach (var obj in tmpList)
                {
                    if (obj.mine == null && obj.theirs == null)
                    {
                        children.Remove(obj);
                    }
                }

                children.Sort(delegate(GameObjectHelper a, GameObjectHelper b) {
                    if (a.mine && b.mine)
                    {
                        return(a.mine.name.CompareTo(b.mine.name));
                    }
                    if (a.mine && b.theirs)
                    {
                        return(a.mine.name.CompareTo(b.theirs.name));
                    }
                    if (a.theirs && b.mine)
                    {
                        return(a.theirs.name.CompareTo(b.mine.name));
                    }
                    if (a.theirs && b.theirs)
                    {
                        return(a.theirs.name.CompareTo(b.theirs.name));
                    }
                    return(0);
                });

                tmpList.Clear();
                tmpList.AddRange(children);
                foreach (var child in tmpList)
                {
                    var enumerator = child.DoRefresh();
                    while (enumerator.MoveNext())
                    {
                        yield return(null);
                    }
                    if (!child.Same)
                    {
                        Same = false;
                    }
                }
            }

            if (mine)
            {
                mySO = new SerializedObject(mine);
            }

            if (theirs)
            {
                theirSO = new SerializedObject(theirs);
            }

            var e = PropertyHelper.UpdatePropertyList(attributes, mySO, theirSO, this, window, true);
            while (e.MoveNext())
            {
                yield return(null);
            }

            sameAttrs = true;
            // ReSharper disable once ForCanBeConvertedToForeach
            for (var i = 0; i < attributes.Count; i++)
            {
                var attribute = attributes[i];
                if (!attribute.Same)
                {
                    sameAttrs = false;
                }
            }

            if (!sameAttrs && window.compareAttrs)
            {
                Same = false;
            }
        }