void IDefinesGenericMenuItems.PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu)
        {
            if (property.ValueEntry.WeakSmartValue == null)
            {
                return;
            }

            bool isReadOnly = false;

            if (property.ValueEntry.TypeOfValue.IsArray == false)
            {
                for (int i = 0; i < property.ValueEntry.ValueCount; i++)
                {
                    var list = (property.ValueEntry.WeakValues[i] as IList <TElement>);
                    if (list != null && list.IsReadOnly)
                    {
                        isReadOnly = true;
                        break;
                    }
                }
            }

            var  config       = property.Info.GetAttribute <ListDrawerSettingsAttribute>();
            bool isEditable   = isReadOnly == false && property.ValueEntry.IsEditable && (config == null || (!config.IsReadOnlyHasValue) || (config.IsReadOnlyHasValue && config.IsReadOnly == false));
            bool pasteElement = isEditable && Clipboard.CanPaste <TElement>();
            bool clearList    = isEditable && property.Children.Count > 0;

            //if (genericMenu.GetItemCount() > 0 && (pasteElement || clearList))
            //{
            //    genericMenu.AddSeparator(null);
            //}

            if (pasteElement)
            {
                genericMenu.AddItem(new GUIContent("Paste Element"), false, () =>
                {
                    property.ValueEntry.GetListValueEntryChanger().AddListElement(new object[] { Clipboard.Paste <TElement>() }, "PasteItems");
                    GUIHelper.RequestRepaint();
                });
            }

            if (clearList)
            {
                genericMenu.AddItem(new GUIContent("Clear List"), false, () =>
                {
                    property.ValueEntry.GetListValueEntryChanger().ClearList(CHANGE_ID);
                    GUIHelper.RequestRepaint();
                });
            }
            else
            {
                genericMenu.AddDisabledItem(new GUIContent("Clear List"));
            }
        }
Beispiel #2
0
        void IDefinesGenericMenuItems.PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu)
        {
            if (property.ValueEntry.WeakSmartValue == null)
            {
                return;
            }

            var resolver = property.ChildResolver as ICollectionResolver;

            bool isReadOnly = resolver.IsReadOnly;

            var  config       = property.GetAttribute <ListDrawerSettingsAttribute>();
            bool isEditable   = isReadOnly == false && property.ValueEntry.IsEditable && (config == null || (!config.IsReadOnlyHasValue) || (config.IsReadOnlyHasValue && config.IsReadOnly == false));
            bool pasteElement = isEditable && Clipboard.CanPaste(resolver.ElementType);
            bool clearList    = isEditable && property.Children.Count > 0;

            //if (genericMenu.GetItemCount() > 0 && (pasteElement || clearList))
            //{
            //    genericMenu.AddSeparator(null);
            //}

            if (pasteElement)
            {
                genericMenu.AddItem(new GUIContent("Paste Element"), false, () =>
                {
                    (property.ChildResolver as ICollectionResolver).QueueAdd(new object[] { Clipboard.Paste() });
                    GUIHelper.RequestRepaint();
                });
            }

            if (clearList)
            {
                genericMenu.AddItem(new GUIContent("Clear Collection"), false, () =>
                {
                    (property.ChildResolver as ICollectionResolver).QueueClear();
                    GUIHelper.RequestRepaint();
                });
            }
            else
            {
                genericMenu.AddDisabledItem(new GUIContent("Clear Collection"));
            }
        }
Beispiel #3
0
        private void PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu)
        {
            PopulateChangedFromPrefabContext(property, genericMenu);

            if (genericMenu.GetItemCount() > 0)
            {
                genericMenu.AddSeparator("");
            }
            var  objs          = property.ValueEntry.WeakValues.FilterCast <object>().Where(x => x != null).ToArray();
            var  valueToCopy   = (objs == null || objs.Length == 0) ? null : (objs.Length == 1 ? objs[0] : objs);
            bool isUnityObject = property.ValueEntry.BaseValueType.InheritsFrom(typeof(UnityEngine.Object));
            bool hasValue      = valueToCopy != null;
            bool canPaste      = Clipboard.CanPaste(property.ValueEntry.BaseValueType);
            bool isEditable    = property.ValueEntry.IsEditable;
            bool isNullable    =
                (property.ValueEntry.BaseValueType.IsClass || property.ValueEntry.BaseValueType.IsInterface) &&
                property.Info.PropertyType == PropertyType.ReferenceType &&
                (property.ValueEntry.SerializationBackend != SerializationBackend.Unity || isUnityObject);

            //if (canPaste && property.ValueEntry.SerializationBackend != SerializationBackend.Unity && Clipboard.CurrentCopyMode == CopyModes.CopyReference)
            //{
            //    canPaste = false;
            //}

            if (canPaste && isEditable)
            {
                genericMenu.AddItem(new GUIContent("Paste"), false, () =>
                {
                    property.Tree.DelayActionUntilRepaint(() =>
                    {
                        for (int i = 0; i < property.ValueEntry.ValueCount; i++)
                        {
                            property.ValueEntry.WeakValues[i] = Clipboard.Paste();
                        }
                        // Apply happens after the action is invoked in repaint
                        //property.ValueEntry.ApplyChanges();
                        GUIHelper.RequestRepaint();
                    });
                });
            }
            else
            {
                genericMenu.AddDisabledItem(new GUIContent("Paste"));
            }

            if (hasValue)
            {
                if (isUnityObject)
                {
                    genericMenu.AddItem(new GUIContent("Copy"), false, () => Clipboard.Copy(valueToCopy, CopyModes.CopyReference));
                }
                else if (property.ValueEntry.TypeOfValue.IsNullableType() == false)
                {
                    genericMenu.AddItem(new GUIContent("Copy"), false, () => Clipboard.Copy(valueToCopy, CopyModes.CopyReference));
                }
                else if (property.ValueEntry.SerializationBackend == SerializationBackend.Unity)
                {
                    genericMenu.AddItem(new GUIContent("Copy"), false, () => Clipboard.Copy(valueToCopy, CopyModes.DeepCopy));
                }
                else
                {
                    genericMenu.AddItem(new GUIContent("Copy"), false, () => Clipboard.Copy(valueToCopy, CopyModes.DeepCopy));
                    genericMenu.AddItem(new GUIContent("Copy Special/Deep Copy (default)"), false, () => Clipboard.Copy(valueToCopy, CopyModes.DeepCopy));
                    genericMenu.AddItem(new GUIContent("Copy Special/Shallow Copy"), false, () => Clipboard.Copy(valueToCopy, CopyModes.ShallowCopy));
                    genericMenu.AddItem(new GUIContent("Copy Special/Copy Reference"), false, () => Clipboard.Copy(valueToCopy, CopyModes.CopyReference));
                }
            }
            else
            {
                genericMenu.AddDisabledItem(new GUIContent("Copy"));
            }

            if (isNullable)
            {
                genericMenu.AddSeparator("");

                if (hasValue && isEditable)
                {
                    genericMenu.AddItem(new GUIContent("Set To Null"), false, () =>
                    {
                        property.Tree.DelayActionUntilRepaint(() =>
                        {
                            for (int i = 0; i < property.ValueEntry.ValueCount; i++)
                            {
                                property.ValueEntry.WeakValues[i] = null;
                            }
                            // Apply happens after the action is invoked in repaint
                            //property.ValueEntry.ApplyChanges();
                            GUIHelper.RequestRepaint();
                        });
                    });
                }
                else
                {
                    genericMenu.AddDisabledItem(new GUIContent("Set To Null"));
                }
            }
        }
        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"));
            }
        }