Ejemplo n.º 1
0
        public static Vector3 DrawVector3(GUIContent label, Vector3 vec, Vector3 defaultValue, Obj objectIAmOn)
        {
            //Horizontal Scope
            ////An Indented way of using Unitys Scopes
            using (new GUILayout.HorizontalScope())
            {
                vec = EditorGUILayout.Vector3Field(label, vec);
                var cachedGuiColor = GUI.color;

                var resetContent = new GUIContent("R", "Resets the vector to  " + defaultValue);
                if (GUILayout.Button(resetContent, GUILayout.Width(25)))
                {
                    Undo.RecordObject(objectIAmOn, "Vector 3 Reset");
                    vec = defaultValue;
                }
                var copyContent = new GUIContent("C", "Copies the vectors data.");
                if (GUILayout.Button(copyContent, GUILayout.Width(25)))
                {
                    CopyPasteUtility.EditorCopy(vec);
                }
                var pasteContent = new GUIContent("P", "Pastes the vectors data.");
                if (GUILayout.Button(pasteContent, GUILayout.Width(25)))
                {
                    Undo.RecordObject(objectIAmOn, "Vector 3 Paste");
                    vec = CopyPasteUtility.Paste <Vector3>();
                }
                GUI.color = cachedGuiColor;
            }
            return(vec);
        }
Ejemplo n.º 2
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.º 3
0
        public static Obj CopyPastObjectButtons(Obj obj)
        {
            if (CopyPasteUtility.CanCopy(obj))
            {
                using (new GUILayout.HorizontalScope())
                {
                    var CopyContent = new GUIContent("Copy Data", "Copies the data.");
                    if (GUILayout.Button(CopyContent, EditorStyles.toolbarButton))
                    {
                        CopyPasteUtility.Copy(obj);
                    }
                    var isType = CopyPasteUtility.IsTypeInBuffer(obj);
                    using (new EditorColorChanger(isType? GUI.color : Color.red))
                    {
                        var PasteContent = new GUIContent("Paste Data", "Pastes the data.\n" + CopyPasteUtility.CopyBuffer);

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

                        if (GUILayout.Button(PasteContent, EditorStyles.toolbarButton))
                        {
                            Undo.RecordObject(obj, "Before Paste Settings");
                            CopyPasteUtility.Paste(ref obj);
                        }
                    }
                    return(obj);
                }
            }
            if (CopyPasteUtility.CanEditorCopy(obj))
            {
                using (new GUILayout.HorizontalScope())
                {
                    var CopyContent = new GUIContent("(Editor) Copy Data", "Copies the data.");

                    if (GUILayout.Button(CopyContent, EditorStyles.toolbarButton))
                    {
                        CopyPasteUtility.EditorCopy(obj);
                    }
                    var PasteContent = new GUIContent("(Editor) Paste Data", "Pastes the data.\n" + CopyPasteUtility.CopyBuffer);

                    var isType = CopyPasteUtility.IsTypeInBuffer(obj);
                    using (new EditorColorChanger(isType? GUI.color : Color.red))
                    {
                        if (!isType)
                        {
                            PasteContent.tooltip = "Warning, this will attempt to paste any feilds with the same name.\n" + PasteContent.tooltip;
                        }

                        if (GUILayout.Button(PasteContent, EditorStyles.toolbarButton))
                        {
                            Undo.RecordObject(obj, "Before Paste Settings");
                            CopyPasteUtility.EditorPaste(ref obj);
                        }
                    }
                }
                return(obj);
            }
            return(obj);
        }