Exemple #1
0
        public static ChildGroupRenderingList BuildContentGroups(GroupAdapter groupAdapter)
        {
            //Debug.Log("BuildContentGroups");
            ChildGroupRenderingList childGroupList = new ChildGroupRenderingList();

            var  groupDescriptors = DesignerReflection.GetChildGroupsReferences(groupAdapter);
            bool skipFirst        = false;

            if (groupDescriptors.Count > 0)
            {
                skipFirst = groupDescriptors[0].Attribute.ShowHeader;
            }

            foreach (ChildGroupDescriptor descriptor in groupDescriptors)
            {
                var attr = descriptor.Attribute;

                ChildGroup group;

                if (attr.ShowHeader)
                {
                    Texture iconTexture = null;

                    if (!string.IsNullOrEmpty(attr.Icon))
                    {
                        iconTexture = (Texture)Resources.Load(attr.Icon);
                    }

                    group = new ChildGroup(new GUIContent(attr.Label, iconTexture, attr.Tooltip));
                }
                else
                {
                    group = new ChildGroup();
                }

                List <ComponentAdapter> adapters = Core.Reflection.CoreReflector.GetMemberValue(descriptor.CollectionMemberInfo, groupAdapter) as List <ComponentAdapter>;

                // temp hack
                // ReSharper disable ConvertIfStatementToNullCoalescingExpression
                if (null == adapters)
                // ReSharper restore ConvertIfStatementToNullCoalescingExpression
                {
                    // ReSharper disable AssignNullToNotNullAttribute
                    adapters = new List <ComponentAdapter>(Core.Reflection.CoreReflector.GetMemberValue(descriptor.CollectionMemberInfo, groupAdapter) as ComponentAdapter[]);
                    // ReSharper restore AssignNullToNotNullAttribute
                }

                //Debug.Log("adapters.Count: " + adapters.Count);
                foreach (ComponentAdapter adapter in adapters)
                {
                    //Debug.Log("  -> adapter: " + adapter);
                    if (null != adapter)
                    {
                        var dataObject = new OrderDisplayRow(adapter.ToString(), adapter, new Rect(0, 0, 0, 0))
                        {
                            Color       = (adapter is GroupAdapter) ? Dark : Light,
                            IsContainer = adapter is GroupAdapter
                        };

                        if (skipFirst)
                        {
                            dataObject.YMin = OrderDisplay.ElementHeight;
                        }

                        //Debug.Log("Adding " + dataObject);
                        group.Add(dataObject);
                    }
                }

//                Debug.Log(string.Format(@"***** Group created:
//{0}
//
//", group));
                childGroupList.AddGroup(group);
            }

            //Debug.Log(childGroupList);

            return(childGroupList);
        }
Exemple #2
0
        /// <summary>
        /// Checks the flags and executes the change received via the slots
        /// (the change that is not healthy to do inside the Render method)
        /// </summary>
        public override void Update()
        {
            if (null != _positionChangedParms)
            {
                //Debug.Log(string.Format("PositionChangedSlot: {0}, {1}", parameters[0], parameters[1]));
                DraggableItem draggableItem = (DraggableItem)_positionChangedParms[0];
                int           newItemIndex  = (int)_positionChangedParms[1];
                int           newGroupIndex = (int)_positionChangedParms[2];

                _positionChangedParms = null;

                ComponentAdapter adapter = (ComponentAdapter)draggableItem.Data;

                // Note: this actually applies changes to collections
                var pack = _groupManager.Reorder(adapter, newGroupIndex, newItemIndex);

                ParentChildLinker.Instance.Update(GroupAdapter, pack);

                //Refresh();

                if (Application.isPlaying)
                {
                    //ParentChildLinker.Instance.Update(ContainerAdapter, pack); // TODO: calling ParentChildLinker from here messes the thing
                    RedrawComponentsInGameView(pack);
                }

                //HierarchyState.Instance.Rebuild();
                EditorState.Instance.HierarchyChange();

                /**
                 * Emit for debugging purposes
                 * */
                CollectionChangedSignal.Emit();
            }

            else if (null != _removedParms)
            {
                //Debug.Log(string.Format("RemovedSlot: {0}", parameters[0]));
                DraggableItem draggableItem = (DraggableItem)_removedParms[0];
                //int groupIndex = (int)_removedParms[1];
                //int itemIndex = (int)_removedParms[2];

                _removedParms = null;

                ComponentAdapter adapter = draggableItem.Data as ComponentAdapter;

                if (null == adapter)
                {
                    return;
                }

                //Debug.Log(string.Format("groupIndex: {0}, itemIndex: {1}", groupIndex, itemIndex));

                /**
                 * 1. Remove the adapter from the collection
                 * */
                var pack = _groupManager.Remove(adapter);

                /**
                 * NOTE: We should not call the linker directly
                 * That is because if we remove adapter from stage, the linker could not find it
                 * We call the EditorState.Instance.HierarchyChange() below, so the
                 * hierarchy change mechanism handles the removal stuff
                 * */
                //ParentChildLinker.Instance.Update(GroupAdapter, pack);

                if (Application.isPlaying)
                {
                    RedrawComponentsInGameView(pack);
                }

                if (adapter.transform.parent != GroupAdapter.transform)
                {
                    return;
                }

                //Refresh();

                /**
                 * 2. Check if the same adapter present in other collections
                 * If not, remove the transform
                 * */
                var group = _groupManager.GetGroupContainingAdapter(adapter);
                //Debug.Log("group: " + group);
                if (null == group)
                {
                    // this adapter is not present in any of the groups
                    // remove the transform now
                    OrderDisplayRow orderDisplayRow = (OrderDisplayRow)draggableItem;

                    Transform    transform    = orderDisplayRow.Adapter.transform;
                    GroupAdapter groupAdapter = transform.parent.GetComponent <GroupAdapter>();
                    groupAdapter.RemoveChild(orderDisplayRow.Adapter);

                    //int instanceId = transform.GetInstanceID();
                    Object.DestroyImmediate(transform.gameObject);
                }

                // apply the change, for not to get the "ArgumentException: Getting control 3's position in a group with only 3 controls when doing Repaint Aborting" error
                Refresh();

                //EditorState.Instance.HierarchyChange();

                /**
                 * Emit for debugging purposes
                 * */
                CollectionChangedSignal.Emit();
            }

            if (null != _depthChangedParms)
            {
                //Debug.Log("OrderDisplay: changing depth");
                // apply the change, for not to get the "ArgumentException: Getting control 3's position in a group with only 3 controls when doing Repaint Aborting" error
                //Refresh();

                _depthChangedParms = null;
            }
        }