Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var prop = Disposables.PropertyScope(position, label, property)) {
                var owner = GetTargetObject(property);
                FoCsGUI.Label(position.Edit(RectEdit.SetHeight(SingleLine)), prop.content);
                DoDragDrop(position.Edit(RectEdit.MultiplyWidth(0.5f)), property);

                using (Disposables.Indent()) {
                    var Position = property.FindPropertyRelative("Position");
                    var Rotation = property.FindPropertyRelative("Rotation");
                    var Scale    = property.FindPropertyRelative("Scale");

                    using (var horizontalScope =
                               Disposables.RectHorizontalScope(5, position.Edit(RectEdit.SetHeight(SingleLine - 2), RectEdit.DivideWidth(2), RectEdit.AddX(position.width * 0.5f)))) {
                        var copyBtn = FoCsGUI.Button(horizontalScope.GetNext(2), CopyContent);
                        var isType  = CopyPasteUtility.IsTypeInBuffer(owner);
                        FoCsGUI.GUIEventBool pasteBtn;

                        using (Disposables.ColorChanger(isType? GUI.color : Color.red))
                            pasteBtn = FoCsGUI.Button(horizontalScope.GetNext(2), PasteContent);

                        var resetBtn = FoCsGUI.Button(horizontalScope.GetNext(1), ResetContent);

                        if (copyBtn)
                        {
                            CopyPasteUtility.Copy(GetTargetObject(property));
                        }
                        else if (pasteBtn)
                        {
                            var tD = CopyPasteUtility.Paste <TransformData>();
                            Undo.RecordObject(property.serializedObject.targetObject, "Paste TD");
                            Position.vector3Value    = tD.Position;
                            Scale.vector3Value       = tD.Scale;
                            Rotation.quaternionValue = tD.Rotation;
                        }
                        else if (resetBtn)
                        {
                            Undo.RecordObject(property.serializedObject.targetObject, "Reset TD");
                            var tD = TransformData.Empty;
                            Position.vector3Value    = tD.Position;
                            Scale.vector3Value       = tD.Scale;
                            Rotation.quaternionValue = tD.Rotation;
                        }
                    }

                    using (var vertScope = Disposables.RectVerticalScope(3, position.Edit(RectEdit.SetHeight(SingleLine * 3), RectEdit.AddY(SingleLine)))) {
                        Vector3PropEditor.Draw(vertScope.GetNext(), Position, PositionContent);
                        QuaternionPropertyDrawer.Draw(vertScope.GetNext(), Rotation, RotationContent);
                        Vector3PropEditor.Draw(vertScope.GetNext(), Scale, ScaleContent);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void DoDragDrop(Rect pos, SerializedProperty property)
        {
            if (DragAndDrop.objectReferences.IsNullOrEmpty())
            {
                return;
            }

            pos = pos.Edit(RectEdit.SetHeight(SingleLine));
            var @event    = Event.current;
            var obj       = DragAndDrop.objectReferences[0];
            var go        = obj as GameObject;
            var transform = obj as Transform;
            var component = obj as Component;

            if (@event.type == EventType.Repaint)
            {
                if (go || transform || component)
                {
                    using (Disposables.ColorChanger(Color.green))
                        FoCsGUI.Styles.Unity.Box.Draw(pos, false, false, false, false);
                }
                else
                {
                    using (Disposables.ColorChanger(Color.red))
                        FoCsGUI.Styles.Unity.Box.Draw(pos, false, false, false, false);
                }
            }

            if (pos.Contains(@event.mousePosition))
            {
                if ((@event.type == EventType.DragUpdated) || (@event.type == EventType.DragPerform))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (@event.type == EventType.DragPerform)
                    {
                        if (DragAndDrop.objectReferences.IsNullOrEmpty())
                        {
                            return;
                        }

                        var tD = TransformData.Empty;

                        if (go)
                        {
                            tD = new TransformData(go);
                        }
                        else if (transform)
                        {
                            tD = new TransformData(transform);
                        }
                        else if (component)
                        {
                            tD = new TransformData(component);
                        }
                        else
                        {
                            return;
                        }

                        var Position = property.FindPropertyRelative("Position");
                        var Rotation = property.FindPropertyRelative("Rotation");
                        var Scale    = property.FindPropertyRelative("Scale");
                        Position.vector3Value    = tD.Position;
                        Scale.vector3Value       = tD.Scale;
                        Rotation.quaternionValue = tD.Rotation;
                        property.serializedObject.ApplyModifiedProperties();
                        DragAndDrop.AcceptDrag();
                    }

                    @event.Use();
                }
            }
        }
        public static Obj CopyPastObjectButtons(Obj obj)
        {
            var canCopy        = CopyPasteUtility.CanCopy(obj);
            var guiEnableCache = GUI.enabled;
            var copyBuff       = CopyPasteUtility.CopyBuffer;

            if (canCopy)
            {
                var isType = CopyPasteUtility.IsTypeInBuffer(obj, copyBuff);
                FoCsGUI.GUIEventBool pasteEvent;
                GUI.enabled = true;
                var copyEvent = FoCsGUI.Layout.Button(CP_CopyContent, EditorStyles.toolbarButton);
                GUI.enabled = guiEnableCache;

                using (Disposables.ColorChanger(isType? GUI.color : Color.red)) {
                    var pasteContent = new GUIContent("Paste", "Pastes the data.\n" + copyBuff.Substring(0, copyBuff.Length >= 512? 512 : copyBuff.Length));

                    if (!isType)
                    {
                        pasteContent.tooltip = "Warning, this will attempt to paste any fields with the same name.\n" + pasteContent.tooltip;
                    }

                    pasteEvent = FoCsGUI.Layout.Button(pasteContent, EditorStyles.toolbarButton);
                }

                if (copyEvent)
                {
                    CopyPasteUtility.Copy(obj);

                    return(obj);
                }

                if (!pasteEvent)
                {
                    return(obj);
                }

                Undo.RecordObject(obj, "Before Paste Settings");
                CopyPasteUtility.Paste(ref obj, copyBuff, true);

                return(obj);
            }

            var canEditorCopy = CopyPasteUtility.CanEditorCopy(obj);

            if (canEditorCopy)
            {
                var isType = CopyPasteUtility.IsTypeInBuffer(obj, copyBuff);
                FoCsGUI.GUIEventBool pasteEvent;
                GUI.enabled = true;
                var copyEvent = FoCsGUI.Layout.Button(CP_EditorCopyContent, EditorStyles.toolbarButton);
                GUI.enabled = guiEnableCache;

                using (Disposables.ColorChanger(isType? GUI.color : Color.red)) {
                    var pasteContent = new GUIContent("Paste (E)",
                                                      $"Pastes the data. (using the EditorJSONUtility)\n{copyBuff.Substring(0, copyBuff.Length >= 512? 512 : copyBuff.Length)}");

                    if (!isType)
                    {
                        pasteContent.tooltip = "Warning, this will attempt to paste any fields with the same name.\n" + pasteContent.tooltip;
                    }

                    pasteEvent = FoCsGUI.Layout.Button(pasteContent, EditorStyles.toolbarButton);
                }

                if (copyEvent)
                {
                    CopyPasteUtility.EditorCopy(obj);

                    return(obj);
                }

                if (!pasteEvent)
                {
                    return(obj);
                }

                Undo.RecordObject(obj, "Before Paste Settings");
                CopyPasteUtility.EditorPaste(ref obj, copyBuff, true);
            }

            return(obj);
        }