Beispiel #1
0
        public static void DoDraw(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var propScope = Disposables.PropertyScope(position, label, property)) {
                position.height = SingleLine;
                label           = propScope.content;
                var labelPos = position.Edit(RectEdit.SetWidth(EditorGUIUtility.labelWidth));
                FoCsGUI.Label(labelPos, label);

                using (var scope = Disposables.RectHorizontalScope(6, position.Edit(RectEdit.AddX(labelPos.width), RectEdit.SetWidth(position.width - labelPos.width)))) {
                    using (Disposables.IndentSet(0)) {
                        using (var innerScope = Disposables.RectHorizontalScope(3, scope.GetNext(2))) {
                            FoCsGUI.Label(innerScope.GetNext(), KEY_LABEL);
                            FoCsGUI.PropertyField(innerScope.GetNext(2), property.FindPropertyRelative(KEY), GUIContent.none);
                        }

                        using (var innerScope = Disposables.RectHorizontalScope(5, scope.GetNext(2))) {
                            FoCsGUI.Label(innerScope.GetNext(2), KEY_TYPE_LABEL);
                            FoCsGUI.PropertyField(innerScope.GetNext(3), property.FindPropertyRelative(KEY_TYPE), GUIContent.none);
                        }

                        using (var innerScope = Disposables.RectHorizontalScope(5, scope.GetNext(2))) {
                            var key     = property.GetTargetObjectOfProperty <AnimatorKey>();
                            var typeStr = GetDisplayString(key);
                            FoCsGUI.Label(innerScope.GetNext(2), LABEL);
                            FoCsGUI.PropertyField(innerScope.GetNext(3), property.FindPropertyRelative(typeStr), GUIContent.none);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static eInt DrawDisabledPropertyWithMenu(bool disabled, Rect position, SerProp property, GUICon label, GUICon[] Options, int active, bool autoLabelField = false)
        {
            Action <Rect> draw = rect => {
                using (Disposables.SetIndent(0))
                    PropertyField(rect.Edit(RectEdit.ChangeY(-1), RectEdit.SetHeight(SingleLine)), property, GUICon.none, property.hasVisibleChildren, autoLabelField);
            };

            return(DrawActionWithMenu(disabled, position, draw, label, Options, active));
        }
        /// <summary>
        ///     Gets the next rect in the layout with a size of "amount" elements
        /// </summary>
        /// <param name="amount">How many spaces should this take</param>
        /// <returns>Returns the Next rect, size of "amount" elements</returns>
        public Rect GetNext(int amount, RectEdit rectEdit)
        {
            if ((CurrentIndex == Count) || (CurrentIndex + amount > Count))
            {
                throw new IndexOutOfRangeException("Trying to create a rect, that is no longer in bounds");
            }

            return(GetNext(amount).Edit(rectEdit));
        }
Beispiel #4
0
 private static void DoFieldsDraw(Rect position, SerializedProperty property)
 {
     using (Disposables.LabelSetWidth(LABEL_WIDTH)) {
         using (var scope = Disposables.RectHorizontalScope(2, position)) {
             property.Next(true);
             EditorGUI.PropertyField(scope.GetNext(RectEdit.AddY(1), RectEdit.SubtractHeight(1), RectEdit.SubtractWidth(2)), property, X_Content);
             property.Next(true);
             EditorGUI.PropertyField(scope.GetNext(RectEdit.AddY(1), RectEdit.SubtractHeight(1)), property, Y_Content);
         }
     }
 }
Beispiel #5
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);
                    }
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var showLabel = ShowLabel(label.text);

            using (var propScope = Disposables.PropertyScope(position, label, property)) {
                label = propScope.content;

                if (EditorGUI.indentLevel <= 1)
                {
                    position = position.Edit(RectEdit.ChangeX(16f));
                }

                var axisProp         = property.FindPropertyRelative("Axis");
                var ValueInverted    = new EditorEntry("Invert Result", property.FindPropertyRelative("ValueInverted"));
                var OnlyButtonEvents = new EditorEntry("Only Button Events", property.FindPropertyRelative("OnlyButtonEvents"));
                var UseSmoothInput   = new EditorEntry("Use Smooth Input", property.FindPropertyRelative("UseSmoothInput"));
                var Axis             = new EditorEntry($"Axis: {axisProp.stringValue}", axisProp);

                var value = new EditorEntry($"{(ValueInverted.Property.boolValue? "Non Inverted " : "")}Value",
                                            property.FindPropertyRelative(UseSmoothInput.Property.boolValue? "valueSmooth" : "valueRaw"));

                var deadZone = new EditorEntry("DeadZone", property.FindPropertyRelative("deadZone"));

                using (var horizontalScope = Disposables.RectHorizontalScope(2, position)) {
                    using (Disposables.LabelFieldSetWidth(horizontalScope.FirstRect.width * LABEL_SIZE)) {
                        using (var verticalScope = Disposables.RectVerticalScope(showLabel? 5 : 4, horizontalScope.GetNext())) {
                            if (showLabel)
                            {
                                FoCsGUI.Label(verticalScope.GetNext(RectEdit.SetHeight(SingleLine), RectEdit.SubtractX(16f)), label);
                            }

                            DrawDropDown(Axis, verticalScope.GetNext(RectEdit.SetHeight(SingleLine)));
                            ProgressBar(verticalScope.GetNext(RectEdit.SetHeight(SingleLine)), value);
                            deadZone.Draw(verticalScope.GetNext(RectEdit.SetHeight(SingleLine)));
                            OnlyButtonEvents.Draw(verticalScope.GetNext(RectEdit.SetHeight(SingleLine)));
                        }

                        using (var verticalScope = Disposables.RectVerticalScope(showLabel? 5 : 4, horizontalScope.GetNext(RectEdit.ChangeX(SingleLine)))) {
                            if (showLabel)
                            {
                                verticalScope.GetNext();
                            }

                            Axis.Draw(verticalScope.GetNext(RectEdit.SetHeight(SingleLine)));
                            value.Draw(verticalScope.GetNext(RectEdit.SetHeight(SingleLine)));
                            ValueInverted.Draw(verticalScope.GetNext(RectEdit.SetHeight(SingleLine)));
                            UseSmoothInput.Draw(verticalScope.GetNext(RectEdit.SetHeight(SingleLine)));
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public static Rect Edit(this Rect rect, RectEdit edits, params RectEdit[] editParams)
        {
            var output = new Rect(rect);

            DoEdit(ref output, edits);

            foreach (var pair in editParams)
            {
                DoEdit(ref output, pair);
            }

            return(output);
        }
        /// <summary>
        ///     Gets the next rect in the layout
        /// </summary>
        /// <returns>Next rect</returns>
        public Rect GetNext(RectEdit rectEdit)
        {
            if (CurrentIndex > Count)
            {
                throw new IndexOutOfRangeException("Trying to create a rect, that is no longer in bounds");
            }

            LastRect = NextRect;
            var retVal = NextRect;

            DoNextRect();

            return(retVal.Edit(rectEdit));
        }
        private static void DrawExpanded(Rect position, SerializedProperty property)
        {
            var val = property.quaternionValue;

            using (var cc = Disposables.ChangeCheck()) {
                using (Disposables.SetIndent(0))
                    val.eulerAngles = EditorGUI.Vector3Field(position.Edit(RectEdit.SetHeight(SingleLine), RectEdit.SubtractWidth(2)), GUIContent.none, val.eulerAngles);

                if (cc.changed)
                {
                    property.quaternionValue = val;
                }
            }
        }
Beispiel #10
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var propScope = Disposables.PropertyScope(position, label, property)) {
                label = propScope.content;

                using (Disposables.LabelFieldSetWidth((position.width / GetAttribute.totalAmount) * 0.5f)) {
                    using (var scope = Disposables.RectHorizontalScope(GetAttribute.totalAmount, position)) {
                        for (var i = 0; i < GetAttribute.index; i++)
                        {
                            scope.GetNext();
                        }

                        FoCsGUI.PropertyField(scope.GetNext(RectEdit.SubtractY(SingleLinePlusPadding * GetAttribute.index), RectEdit.SetHeight(SingleLine)), property, label);
                    }
                }
            }
        }
 private static void DrawNormal(Rect position, SerializedProperty property)
 {
     using (Disposables.SetIndent(0)) {
         using (Disposables.LabelSetWidth(LABEL_WIDTH)) {
             using (var scope = Disposables.RectHorizontalScope(4, position)) {
                 property.Next(true);
                 EditorGUI.PropertyField(scope.GetNext(RectEdit.SubtractWidth(2)), property, X_Content);
                 property.Next(true);
                 EditorGUI.PropertyField(scope.GetNext(RectEdit.SubtractWidth(2)), property, Y_Content);
                 property.Next(true);
                 EditorGUI.PropertyField(scope.GetNext(RectEdit.SubtractWidth(2)), property, Z_Content);
                 property.Next(true);
                 EditorGUI.PropertyField(scope.GetNext(RectEdit.SubtractWidth(2)), property, W_Content);
             }
         }
     }
 }
Beispiel #12
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var cc = FoCsEditor.Disposables.ChangeCheck())
            {
                var itemProp   = property.FindPropertyRelative("item");
                var amountProp = property.FindPropertyRelative("amount");

                using (var hScope = FoCsEditor.Disposables.RectHorizontalScope(4, position.Edit(RectEdit.SetHeight(SingleLine))))
                {
                    using (var propScope = FoCsEditor.Disposables.PropertyScope(position, label, property))
                    {
                        if (itemProp.objectReferenceValue == null)
                        {
                            FoCsGUI.Label(hScope.GetNext(), propScope.content);
                        }
                        else
                        {
                            FoCsGUI.Label(hScope.GetNext(RectEdit.ChangeX(16)), propScope.content);
                        }

                        FoCsGUI.PropertyField(hScope.GetNext(2), itemProp);
                        FoCsGUI.PropertyField(hScope.GetNext(), amountProp);
                    }
                }

                if (cc.changed)
                {
                    serializedObject = null;
                }

                if (itemProp.objectReferenceValue == null)
                {
                    return;
                }

                if (serializedObject == null)
                {
                    serializedObject = new SerializedObject(itemProp.objectReferenceValue);
                }
            }

            foldout = DrawReference(position, serializedObject, foldout);
        }
Beispiel #13
0
        private static void DoEdit(ref Rect output, RectEdit pair)
        {
            switch (pair.Type)
            {
            case RectEdit.RectEditType.Add:
                RectEdit.Add(pair, ref output);

                break;

            case RectEdit.RectEditType.Change:
                RectEdit.Change(pair, ref output);

                break;

            case RectEdit.RectEditType.Set:
                RectEdit.Set(pair, ref output);

                break;

            case RectEdit.RectEditType.Multiply:
                RectEdit.Multiply(pair, ref output);

                break;

            case RectEdit.RectEditType.Subtract:
                RectEdit.Subtract(pair, ref output);

                break;

            case RectEdit.RectEditType.Divide:
                RectEdit.Divide(pair, ref output);

                break;

            case RectEdit.RectEditType.Modulo:
                RectEdit.Modulo(pair, ref output);

                break;

            default: throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #14
0
        public static void Draw(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var propScope = Disposables.PropertyScope(position, label, property)) {
                label           = propScope.content;
                position.height = SingleLine;

                if (string.IsNullOrEmpty(label.text))
                {
                    DoFieldsDraw(position, property);
                }
                else
                {
                    EditorGUI.LabelField(position, label);

                    using (Disposables.IndentSet(0)) {
                        var pos = position.Edit(RectEdit.AddX(EditorGUIUtility.labelWidth), RectEdit.SubtractWidth(EditorGUIUtility.labelWidth));
                        DoFieldsDraw(pos, property);
                    }
                }
            }
        }
Beispiel #15
0
        public static eInt DrawActionWithMenu(bool disabled, Rect position, Action <Rect> draw, GUICon label, GUICon[] Options, int active)
        {
            var propRect  = new Rect(position);
            var labelRect = new Rect(position);
            var menuRect  = new Rect(position);

            labelRect     = labelRect.Edit(RectEdit.SubtractY(1), RectEdit.SetWidth(EditorGUIUtility.labelWidth));
            menuRect.xMin = menuRect.xMax - MENU_BUTTON_SIZE;
            menuRect.xMax = position.xMax;
            propRect.xMin = labelRect.xMax;
            propRect.xMax = menuRect.xMin - 2;
            Label(labelRect, label);

            using (Disposables.DisabledScope(disabled))
                draw.Trigger(propRect);

            using (Disposables.SetIndent(0)) {
                var index = EditorGUI.Popup(menuRect, GUICon.none, active, Options, Styles.InLineOptionsMenu);

                return(GUIEvent.Create(position, index));
            }
        }
Beispiel #16
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var propScope = Disposables.PropertyScope(position, label, property)) {
                label = propScope.content;
                var useGlobalSpaceProp = property.FindPropertyRelative("useGlobalSpace");
                var positionsProp      = property.FindPropertyRelative("Positions");
                var useGlobalBoolRect  = position.Edit(RectEdit.SetHeight(SingleLine));
                position = position.Edit(RectEdit.ChangeY(SingleLine));
                EditorGUI.PropertyField(useGlobalBoolRect, useGlobalSpaceProp);
                var targ = property.GetTargetObjectOfProperty <ITDCurve>();

                if (targ.IsFixedLength)
                {
                    if (positionsProp.arraySize != targ.Length)
                    {
                        positionsProp.arraySize = targ.Length;
                    }
                }

                ListNullCheck(property);
                list.HandleDrawing(position.Edit(RectEdit.ChangeX(16)));
            }
        }
Beispiel #17
0
        protected override Rect DoGetNextAmount(int amount, Rect retVal)
        {
            retVal = retVal.Edit(RectEdit.SetHeight(retVal.height * amount));

            return(retVal);
        }
        protected virtual Rect DoGetNextAmount(int amount, Rect retVal)
        {
            retVal = retVal.Edit(RectEdit.SetWidth(retVal.width * amount));

            return(retVal);
        }
Beispiel #19
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();
                }
            }
        }
        private static int DoLessThen4Draw(Rect position, SerializedProperty property, int buttonsIntValue, float labelWidth, int enumLength, bool[] buttonPressed)
        {
            using (var scope = Disposables.RectHorizontalScope(enumLength, position.Edit(RectEdit.SetWidth(position.width - labelWidth), RectEdit.AddX(labelWidth)))) {
                for (var i = 0; i < enumLength; i++)
                {
                    // Check if the button is/was pressed
                    if ((property.intValue & 1 << i) == (1 << i))
                    {
                        buttonPressed[i] = true;
                    }

                    buttonPressed[i] = GUI.Toggle(scope.GetNext(), buttonPressed[i], property.enumNames[i], "Button");

                    if (buttonPressed[i])
                    {
                        buttonsIntValue += 1 << i;
                    }
                }
            }

            return(buttonsIntValue);
        }