示例#1
0
        /// <summary>
        /// Scans the supplied parent adapter
        /// Converts ChildGroupPacks to SaveablePacks and saves them to dictionary
        /// These packs are used later (in "Process" method) to apply the changes after the play mode is stopped
        /// </summary>
        /// <param name="parentAdapter"></param>
        /// <param name="pack"></param>
        public void Update(GroupAdapter parentAdapter, ChildGroupPack pack)
        {
            //Debug.Log("Update: " + parentAdapter);
#if DEBUG
            if (DebugMode)
            {
                //Debug.Log(string.Format("Linking {0} -> {1}", parentAdapter, childAdapter));
                Debug.Log(string.Format("ParentChildLinker: Updating {0}", parentAdapter));
            }
#endif
            //Debug.Log("parentAdapter: " + parentAdapter);
            // 1. we have to monitor parentAdapter for later (if not yet monitored)
            if (Application.isPlaying)
            {
                PersistenceManager.Instance.Watch(parentAdapter);
            }

            // 2. if no pack supplied, read it now
            if (null == pack)
            {
                //Debug.Log("ParentChildLinker: Pack not defined. Reading now.");
                pack = ChildGroupPack.Read(parentAdapter);
            }

            // 3. register adapters for later
            pack.RegisterAdapters();

            // 4. get relation object
            var guidPack = pack.ToSaveablePack();

            // 5. cache it (overwrite existing!)
            _changes[guidPack.ParentInstanceId] = guidPack;
        }
示例#2
0
        public static void Write(GroupAdapter parentAdapter, ChildGroupPack pack)
        {
            ChildGroupPack currentGroupPack = ChildGroupPack.Read(parentAdapter);

            Debug.Log(string.Format("ParentAdapter: {0}, {1}", parentAdapter,
                                    parentAdapter.GetInstanceID()));

            for (int i = 0; i < currentGroupPack.Groups.Count; i++)
            {
                var currentGroup = currentGroupPack.Groups[i];
                Debug.Log("newGroup.Adapters: " + currentGroup.Adapters.Count);
                currentGroup.Adapters.Clear();
                //Debug.Log("newGroup.Adapters 2: " + newGroup.Adapters.Count);
                currentGroup.Adapters.AddRange(pack.Groups[i].Adapters);
                Debug.Log("newGroup.Adapters 2: " + currentGroup.Adapters.Count);
            }
        }
示例#3
0
        public static void DescribeChildrenWithGroups(ref StringBuilder sb, Node node, bool richText)
        {
            var childNodes = node.ChildNodes;

            var unprocessedNodes = ListUtil <Node> .Clone(node.ChildNodes);

            var adapter = node.Adapter;

            //Debug.Log(@"adapter: " + adapter);
            var containerAdapter = adapter as GroupAdapter;

            // Note: the ROOT node has no adapter nor groups defined!
            if (null != containerAdapter)
            {
                ChildGroupPack pack = ChildGroupPack.Read(containerAdapter);
                //                Debug.Log(@"pack:
                //" + pack);
                foreach (ChildGroup childGroup in pack.Groups)
                {
                    sb.AppendLine(StringUtil.Indent(node.Depth + 1, string.Format("== {0} ==", childGroup.GroupName)));
                    foreach (ComponentAdapter componentAdapter in childGroup.Adapters)
                    {
                        var childNode = GetNode(childNodes, componentAdapter);
                        if (null == childNode)
                        {
                            var line = StringUtil.Indent(node.Depth + 1, string.Format("*** Not found ***"));
                            if (richText)
                            {
                                line = (StringUtil.WrapColor(StringUtil.WrapTag(line, "b"), EditorSettings.UseDarkSkin ? "yellow" : "blue"));
                            }
                            sb.AppendLine(line);
                        }
                        else
                        {
                            unprocessedNodes.Remove(childNode);
                            string name = null == childNode.Transform ? "New" : childNode.Transform.name;

                            var    isSelected = Selection.activeGameObject == componentAdapter.gameObject;
                            string selected   = isSelected ? "*" : string.Empty;
                            string changed    = ParentChildLinker.Instance.IsChanged(childNode.AdapterId) ? "[changed]" : string.Empty;

                            var line = StringUtil.Indent(childNode.Depth /* + 1*/,
                                                         string.Format("{2}{0} [A:{1}]{3}", name, childNode.AdapterId, selected, changed));

                            if (richText && isSelected)
                            {
                                line = StringUtil.WrapTag(line, "b");
                            }

                            sb.AppendLine(line);
                            DescribeChildrenWithGroups(ref sb, childNode, richText);
                        }
                    }
                }
            }

            if (unprocessedNodes.Count > 0 && null != node.ParentTransform)
            {
                sb.AppendLine(StringUtil.Indent(node.Depth + 1, string.Format("== Orphans ==")));
            }

            // orphans
            foreach (Node childNode in unprocessedNodes)
            {
                string name       = null == childNode.Transform ? "New" : childNode.Transform.name;
                var    isSelected = (Selection.activeGameObject == childNode.Adapter.gameObject);
                string selected   = isSelected ? "*" : string.Empty;
                string changed    = ParentChildLinker.Instance.IsChanged(childNode.AdapterId) ? "[changed]" : string.Empty;

                bool   isOrphan = !(childNode.Adapter is StageAdapter);
                string orphan   = isOrphan ? "[orphan] " : string.Empty;
                //string orphan = StringUtil.WrapColor((childNode.Adapter is StageAdapter) ? string.Empty : "[orphan] ",
                //EditorSettings.UseDarkSkin ? "yellow" : "blue");

                var line = StringUtil.Indent(childNode.Depth /* + 1*/, string.Format("{4}{2}{0} [A:{1}]{3}", name, childNode.AdapterId, selected, changed, orphan));
                if (isOrphan)
                {
                    line = StringUtil.WrapColor(StringUtil.WrapTag(line, "b"), EditorSettings.UseDarkSkin ? "yellow" : "blue");
                }

                if (richText && isSelected)
                {
                    line = StringUtil.WrapTag(line, "b");
                }

                sb.AppendLine(line);
                DescribeChildrenWithGroups(ref sb, childNode, richText);
            }
        }
