// ReSharper restore UnassignedField.Global #endif internal static void Process(List <Node> removals) { if (0 == removals.Count) { return; } #if DEBUG if (DebugMode) { Debug.Log(string.Format("Processing {0} removals.", removals.Count)); } #endif //Debug.Log(string.Format("Processing {0} removals.", removals.Count)); // TODO: do removals bottom up! nesting level should be used here foreach (Node node in removals) { //if (null == node.Transform) // continue; // ROOT node.RemoveFromHierarchy(); //Debug.Log("node.ParentTransform: " + node.ParentTransform); if (null == node.ParentTransform) //|| /*!*/(adapter is StageAdapter)) { continue; // not a stage, return (if stage, should process) } // consolidate parent transform ComponentAdapter adapter = node.Adapter; GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter; if (null != parentGroupAdapter) { /** * Stop monitoring * */ PersistenceManager.Instance.Unwatch(node.AdapterId); //PersistenceManager.Instance.RemoveAdapter(node.AdapterId); /** * Note: if object removed from the hierarchy, the adapter is destroyed * In that case following command doesn nothing (doesn not remove the slot from the parent) * Thus we have the consolidation below (removing null) * */ parentGroupAdapter.RemoveChild(adapter); // TODO: consolidate only for top level removals (add parameter) /*parentContainerAdapter.RemoveChild(adapter);*/ //parentContainerAdapter.RemoveAllChildren(); ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter); pack.Consolidate(); // there is a null slot here. We have to re-render children //Debug.Log("*pack: " + pack); parentGroupAdapter.InstantiateChildren(true); } } }
internal static void Process(List <Node> nodes) { if (nodes.Count == 0) { return; } //Debug.Log(string.Format("Processing {0} top level removals in edit mode.", nodes.Count)); foreach (Node node in nodes) { if (null == node.ParentTransform) { continue; } GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter; if (null != parentGroupAdapter) { /** * Important: the removal could happen when we *move* components outside of the Stage hierarchy * From group's standpoint, these components have been *removed* * However, the adapters are not null, so the consolidation without a prior * removal would do nothing to the parent collection (e.g. the moved adapter * would still be on the list) * */ parentGroupAdapter.RemoveChild(node.Adapter); ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter); pack.Consolidate(); // there is a null slot here. We have to re-render children } } }
private void RedrawComponentsInGameView(ChildGroupPack pack) { for (int i = 0; i < pack.Groups.Count; i++) { ChildGroupDescriptor groupDescriptor = _groupManager.GroupDescriptors[i]; List <ComponentAdapter> adaptersCollection = groupDescriptor.GetChildAdaptersCollection(GroupAdapter); if (null == adaptersCollection) { return; } // TODO: move to parent child linker var targetContainer = groupDescriptor.GetTargetContainer((IContentChildList)GroupAdapter.Component); if (null == targetContainer) { continue; // not instantiated } targetContainer.RemoveAllContentChildren(); foreach (ComponentAdapter adapter in adaptersCollection) { if (null != adapter && adapter.gameObject.activeInHierarchy && adapter.enabled) // the adapter could be disabled in many ways { targetContainer.AddContentChild(adapter.Component); } } } }
public GroupManager(GroupAdapter adapter) { //Debug.Log("Creating GroupManager"); _groupAdapter = adapter; _groupDescriptors = DesignerReflection.GetChildGroupsReferences(adapter); _pack = ChildGroupPack.Read(adapter); }
/// <summary> /// Note: this method actually changes the collections /// </summary> /// <param name="adapter"></param> /// <returns></returns> public ChildGroupPack Remove(ComponentAdapter adapter) { _pack = ChildGroupPack.Read(_groupAdapter); //Debug.Log(string.Format("Reorder: grp:{0}, item:{1}", groupIndex, itemIndex)); // get old group index var oldGroupIndex = _pack.GetGroupHostingAdapterIndex(adapter); // remove adapter from old group _pack.Groups[oldGroupIndex].Remove(adapter); return(_pack); }
// 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; } } }
/// <summary> /// Note: this method actually changes the collections /// </summary> /// <param name="adapter"></param> /// <param name="groupIndex"></param> /// <param name="itemIndex"></param> /// <returns></returns> public ChildGroupPack Reorder(ComponentAdapter adapter, int groupIndex, int itemIndex) { _pack = ChildGroupPack.Read(_groupAdapter); //Debug.Log(string.Format("Reorder: grp:{0}, item:{1}", groupIndex, itemIndex)); // get old group index var oldGroupIndex = _pack.GetGroupHostingAdapterIndex(adapter); // remove adapter from old group _pack.Groups[oldGroupIndex].Remove(adapter); // add adapter to a new group _pack.Groups[groupIndex].Insert(adapter, itemIndex); return(_pack); // (ChildGroupPack)_pack.Clone(); ////Debug.Log("_groupDescriptors.Count: " + _groupDescriptors.Count); ////Debug.Log("groupIndex: " + groupIndex); //ChildGroupDescriptor groupDescriptor = _groupDescriptors[groupIndex]; ////Debug.Log("groupDescriptor: " + groupDescriptor); //List<ComponentAdapter> adaptersCollection = groupDescriptor.GetChildAdaptersCollection(_containerAdapter); ////var targetContainer = groupDescriptor.GetTargetContainer((Container)_containerAdapter.Component); ////Debug.Log("adaptersCollection: " + adaptersCollection); //if (null == adaptersCollection) // return; ///** // * 1. Find the old collection containing the adapter and remove the adapter // * */ //var oldCollection = GetGroupContainingAdapter(adapter); ////Debug.Log("Old collection: " + collection); //oldCollection.Remove(adapter); ///** // * 2. Insert it into a new collection at given index // * */ //if (oldCollection == adaptersCollection) // itemIndex = Math.Max(itemIndex, 0); ////Debug.Log(string.Format("Inserting to : [{0}] at index {1}", adaptersCollection, itemIndex)); //adaptersCollection.Insert(itemIndex, adapter); ////Debug.Log("targetContainer: " + targetContainer); ////Debug.Log("newItemIndex: " + itemIndex); ////Debug.Log("childAdapters[newItemIndex]: " + adaptersCollection[itemIndex]); //if (Application.isPlaying) // Flush(); ////var comp = adaptersCollection[itemIndex].Component; ////if (null != targetContainer && null != comp) //// targetContainer.AddContentChildAt(itemIndex, comp); //// if (_depthMode) //// { //// ContainerAdapter.SetChildDepth(index, adapter); //// } //// else //// { //// ContainerAdapter.Reorder(index, adapter); //// } }