Exemplo n.º 1
0
        public static void Process(List <Node> nodes)
        {
            if (nodes.Count == 0)
            {
                return;
            }

            //Debug.Log(string.Format("Processing {0} top level additions in edit mode.", nodes.Count));

            foreach (Node node in nodes)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;

                if (null == transform)
                {
                    continue; // ROOT
                }
                ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                bool             isStage = adapter is StageAdapter;

                Transform parentTransform = node.ParentTransform;

                /* This happens when a stage added to root */
                if (null == parentTransform && !isStage)
                {
                    continue; // not a stage, return (if stage, should process)
                }
                GroupAdapter parentAdapter = null;

                if (null != parentTransform)
                {
                    parentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                }

                /**
                 * 2. Process adapters
                 * */
                if (null != adapter)
                {
                    // this is eDriven.Gui component. process it properly
                    if (null == parentAdapter)
                    {
                        if (!isStage)
                        {
                            const string txt = "eDriven.Gui components could be added to containers only";
                            throw new Exception(txt);
                        }
                    }
                    else
                    {
                        parentAdapter.AddChild(adapter, true);
                        //if (!PrefabUtil.IsCreatedFromPrefab(parentAdapter))
                        ParentChildLinker.Instance.Update(parentAdapter);
                    }
                }
            }
        }
Exemplo n.º 2
0
// ReSharper restore UnassignedField.Global
#endif

        /// <summary>
        /// Is processing additions, as well as top level additions
        /// </summary>
        /// <param name="topLevelAdditions">Needed for adding into order</param>
        /// <param name="additions">Needed for child instantiation</param>
        internal static void Process(List <Node> topLevelAdditions, List <Node> additions)
        {
            if (0 == topLevelAdditions.Count && 0 == additions.Count)
            {
                return;
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Processing {0} topLevelAdditions, {1} additions.", topLevelAdditions.Count, additions.Count));
            }
#endif
            foreach (Node node in additions)
            {
                bool isTopLevelAddition = topLevelAdditions.Contains(node);
                bool isPrefab           = PrefabUtility.GetPrefabType(node.Adapter) == PrefabType.PrefabInstance;

                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;

                if (null == transform)
                {
                    continue; // ROOT
                }
                ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                bool             isStage = adapter is StageAdapter;

                Transform parentTransform = node.ParentTransform;

                if (null == parentTransform && !isStage)
                {
                    continue; // not a stage, return (if stage, should process)
                }
                GroupAdapter parentAdapter = null;

                if (null != parentTransform)
                {
                    parentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                }

                /**
                 * 2. Process adapters
                 * */
                if (null != adapter)
                {
                    // this is eDriven.Gui component. process it properly
                    if (null == parentAdapter)
                    {
                        if (!isStage)
                        {
                            const string txt = "eDriven.Gui components could be added to containers only";
                            throw new Exception(txt);
                        }
                    }
                    else
                    {
                        /**
                         * Update parent ordering for top level additions only!
                         * */
                        if (isTopLevelAddition)
                        {
                            //node.Transform.parent = parentTransform;
                            parentAdapter.AddChild(adapter, true); // instantiate and change the parent collection

                            // ReSharper disable once RedundantCheckBeforeAssignment
                            if (adapter.transform.parent != parentTransform) // avoid multiple OnHierarchyChange callbacks
                            {
                                adapter.transform.parent = parentTransform;
                            }

                            //adapter.transform.parent = parentTransform;
                            ParentChildLinker.Instance.Update(parentAdapter);
                        }
                        else
                        {
                            //parentAdapter.DoInstantiate(adapter, true); // instantiate only
                            ChildGroupPack pack = ChildGroupPack.Read(parentAdapter);
                            pack.Consolidate(); // there is a null slot here. We have to re-render children
                            parentAdapter.InstantiateChildren(true);
                        }

                        /**
                         * Instantiate component
                         * */
                        if (!adapter.Instantiated)
                        {
                            adapter.DoInstantiate(true);
                        }

                        /**
                         * By now, the component should be instantiated
                         * */
                        var cmp = adapter.Component;
                        if (null == cmp)
                        {
                            throw new Exception("Component not found on ComponentAdapter: " + adapter);
                        }
                    }
                }

                /**
                 * 3. If adapter stuff went without a problem...
                 * */
                // ReSharper disable once RedundantCheckBeforeAssignment
                if (node.Transform.parent != parentTransform)
                {
                    node.Transform.parent = parentTransform;
                }
            }
        }