示例#4
0
        /// <summary>
        /// Recursive!
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="node"></param>
        private static void DoFix(ref StringBuilder sb, Node node)
        {
            bool isRoot = (null == node.Adapter);
            //if (!isRoot)
            //    Debug.Log(StringUtil.Indent(node.Depth, "Fixing " + node.Adapter));

            var childNodes = node.ChildNodes;

            var unprocessedNodes = ListUtil <Node> .Clone(node.ChildNodes);

            var adapter = node.Adapter;

            //Debug.Log(@"adapter: " + adapter);
            var containerAdapter = adapter as GroupAdapter;

            //Debug.Log(@"containerAdapter: " + containerAdapter);

            // Note: the ROOT node has no adapter no groups defined!

            if (null != containerAdapter)
            {
                ChildGroupPack pack = ChildGroupPack.Read(containerAdapter);
                // Debug.Log(@"pack:
                //" + pack);
                foreach (ChildGroup childGroup in pack.Groups)
                {
                    //sb.AppendLine(StringUtil.Indent(node.Depth + 1, string.Format("== {0} ==", childGroup.GroupName)));
                    //foreach (ComponentAdapter componentAdapter in childGroup.Adapters)
                    for (int i = childGroup.Adapters.Count - 1; i >= 0; i--)
                    {
                        ComponentAdapter componentAdapter = childGroup.Adapters[i];

                        bool doRemove = false;

                        /**
                         * 1. Handle null
                         * */
                        if (null == componentAdapter)
                        {
                            //sb.AppendLine(StringUtil.Indent(node.Depth + 1, "*** Not found ***"));
                            // adapter is not child of this container, remove it from the list
                            //toRemove.Add(componentAdapter);
                            doRemove = true;
                        }

                        /**
                         * 2. Not null. Handle the adapter
                         * */
                        else
                        {
                            var childNode = GetNode(childNodes, componentAdapter);
                            if (null == childNode)
                            {
                                //sb.AppendLine(StringUtil.Indent(node.Depth + 1, "*** Not found ***"));
                                // adapter is not child of this container, remove it from the list
                                //toRemove.Add(componentAdapter);
                                doRemove = true;
                            }
                            else
                            {
                                unprocessedNodes.Remove(childNode);
                                DoFix(ref sb, childNode);
                            }
                        }

                        if (doRemove)
                        {
                            //Debug.Log("list 1: " + ComponentAdapterUtil.DescribeAdapterList(childGroup.Adapters));
                            childGroup.Adapters.RemoveAt(i);
                            //childGroup.Adapters.Remove(adapterToRemove);
                            if (null != componentAdapter)
                            {
                                sb.AppendLine(string.Format("{0}: {1} [A:{2}] removed", GuiLookup.PathToString(containerAdapter.transform, "->"), componentAdapter, componentAdapter.GetInstanceID()));
                            }
                            else
                            {
                                sb.AppendLine(string.Format("{0}: Adapter at position {1} removed", GuiLookup.PathToString(containerAdapter.transform, "->"), i));
                            }
                            //Debug.Log("list 2: " + ComponentAdapterUtil.DescribeAdapterList(childGroup.Adapters));
                        }
                    }
                }
            }

            // orphans
            foreach (Node childNode in unprocessedNodes)
            {
                if (!isRoot)
                {
                    if (null != containerAdapter)
                    {
                        ChildGroupPack pack = ChildGroupPack.Read(containerAdapter);
                        if (pack.Groups.Count > 0)
                        {
                            pack.Groups[0].Adapters.Add(childNode.Adapter);
                            sb.AppendLine(string.Format("{0}: [{1}] added to the first group", GuiLookup.PathToString(containerAdapter.transform, "->"), childNode.Adapter));
                        }
                    }
                }
                DoFix(ref sb, childNode);
            }
        }