Esempio n. 1
0
        private void AssignToLayer(LayerTreeElement[] elements, LayerTreeElement layer)
        {
            if (layer == null || layer.Type != LayerTreeViewElementType.Layer || elements.Length == 0)
            {
                return;
            }

            foreach (var element in elements)
            {
                if (element.Type == LayerTreeViewElementType.Item)
                {
                    var oldLayer = element.ReParent(layer) as LayerTreeElement;
                    var bh       = element.Item as MonoBehaviour;
                    if (oldLayer != null)
                    {
                        _layers[oldLayer.Name].Remove(bh);
                    }
                    _layers[layer.Name].Add(bh);
                }
            }
            Rebuild();
            ItemsAssigned?.Invoke(layer, elements);
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes a layer using a TreeElement ID used within TreeRoot
        /// </summary>
        /// <param name="id">the id of the layer TreeElement</param>
        /// <remarks>
        /// Cannot delete the last layer, table need at least one layer
        /// Will transfer all items from the deleted layer to the first layer of the table
        /// </remarks>
        public void DeleteLayer(int id)
        {
            var layerItem = TreeRoot.Find(id);

            if (layerItem != null && layerItem.Type == LayerTreeViewElementType.Layer)
            {
                if (_layers.Keys.Count == 1)
                {
                    EditorUtility.DisplayDialog("Visual Pinball", "Cannot delete all layers.", "Close");
                    return;
                }

                if (!EditorUtility.DisplayDialog("Visual Pinball", $"Do you really want to delete layer {layerItem.Name} ?", "Yes", "No"))
                {
                    return;
                }

                // Keep layer's items and put them in the first layer
                var items = layerItem.GetChildren();
                _layers.Remove(layerItem.LayerName);
                if (items.Length > 0)
                {
                    var firstLayer = TreeRoot.GetChildren(e => e.Type == LayerTreeViewElementType.Layer)[0];
                    foreach (var item in items)
                    {
                        item.ReParent(firstLayer);
                    }
                    Rebuild();
                    ItemsAssigned?.Invoke(firstLayer, items);
                }
                else
                {
                    Rebuild();
                }
            }
        }