Exemplo n.º 3
0
        internal static void Process(List <Node> nodes)
        {
            if (nodes.Count == 0)
            {
                return;
            }

            //Debug.Log(string.Format("Processing {0} moves in edit mode.", nodes.Count));

            foreach (Node node in nodes)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;
                if (null == node.Transform)
                {
                    throw new Exception("Transform is null");
                }

                /*if (null == transform)
                 *  continue; // ROOT*/

                //Debug.Log("node.Transform: " + transform);

                ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                bool             isStage = adapter is StageAdapter;

                Transform oldParentTransform = node.OldParentTransform;
                Transform newParentTransform = node.ParentTransform;

                /* This happens when a stage moved to root */
                if (null == newParentTransform && !isStage)
                {
                    continue; // not a stage, return (if stage, should process) - only stage could be added to root
                }

                /**
                 * The adapter was moved
                 * It is still placed on the same (moved) transform
                 * We are accessing the old and the new parent adapter via transforms:
                 * 1. old parent transform could be referenced using the node.OldParentTransform
                 * 2. new parent transform could be referenced using the node.ParentTransform
                 * */
                GroupAdapter oldParentAdapter = null != oldParentTransform?
                                                GuiLookup.GetAdapter(oldParentTransform) as GroupAdapter:
                                                null;

                GroupAdapter newParentAdapter = null != newParentTransform?
                                                GuiLookup.GetAdapter(newParentTransform) as GroupAdapter:
                                                null;

                Debug.Log(string.Format("[{0}] -> moving from [{1}] to [{2}]",
                                        adapter,
                                        null == oldParentAdapter ? "-" : oldParentAdapter.ToString(),
                                        null == newParentAdapter ? "-" : newParentAdapter.ToString()
                                        ));

                /**
                 * 2. Sanity check
                 * */
                if (null == newParentAdapter && !isStage)
                {
                    throw new Exception("eDriven.Gui components could be added to containers only");
                }

                /**
                 * 3. Process adapters
                 * */
                if (null != oldParentAdapter)
                {
                    oldParentAdapter.RemoveChild(adapter);
                    ParentChildLinker.Instance.Update(oldParentAdapter);
                }

                if (null != newParentAdapter)
                {
                    newParentAdapter.AddChild(adapter, true);
                    ParentChildLinker.Instance.Update(newParentAdapter);
                }

                /**
                 * 4. Set transform
                 * */
                node.Transform.parent = newParentTransform;
            }
        }
Exemplo n.º 4
0
// ReSharper restore UnassignedField.Global
#endif

        internal static void Process(List <Node> moves)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Processing {0} moves.", moves.Count));
            }
#endif

            foreach (Node node in moves)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;

                Transform parentTransform = node.ParentTransform;

                if (null == transform)
                {
                    continue; // ROOT
                }
                //Debug.Log("node.Transform: " + transform);

                ComponentAdapter adapter     = GuiLookup.GetAdapter(transform);
                bool             thisIsStage = adapter is StageAdapter;

                /**
                 * The adapter has been moved
                 * It is still placed on the same (moved) transform
                 * We are accessing the old and the new parent adapter via transforms:
                 * - the old parent transform could be referenced using the node.OldParentTransform
                 * - the new parent transform could be referenced using the node.ParentTransform
                 * */

                if (null == node.Transform)
                {
                    throw new Exception("Transform is null");
                }

                GroupAdapter oldParentAdapter = GuiLookup.GetAdapter(node.OldParentTransform) as GroupAdapter;
                GroupAdapter newParentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;

                //Debug.Log(string.Format("  -> moving from [{0}] to [{1}]", oldParentAdapter, newParentAdapter));

                /**
                 * 2. Process adapters
                 * */
                if (null != oldParentAdapter)
                {
                    oldParentAdapter.RemoveChild(adapter);
                    ParentChildLinker.Instance.Update(oldParentAdapter);
                }

                if (null == newParentAdapter)
                {
                    if (!thisIsStage)
                    {
                        const string txt = "eDriven.Gui components could be added to containers only";
                        //Debug.LogWarning(txt);
                        throw new Exception(txt);
                    }
                }
                else
                {
                    newParentAdapter.AddChild(adapter, true);
                    ParentChildLinker.Instance.Update(newParentAdapter);
                }

                /**
                 * 3. If adapter stuff went without a problem...
                 * */
                node.Transform.parent = parentTransform;

                //ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                //bool thisIsStage = adapter is StageAdapter;

                ////Debug.Log("done.");

                //Transform parentTransform = node.ParentTransform;

                //if (null == parentTransform && !thisIsStage)
                //    continue; // not a stage, return (if stage, should process) - only stage could be added to root

                //ContainerAdapter newParentAdapter = null;

                //if (null != parentTransform)
                //    newParentAdapter = GuiLookup.GetAdapter(parentTransform) as ContainerAdapter;

                //    /**
                //     * 2. Process adapters
                //     * */
                //    if (null != adapter)
                //    {
                //        // this is eDriven.Gui component. process it properly
                //        if (null == newParentAdapter)
                //        {
                //            if (!thisIsStage) {
                //                const string txt = "eDriven.Gui components could be added to containers only";
                //                //Debug.LogWarning(txt);
                //                throw new Exception(txt);
                //                //return;
                //            }
                //        }
                //        else
                //        {
                //            ContainerAdapter oldParentAdapter = node.OldParentTransform.GetComponent<ContainerAdapter>();

                //            //Debug.Log("oldParentAdapter: " + oldParentAdapter);
                //            //Debug.Log("newParentAdapter: " + newParentAdapter);

                //            oldParentAdapter.RemoveChild(adapter);

                //            newParentAdapter.AddChild(adapter, true);

                //            ////if (!PrefabUtil.IsCreatedFromPrefab(oldParentAdapter)) // TODO: Need this?
                //            //    ParentChildLinker.Instance.Update(oldParentAdapter);

                //            ////if (!PrefabUtil.IsCreatedFromPrefab(newParentAdapter)) // TODO: Need this?
                //            //    ParentChildLinker.Instance.Update(newParentAdapter);

                //            if (EditorApplication.isPlaying)
                //            {
                //                if (!adapter.Instantiated)
                //                    adapter.DoInstantiate(true);
                //                //Debug.Log(string.Format("OnHierarchyChange: Component instantiated: {0} [{1}]", adapter.Component, adapter.transform.GetInstanceID()));
                //            }

                //            var cmp = adapter.Component;
                //            if (null == cmp)
                //            {
                //                throw new Exception("Component not found on ComponentAdapter: " + adapter);
                //            }
                //        }
                //    }

                //    /**
                //     * 3. If adapter stuff went without a problem...
                //     * */
                //    node.Transform.parent = parentTransform;
            }
        }