private void RefreshSelectionOIDs(IEnumerable <long> oids)
 {
     FieldAttributes.Clear();
     SetProperty(ref _selectedOID, null, () => SelectedOID);
     LayerSelection.Clear();
     lock (_lock)
     {
         foreach (var oid in oids)
         {
             LayerSelection.Add(oid);
         }
     }
 }
Exemplo n.º 2
0
        public void DoLayout(SVGLayer[] layers, LayerSelection layerSelection)
        {
            if (layers == null)
            {
                return;
            }

            float width  = EditorGUIUtility.currentViewWidth - 55f;
            float height = itemHeight * Mathf.Min(layers.Length, maxVisibleItems);

            Rect rect = GUILayoutUtility.GetRect(width, height);

            rect.width = width;
            Rect finRect = new Rect(rect.position.x - rect.width * 0.5f, rect.position.y - itemHeight * 0.5f, rect.width, itemHeight);

            int layersLength = scrollIndex + Mathf.Clamp(layers.Length - scrollIndex, 0, maxVisibleItems);
            int index        = 0;

            if (rect.Contains(Event.current.mousePosition))
            {
                hilightedLayer = Mathf.Clamp(Mathf.FloorToInt((Event.current.mousePosition.y - rect.y) / itemHeight), 0, layers.Length);
                if (Event.current.type == EventType.ScrollWheel)
                {
                    scrollIndex = Mathf.Clamp(scrollIndex + (int)Mathf.Sign(Event.current.delta.y), 0, layers.Length);
                    Event.current.Use();
                }
            }
            else
            {
                hilightedLayer = -1;
            }

            bool selected;
            bool lastSelected;

            for (int i = scrollIndex; i < layersLength; i++)
            {
                finRect.x = rect.x;
                finRect.y = rect.y + index * itemHeight;

                lastSelected = layerSelection.Contains(i);
                selected     = GUI.Toggle(finRect, layerSelection.Contains(i), GUIContent.none);
                if (selected != lastSelected)
                {
                    if (selected)
                    {
                        layerSelection.Add(i);
                    }
                    else
                    {
                        layerSelection.Remove(i);
                    }
                }

                finRect.x += itemHeight;
                GUI.Label(finRect, i + " " + layers[i].name);
                index++;
            }

            if (layers.Length > maxVisibleItems)
            {
                finRect.x      = width + 20;
                finRect.y      = rect.y;
                finRect.width  = 35f;
                finRect.height = rect.height;
                scrollIndex    = Mathf.Clamp((int)GUI.VerticalScrollbar(finRect, scrollIndex, maxVisibleItems, 0f, layers.Length), 0, layers.Length);
            }
            else
            {
                scrollIndex = 0;
            }
        }