Esempio n. 1
0
        private IBrowsable DrawBrowser(List <IBrowsable> allItems, IBrowsable currentItem)
        {
            var selected = default(IBrowsable);
            var columns  = Mathf.FloorToInt((position.width - 28) / Settings.IconSize);

            if (columns > 0)
            {
                var rows  = Mathf.CeilToInt(allItems.Count / (float)columns);
                var index = 0;

                for (var r = 0; r < rows; r++)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    for (var c = 0; c < columns; c++)
                    {
                        if (index < allItems.Count)
                        {
                            var item = allItems[index++];

                            if (item != null)
                            {
                                var rect = DrawIcon(Settings.IconSize, item.GetIcon(), item.GetTitle(), item == currentItem);

                                if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition) == true)
                                {
                                    if (Event.current.button == 0)
                                    {
                                        selected = item;
                                    }
                                    else
                                    {
                                        P3dHelper.SelectAndPing(item.GetObject());
                                    }
                                }
                            }
                            GUILayout.FlexibleSpace();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            return(selected);
        }
        private void DrawTop()
        {
            var toolIcon      = default(Texture2D);
            var toolTitle     = "None";
            var materialIcon  = default(Texture2D);
            var materialTitle = "None";
            var shapeIcon     = default(Texture2D);
            var shapeTitle    = "None";
            var width         = Mathf.FloorToInt((position.width - 30) / 3);

            if (Settings.CurrentTool != null)
            {
                toolIcon  = Settings.CurrentTool.GetIcon();
                toolTitle = Settings.CurrentTool.GetTitle();
            }

            if (Settings.CurrentMaterial != null)
            {
                materialIcon  = Settings.CurrentMaterial.GetIcon();
                materialTitle = Settings.CurrentMaterial.GetTitle();
            }

            if (Settings.CurrentShape != null)
            {
                shapeIcon  = Settings.CurrentShape.GetIcon();
                shapeTitle = Settings.CurrentShape.GetTitle();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginVertical();
            var rectA = DrawIcon(width, toolIcon, toolTitle, Settings.CurrentTool != null, "Tool");

            EditorGUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginVertical();
            var rectB = DrawIcon(width, materialIcon, materialTitle, Settings.CurrentMaterial != null, "Material");

            EditorGUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginVertical();
            var rectC = DrawIcon(width, shapeIcon, shapeTitle, Settings.CurrentShape != null, "Shape");

            EditorGUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (Event.current.type == EventType.MouseDown && rectA.Contains(Event.current.mousePosition) == true)
            {
                if (Event.current.button == 0)
                {
                    selectingTool = true;
                }
                else
                {
                    P3dHelper.SelectAndPing(Settings.CurrentTool);
                }
            }

            if (Event.current.type == EventType.MouseDown && rectB.Contains(Event.current.mousePosition) == true)
            {
                if (Event.current.button == 0)
                {
                    selectingMaterial = true;
                }
                else
                {
                    P3dHelper.SelectAndPing(Settings.CurrentMaterial);
                }
            }

            if (Event.current.type == EventType.MouseDown && rectC.Contains(Event.current.mousePosition) == true)
            {
                if (Event.current.button == 0)
                {
                    selectingShape = true;
                }
                else
                {
                    P3dHelper.SelectAndPing(Settings.CurrentShape);
                }
            }
        }