예제 #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;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void OnEnable()
        {
            mainWindow    = this;
            gradientField = typeof(EditorGUILayout).GetMethod("GradientField", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new System.Type[] { typeof(GUIContent), typeof(Gradient), typeof(GUILayoutOption[]) }, null);

            Repaint();
        }
예제 #3
0
        public static new void Show()
        {
            PasteBinWindow window = GetWindow <PasteBinWindow>();

            window.titleContent = new GUIContent("Paste Bin");
            window.minSize      = new Vector2(250f, 150f);
            ((EditorWindow)window).Show();
        }
예제 #4
0
 private static void ContextMenuItemCopyObject(MenuCommand command)
 {
     if (command.context)
     {
         PasteBinWindow.AddToClipboard(command.context, Utilities.GetDetailedObjectName(command.context), command.context);
     }
     else
     {
         PasteBinWindow.AddToClipboard(Selection.activeObject, Utilities.GetDetailedObjectName(Selection.activeObject), Selection.activeObject);
     }
 }
예제 #5
0
        public void Initialize(Object[] objects, PasteType pasteType)
        {
            targetProperty = null;
            targetObjects  = objects;
            this.pasteType = pasteType;

            List <SerializedClipboard> clipboardRaw = PasteBinWindow.GetSerializedClipboards();

            for (int i = 0; i < clipboardRaw.Count; i++)
            {
                switch (pasteType)
                {
                case PasteType.Normal:
                    if (!clipboardRaw[i].CanPasteToObject(objects[0]))
                    {
                        continue;
                    }

                    shouldShowSmartPasteButton = true; break;

                case PasteType.ComponentAsNew:
                    if (!clipboardRaw[i].CanPasteAsNewComponent((Component)objects[0]))
                    {
                        continue;
                    }

                    shouldShowSmartPasteButton = true; break;

                case PasteType.CompleteGameObject: if (!clipboardRaw[i].CanPasteCompleteGameObject((GameObject)objects[0]))
                    {
                        continue;
                    }
                    break;

                case PasteType.AssetFiles: if (!clipboardRaw[i].CanPasteAssetFiles(objects))
                    {
                        continue;
                    }
                    break;
                }

                clipboard.Add(clipboardRaw[i]);
                clipboardValues.Add(clipboardRaw[i].RootValue.GetClipboardObject(null));
            }
        }
예제 #6
0
        private static void CopyCompleteGameObject(bool withChildren)
        {
            GameObject[] selectedGameObjects = Selection.GetFiltered <GameObject>(SelectionMode.TopLevel | SelectionMode.ExcludePrefab | SelectionMode.Editable);

            // Sorting selection can be important when all copied objects have the same name because their order will matter for Smart Paste's RelativePath
            System.Array.Sort(selectedGameObjects, (go1, go2) => CompareHierarchySiblingIndices(go1.transform, go2.transform));

            if (selectedGameObjects.Length > 0)
            {
                string label = Utilities.GetDetailedObjectName(selectedGameObjects[0]);
                if (selectedGameObjects.Length > 1)
                {
                    label += " (and " + (selectedGameObjects.Length - 1) + " more)";
                }

                PasteBinWindow.AddToClipboard(new GameObjectHierarchyClipboard(selectedGameObjects, withChildren), label + " (Complete GameObject)", null);
            }
        }
예제 #7
0
        private void RemoveClipboard(object obj)
        {
            int index = (int)obj;

            if (index >= clipboard.Count)
            {
                return;
            }

            PasteBinWindow.RemoveClipboard(clipboard[index]);

            clipboard.RemoveAt(index);
            clipboardValues.RemoveAt(index);

            hoveredClipboardIndex = -1;
            PasteBinTooltip.Hide();

            shouldResizeSelf = true;
            Repaint();
        }
예제 #8
0
        private void OnEnable()
        {
            mainWindow = this;

            EditorApplication.update       -= RefreshClipboardRegularly;
            EditorApplication.update       += RefreshClipboardRegularly;
            EditorSceneManager.sceneOpened -= OnSceneOpened;
            EditorSceneManager.sceneOpened += OnSceneOpened;
            SceneManager.sceneLoaded       -= OnSceneLoaded;
            SceneManager.sceneLoaded       += OnSceneLoaded;

            if (!LoadClipboard())
            {
                // When LoadClipboard returns true, clipboardValues are filled by LoadClipboard automatically
                clipboardValues.Clear();
                for (int i = 0; i < clipboard.Count; i++)
                {
                    clipboardValues.Add(clipboard[i].RootValue.GetClipboardObject(null));
                }
            }

            Repaint();
        }
예제 #9
0
        private static void MenuItemCopyAssetFiles(MenuCommand command)
        {
            // We are using EditorApplication.update to copy all selected asset files in one batch (else-clause)
            if (command.context)
            {
                EditorApplication.update -= CallCopyAssetFilesOnce;
                EditorApplication.update += CallCopyAssetFilesOnce;
            }
            else
            {
                string[] selectedAssets = GetSelectedAssetPaths(false, true);
                if (selectedAssets.Length > 0)
                {
                    string label = selectedAssets[0];
                    if (selectedAssets.Length > 1)
                    {
                        label += " (and " + (selectedAssets.Length - 1) + " more)";
                    }

                    PasteBinWindow.AddToClipboard(new AssetFilesClipboard(selectedAssets), label + " (Asset File)", null);
                }
            }
        }
