Exemple #1
0
        public void Initialize(SerializedProperty property)
        {
            targetProperty = property;
            targetObjects  = null;
            pasteType      = PasteType.Normal;

            Object context = property.serializedObject.targetObject;
            List <SerializedClipboard> clipboardRaw = PasteBinWindow.GetSerializedClipboards();

            for (int i = 0; i < clipboardRaw.Count; i++)
            {
                object value = clipboardRaw[i].RootValue.GetClipboardObject(context);
                if (targetProperty.CanPasteValue(value, false))
                {
                    clipboard.Add(clipboardRaw[i]);
                    clipboardValues.Add(value);

                    if (!shouldShowSmartPasteButton)
                    {
                        switch (clipboardRaw[i].RootType)
                        {
                        case SerializedClipboard.IPObjectType.Array:
                        case SerializedClipboard.IPObjectType.AssetReference:
                        case SerializedClipboard.IPObjectType.GenericObject:
                        case SerializedClipboard.IPObjectType.ManagedReference:
                        case SerializedClipboard.IPObjectType.SceneObjectReference:
                            shouldShowSmartPasteButton = true;
                            break;
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static void OnPropertyRightClicked(GenericMenu menu, SerializedProperty property)
        {
            Object obj = null;
            bool   isUnityObjectType = false;

            if (property.propertyType == SerializedPropertyType.ExposedReference)
            {
                obj = property.exposedReferenceValue;
                isUnityObjectType = true;
            }
            else if (property.propertyType == SerializedPropertyType.ObjectReference)
            {
                obj = property.objectReferenceValue;
                isUnityObjectType = true;
            }

            if (isUnityObjectType && property.hasMultipleDifferentValues)
            {
                string   propertyPath = property.propertyPath;
                Object[] targets      = property.serializedObject.targetObjects;

                bool containsComponents = false;
                for (int i = 0; i < targets.Length; i++)
                {
                    SerializedProperty _property = new SerializedObject(targets[i]).FindProperty(propertyPath);
                    if (_property.propertyType == SerializedPropertyType.ExposedReference)
                    {
                        targets[i] = _property.exposedReferenceValue;
                        if (targets[i] is Component)
                        {
                            containsComponents = true;
                        }
                    }
                    else if (_property.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        targets[i] = _property.objectReferenceValue;
                        if (targets[i] is Component)
                        {
                            containsComponents = true;
                        }
                    }
                }

                if (containsComponents)
                {
                    menu.AddItem(new GUIContent(NEW_TAB_LABEL + "/All/GameObject"), false, () => InspectPlusWindow.Inspect(PreferablyGameObject(targets), false));
                    menu.AddItem(new GUIContent(NEW_TAB_LABEL + "/All/Component"), false, () => InspectPlusWindow.Inspect(targets, false));
                    menu.AddItem(new GUIContent(NEW_WINDOW_LABEL + "/All/GameObject"), false, () => InspectPlusWindow.Inspect(PreferablyGameObject(targets), true));
                    menu.AddItem(new GUIContent(NEW_WINDOW_LABEL + "/All/Component"), false, () => InspectPlusWindow.Inspect(targets, true));
                }
                else
                {
                    menu.AddItem(new GUIContent(NEW_TAB_LABEL + "/All"), false, () => InspectPlusWindow.Inspect(targets, false));
                    menu.AddItem(new GUIContent(NEW_WINDOW_LABEL + "/All"), false, () => InspectPlusWindow.Inspect(targets, true));
                }

                for (int i = 0; i < targets.Length; i++)
                {
                    if (targets[i])
                    {
                        AddInspectButtonToMenu(menu, targets[i], "/" + targets[i].name);
                    }
                }

                menu.AddSeparator("");
            }
            else if (obj)
            {
                AddInspectButtonToMenu(menu, obj, "");
                menu.AddSeparator("");
            }

            if (!property.hasMultipleDifferentValues && (!isUnityObjectType || obj))
            {
                menu.AddItem(new GUIContent(CONTEXT_COPY_LABEL), false, CopyValue, property.Copy());
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(CONTEXT_COPY_LABEL));
            }

            if (PasteBinWindow.ActiveClipboard == null || !property.CanPasteValue(PasteBinWindow.ActiveClipboard.RootValue, false))
            {
                menu.AddDisabledItem(new GUIContent(CONTEXT_PASTE_LABEL));
            }
            else
            {
                menu.AddItem(new GUIContent(CONTEXT_PASTE_LABEL), false, PasteValue, property.Copy());
            }

            menu.AddItem(new GUIContent(CONTEXT_PASTE_FROM_BIN_LABEL), false, PasteValueFromBin, property.Copy());
        }