Пример #1
0
        private void DrawGroup(Rect r, string label, int childCount)
        {
            if (FR2_Setting.GroupMode == Mode.Folder)
            {
                Texture tex = AssetDatabase.GetCachedIcon("Assets");
                GUI.DrawTexture(new Rect(r.x - 2f, r.y - 2f, 16f, 16f), tex);
                r.xMin += 16f;
            }

            GUI.Label(r, label + " (" + childCount + ")", EditorStyles.boldLabel);


            bool hasMouse = Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition);

            if (hasMouse && Event.current.button == 1)
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("Select"), false, () =>
                {
                    string[] ids = groupDrawer.GetChildren(label);
                    FR2_Selection.ClearSelection();
                    for (var i = 0; i < ids.Length; i++)
                    {
                        FR2_Ref rf;
                        if (!refs.TryGetValue(ids[i], out rf))
                        {
                            continue;
                        }

                        FR2_Selection.AppendSelection(rf);
                    }


                    // FR2_Selection.h.Clear();
                    // for (var i = 0; i < ids.Length; i++)
                    // {
                    //     FR2_Selection.h.Add(ids[i]);
                    // }
                });
                menu.AddItem(new GUIContent("Append Selection"), false, () =>
                {
                    string[] ids = groupDrawer.GetChildren(label);
                    for (var i = 0; i < ids.Length; i++)
                    {
                        FR2_Ref rf;
                        if (!refs.TryGetValue(ids[i], out rf))
                        {
                            continue;
                        }

                        FR2_Selection.AppendSelection(rf);
                    }
                });
                menu.AddItem(new GUIContent("Remove From Selection"), false, () =>
                {
                    string[] ids = groupDrawer.GetChildren(label);
                    for (var i = 0; i < ids.Length; i++)
                    {
                        FR2_Ref rf;
                        if (!refs.TryGetValue(ids[i], out rf))
                        {
                            continue;
                        }

                        FR2_Selection.RemoveSelection(rf);
                        // if (FR2_Selection.h.Contains(ids[i]))
                        // {
                        //     FR2_Selection.h.Remove(ids[i]);
                        // }
                    }
                });

                menu.ShowAsContext();
                Event.current.Use();
            }
        }
Пример #2
0
        public void Draw(Rect r, IWindow window)
        {
            bool selected = isSelected();
            var  margin   = 2;
            var  left     = new Rect(r);

            left.width = r.width / 3f;
            var right = new Rect(r);

            right.x    += left.width + margin;
            right.width = r.width * 2f / 3 - margin;

            if (/* FR2_Setting.PingRow && */ Event.current.type == EventType.MouseDown && Event.current.button == 0)
            {
                Rect pingRect = FR2_Setting.PingRow
                                        ? new Rect(0, r.y, r.x + r.width, r.height)
                                        : left;
                if (pingRect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.control || Event.current.command)
                    {
                        if (selected)
                        {
                            FR2_Selection.RemoveSelection(this);
                        }
                        else
                        {
                            FR2_Selection.AppendSelection(this);
                        }

                        if (window != null)
                        {
                            window.Repaint();
                        }
                    }

                    EditorGUIUtility.PingObject(component);
                    //Event.current.Use();
                }
            }


            EditorGUI.ObjectField(left, GUIContent.none, component, typeof(GameObject), true);


            bool   drawPath  = FR2_Setting.GroupMode != FR2_RefDrawer.Mode.Folder;
            float  pathW     = drawPath ? EditorStyles.miniLabel.CalcSize(new GUIContent(scenePath)).x : 0;
            string assetName = component.name;
            // if(usingType!= null && usingType.Count > 0)
            // {
            //  assetName += " -> ";
            //  foreach(var item in usingType)
            //  {
            //      assetName += item + " - ";
            //  }
            //  assetName = assetName.Substring(0, assetName.Length - 3);
            // }
            Color cc = FR2_Cache.Api.setting.SelectedColor;

            var lableRect = new Rect(
                right.x,
                right.y,
                pathW + EditorStyles.boldLabel.CalcSize(new GUIContent(assetName)).x,
                right.height);

            if (selected)
            {
                Color c = GUI.color;
                GUI.color = cc;
                GUI.DrawTexture(lableRect, EditorGUIUtility.whiteTexture);
                GUI.color = c;
            }

            if (drawPath)
            {
                GUI.Label(LeftRect(pathW, ref right), scenePath, EditorStyles.miniLabel);
                right.xMin -= 4f;
                GUI.Label(right, assetName, EditorStyles.boldLabel);
            }
            else
            {
                GUI.Label(right, assetName);
            }


            if (!FR2_Setting.ShowUsedByClassed || usingType == null)
            {
                return;
            }

            float sub = 10;
            var   re  = new Rect(r.x + r.width - sub, r.y, 20, r.height);
            Type  t   = null;

            foreach (string item in usingType)
            {
                string name = item;
                if (!CacheType.TryGetValue(item, out t))
                {
                    t = FR2_Unity.GetType(name);
                    // if (t == null)
                    // {
                    //  continue;
                    // }
                    CacheType.Add(item, t);
                }

                GUIContent content;
                var        width = 0.0f;
                if (!FR2_Asset.cacheImage.TryGetValue(name, out content))
                {
                    if (t == null)
                    {
                        content = new GUIContent(name);
                    }
                    else
                    {
                        Texture text = EditorGUIUtility.ObjectContent(null, t).image;
                        if (text == null)
                        {
                            content = new GUIContent(name);
                        }
                        else
                        {
                            content = new GUIContent(text, name);
                        }
                    }


                    FR2_Asset.cacheImage.Add(name, content);
                }

                if (content.image == null)
                {
                    width = EditorStyles.label.CalcSize(content).x;
                }
                else
                {
                    width = 20;
                }

                re.x    -= width;
                re.width = width;

                GUI.Label(re, content);
                re.x -= margin;                 // margin;
            }


            // var nameW = EditorStyles.boldLabel.CalcSize(new GUIContent(assetName)).x;
        }