예제 #10
0
 private void OnDestroy()
 {
     mainWindow = null;
 }
예제 #11
0
        private void OnGUI()
        {
            if (backgroundStyle == null)
            {
                backgroundStyle = new GUIStyle(PasteBinTooltip.Style)
                {
                    margin = new RectOffset(0, 0, 0, 0), padding = new RectOffset(0, 0, 0, 0)
                }
            }
            ;

            Event ev = Event.current;

            Color backgroundColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.Lerp(backgroundColor, new Color(0.5f, 0.5f, 0.5f, 1f), 0.325f);

            GUILayout.BeginVertical(backgroundStyle);

            GUI.backgroundColor = backgroundColor;

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            GUILayout.BeginVertical();

            if (!shouldShowSmartPasteButton)
            {
                GUILayout.Label("Select value to paste:", EditorStyles.boldLabel);
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Select value to paste:", EditorStyles.boldLabel);

                EditorGUI.BeginChangeCheck();
                InspectPlusSettings.Instance.SmartCopyPaste = GUILayout.Toggle(InspectPlusSettings.Instance.SmartCopyPaste, InspectPlusSettings.Instance.SmartCopyPaste ? smartPasteOnButtonLabel : smartPasteOffButtonLabel, GUI.skin.button);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(InspectPlusSettings.Instance);

                    if (targetProperty != null)
                    {
                        // Refresh values
                        Object context = targetProperty.serializedObject.targetObject;
                        for (int i = 0; i < clipboard.Count; i++)
                        {
                            SerializedClipboard.IPObjectType type = clipboard[i].RootType;
                            if (type == SerializedClipboard.IPObjectType.AssetReference || type == SerializedClipboard.IPObjectType.SceneObjectReference)
                            {
                                clipboardValues[i] = clipboard[i].RootValue.GetClipboardObject(context);
                            }
                        }
                    }
                }

                GUILayout.EndHorizontal();
            }

            int hoveredClipboardIndex = -1;

            if (clipboard.Count == 0)
            {
                GUILayout.Label("Nothing to paste here...");
            }
            else
            {
                // Traverse the list in reverse order so that the newest SerializedClipboards will be at the top of the list
                for (int i = clipboard.Count - 1; i >= 0; i--)
                {
                    PasteBinWindow.DrawClipboardOnGUI(clipboard[i], clipboardValues[i], this.hoveredClipboardIndex == i, false);

                    if (hoveredClipboardIndex < 0 && (ev.type == EventType.MouseDown || ev.type == EventType.MouseMove) && GUILayoutUtility.GetLastRect().Contains(ev.mousePosition))
                    {
                        hoveredClipboardIndex = i;
                    }
                }
            }

            if (ev.type == EventType.MouseMove && this.hoveredClipboardIndex != hoveredClipboardIndex)
            {
                OnHoveredClipboardChanged(hoveredClipboardIndex);
            }

            if (ev.type == EventType.MouseDown && hoveredClipboardIndex >= 0)
            {
                int mouseButton = ev.button;
                ev.Use();

                if (mouseButton == 0)
                {
                    PasteClipboard(hoveredClipboardIndex);
                    GUIUtility.ExitGUI();
                }
                else if (mouseButton == 1)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Paste"), false, PasteClipboard, hoveredClipboardIndex);
                    menu.AddItem(new GUIContent("Delete"), false, RemoveClipboard, hoveredClipboardIndex);
                    menu.ShowAsContext();

                    GUIUtility.ExitGUI();
                }
                else
                {
                    RemoveClipboard(hoveredClipboardIndex);
                }
            }

            GUILayout.EndVertical();

            if (shouldRepositionSelf || shouldResizeSelf)
            {
                float preferredHeight = GUILayoutUtility.GetLastRect().height;
                if (preferredHeight > 10f)
                {
                    Vector2 size = new Vector2(position.width, preferredHeight + 15f);

                    if (shouldRepositionSelf)
                    {
                        position = Utilities.GetScreenFittedRect(new Rect(GUIUtility.GUIToScreenPoint(ev.mousePosition) - size * 0.5f, size));
                    }
                    else if (shouldResizeSelf)
                    {
                        position = new Rect(position.position, size);
                    }

                    shouldRepositionSelf = false;
                    shouldResizeSelf     = false;

                    GUIUtility.ExitGUI();
                }
            }

            EditorGUILayout.EndScrollView();
            GUILayout.EndVertical();

            // Make the window draggable
            if (ev.type == EventType.MouseDown)
            {
                prevMousePos = GUIUtility.GUIToScreenPoint(ev.mousePosition);
            }
            else if (ev.type == EventType.MouseDrag && prevMousePos.HasValue)
            {
                Vector2 mousePos  = GUIUtility.GUIToScreenPoint(ev.mousePosition);
                Rect    _position = position;
                _position.position += mousePos - prevMousePos.Value;
                position            = _position;

                prevMousePos = mousePos;
                ev.Use();
            }
            else if (ev.type == EventType.MouseUp)
            {
                prevMousePos = null;
            }
        }
예제 #12
0
 private static void CopyValue(object obj)
 {
     PasteBinWindow.AddToClipboard((SerializedProperty)obj);
 }