예제 #1
0
        internal static void PopulateGenericMenu <T>(IPropertyValueEntry <T> entry, GenericMenu genericMenu)
        {
            Color color;

            if (entry.TypeOfValue == typeof(Color))
            {
                color = (Color)(object)entry.SmartValue;
            }
            else
            {
                color = (Color32)(object)entry.SmartValue;
            }

            Color colorInClipboard;
            bool  hasColorInClipboard = ColorExtensions.TryParseString(EditorGUIUtility.systemCopyBuffer, out colorInClipboard);

            if (genericMenu.GetItemCount() > 0)
            {
                genericMenu.AddSeparator("");
            }

            genericMenu.AddItem(new GUIContent("Copy RGBA"), false, () =>
            {
                EditorGUIUtility.systemCopyBuffer = entry.SmartValue.ToString();
            });
            genericMenu.AddItem(new GUIContent("Copy HEX"), false, () =>
            {
                EditorGUIUtility.systemCopyBuffer = "#" + ColorUtility.ToHtmlStringRGBA(color);
            });
            genericMenu.AddItem(new GUIContent("Copy Color Code Declaration"), false, () =>
            {
                EditorGUIUtility.systemCopyBuffer = ColorExtensions.ToCSharpColor(color);
            });

            if (hasColorInClipboard)
            {
                genericMenu.ReplaceOrAdd("Paste", false, () =>
                {
                    entry.Property.Tree.DelayActionUntilRepaint(() =>
                    {
                        SetEntryValue(entry, colorInClipboard);
                    });

                    GUIHelper.RequestRepaint();
                });
            }
            else if (Clipboard.CanPaste(typeof(Color)) || Clipboard.CanPaste(typeof(Color32)))
            {
                genericMenu.ReplaceOrAdd("Paste", false, () =>
                {
                    entry.Property.Tree.DelayActionUntilRepaint(() =>
                    {
                        SetEntryValue(entry, Clipboard.Paste());
                    });

                    GUIHelper.RequestRepaint();
                });
            }
            else
            {
                genericMenu.AddDisabledItem(new GUIContent("Paste"));
            }
        }