Beispiel #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update(); // dunno what this does but it's in the examples?

            Shape shape = (Shape)serializedObject.targetObject;

            EditorGUI.BeginDisabledGroup(!shape.enabled);

            // shape type
            EditorGUILayout.PropertyField(shapeTypeProp);

            ShapeType shapeType = (ShapeType)shapeTypeProp.enumValueIndex;

            if (shapeType == ShapeType.Rectangle)
            {
                // rectangle props
                EditorGUILayout.PropertyField(roundnessPerCornerProp);
                if (shape.settings.roundnessPerCorner)
                {
                    EditorGUILayout.PropertyField(roundnessTLProp);
                    EditorGUILayout.PropertyField(roundnessTRProp);
                    EditorGUILayout.PropertyField(roundnessBLProp);
                    EditorGUILayout.PropertyField(roundnessBRProp);
                }
                else
                {
                    EditorGUILayout.PropertyField(roundnessProp);
                    roundnessTLProp.floatValue = roundnessProp.floatValue;
                    roundnessTRProp.floatValue = roundnessProp.floatValue;
                    roundnessBLProp.floatValue = roundnessProp.floatValue;
                    roundnessBRProp.floatValue = roundnessProp.floatValue;
                }
            }
            else if (shapeType == ShapeType.Ellipse)
            {
                //ellipse props
                EditorGUILayout.PropertyField(startAngleProp);
                EditorGUILayout.PropertyField(endAngleProp);
                EditorGUILayout.PropertyField(invertArcProp);
                EditorGUILayout.PropertyField(innerCutoutProp);
            }
            else if (shapeType == ShapeType.Polygon)
            {
                // polygon props
                EditorGUILayout.PropertyField(polygonPresetProp);
                EditorGUI.BeginDisabledGroup(Selection.objects.Length != 1);
                if (GUILayout.Toggle(isEditingPolygon, "Edit Shape", "Button"))
                {
                    if (!isEditingPolygon)
                    {
                        EditPolygon();
                    }
                }
                else
                {
                    if (isEditingPolygon)
                    {
                        StopEditingPolygon(true);
                    }
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.PropertyField(usePolygonMapProp,
                                              new GUIContent("Optimize rendering (see docs!)"));
            }
            else if (shapeType == ShapeType.Triangle)
            {
                // triangle props
                EditorGUILayout.PropertyField(triangleOffsetProp);
            }

            // common props
            EditorGUILayout.PropertyField(blurProp);
            EditorGUILayout.PropertyField(outlineSizeProp);
            EditorGUILayout.PropertyField(outlineColorProp);

            // fill props
            EditorGUILayout.PropertyField(fillTypeProp);
            FillType fillType = (FillType)fillTypeProp.enumValueIndex;

            if (fillType == FillType.Gradient)
            {
                EditorGUILayout.PropertyField(gradientTypeProp);
                if ((GradientType)gradientTypeProp.enumValueIndex < GradientType.Radial)
                {
                    EditorGUILayout.PropertyField(gradientAxisProp);
                }
                EditorGUILayout.PropertyField(gradientStartProp);
            }
            if (fillType >= FillType.SolidColor && fillType < FillType.Texture)
            {
                EditorGUILayout.PropertyField(fillColorProp);
            }
            if (fillType == FillType.Texture)
            {
                EditorGUILayout.PropertyField(fillTextureProp);
                EditorGUILayout.PropertyField(fillScaleProp);
            }
            if (fillType >= FillType.Gradient && fillType < FillType.Texture)
            {
                EditorGUILayout.PropertyField(fillColor2Prop);
            }
            if (fillType >= FillType.Gradient)
            {
                EditorGUILayout.PropertyField(fillOffsetProp);
                EditorGUILayout.PropertyField(fillRotationProp);
            }
            if (fillType == FillType.Grid || fillType == FillType.Stripes)
            {
                EditorGUILayout.PropertyField(lineSizeProp);
            }
            if (fillType == FillType.Grid || fillType == FillType.Stripes ||
                fillType == FillType.CheckerBoard)
            {
                EditorGUILayout.PropertyField(gridSizeProp);
            }

            EditorGUI.BeginDisabledGroup(Selection.objects.Length != 1);
            if (GUILayout.Button("Convert to Sprite"))
            {
                ConvertToSprite(shape);
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.EndDisabledGroup();

            serializedObject.ApplyModifiedProperties();

            // if the material has been destroyed, configure everything again.
            // or if the shape has been re-enabled after being converted to a sprite,
            // attempt to restore the scale it had previously
            if (shape.enabled && (!shape.IsConfigured() || shape.wasConverted))
            {
                Undo.RecordObjects(shape.GetUndoObjects().ToArray(),
                                   "Re-enable Shapes2D Component");
                shape.Configure();
                if (shape.wasConverted)
                {
                    shape.RestoreFromConversion();
                }
                // combine with the re-enable action
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
            }
        }
Beispiel #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update(); // dunno what this does but it's in the examples?

            Shape shape = (Shape)serializedObject.targetObject;

            EditorGUI.BeginDisabledGroup(!shape.enabled);

            // shape type
            EditorGUILayout.PropertyField(shapeTypeProp);

            ShapeType shapeType = (ShapeType)shapeTypeProp.enumValueIndex;

            if (shapeType == ShapeType.Rectangle)
            {
                // rectangle props
                EditorGUILayout.PropertyField(roundnessPerCornerProp);
                if (shape.settings.roundnessPerCorner)
                {
                    EditorGUILayout.PropertyField(roundnessTLProp);
                    EditorGUILayout.PropertyField(roundnessTRProp);
                    EditorGUILayout.PropertyField(roundnessBLProp);
                    EditorGUILayout.PropertyField(roundnessBRProp);
                }
                else
                {
                    EditorGUILayout.PropertyField(roundnessProp);
                    roundnessTLProp.floatValue = roundnessProp.floatValue;
                    roundnessTRProp.floatValue = roundnessProp.floatValue;
                    roundnessBLProp.floatValue = roundnessProp.floatValue;
                    roundnessBRProp.floatValue = roundnessProp.floatValue;
                }
            }
            else if (shapeType == ShapeType.Ellipse)
            {
                //ellipse props
                EditorGUILayout.PropertyField(startAngleProp);
                EditorGUILayout.PropertyField(endAngleProp);
                EditorGUILayout.PropertyField(invertArcProp);
                EditorGUILayout.PropertyField(innerCutoutProp);
            }
            else if (shapeType == ShapeType.Polygon)
            {
                // polygon props
                EditorGUILayout.PropertyField(polygonPresetProp);
                EditorGUI.BeginDisabledGroup(Selection.objects.Length != 1);
                if (GUILayout.Toggle(isEditing, "Edit Shape", "Button"))
                {
                    if (!isEditing)
                    {
                        EditShape();
                    }
                    GUIStyle helpStyle = new GUIStyle(GUI.skin.label);
                    helpStyle.wordWrap         = true;
                    helpStyle.normal.textColor = Color.green;
                    EditorGUILayout.LabelField("Click on a segment to add a new node (up to 64).\nCtrl-click nodes to delete.\nSee docs about performance!", helpStyle);
                }
                else
                {
                    if (isEditing)
                    {
                        StopEditingShape(true);
                    }
                }
                if (shape.GetComponent <PolygonCollider2D>() && GUILayout.Button("From Polygon Collider 2D"))
                {
                    FromPolygonCollider2D(shape);
                }
                if (GUILayout.Button("Set Polygon Collider 2D"))
                {
                    SetPolygonCollider2D(shape);
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.PropertyField(usePolygonMapProp,
                                              new GUIContent("Optimize rendering (see docs!)"));
            }
            else if (shapeType == ShapeType.Triangle)
            {
                // triangle props
                EditorGUILayout.PropertyField(triangleOffsetProp);
            }
            else if (shapeType == ShapeType.Path)
            {
                EditorGUILayout.PropertyField(pathThicknessProp);
                EditorGUILayout.PropertyField(fillPathLoopsProp);
                EditorGUI.BeginDisabledGroup(Selection.objects.Length != 1);
                if (GUILayout.Toggle(isEditing, "Edit Path", "Button"))
                {
                    if (!isEditing)
                    {
                        EditShape();
                    }
                    GUIStyle helpStyle = new GUIStyle(GUI.skin.label);
                    helpStyle.wordWrap         = true;
                    helpStyle.normal.textColor = Color.green;
                    EditorGUILayout.LabelField("Click to add a new segment (up to 32).\nShift-drag to separate connected nodes or prevent snapping.\nCtrl-click nodes to delete.\nDouble-click a circular node to make it linear.\nSee docs about performance!", helpStyle);
                }
                else
                {
                    if (isEditing)
                    {
                        StopEditingShape(true);
                    }
                }
                if (shape.GetComponent <PolygonCollider2D>() && GUILayout.Button("From Polygon Collider 2D"))
                {
                    FromPolygonCollider2D(shape);
                }
                EditorGUI.EndDisabledGroup();
            }

            // common props
            EditorGUILayout.PropertyField(blurProp);
            EditorGUILayout.PropertyField(outlineSizeProp);
            EditorGUILayout.PropertyField(outlineColorProp);

            // fill props
            EditorGUILayout.PropertyField(fillTypeProp);
            FillType fillType = (FillType)fillTypeProp.enumValueIndex;

            if (fillType == FillType.Gradient)
            {
                EditorGUILayout.PropertyField(gradientTypeProp);
                if ((GradientType)gradientTypeProp.enumValueIndex < GradientType.Radial)
                {
                    EditorGUILayout.PropertyField(gradientAxisProp);
                }
                EditorGUILayout.PropertyField(gradientStartProp);
            }
            if (fillType >= FillType.SolidColor && fillType < FillType.Texture)
            {
                EditorGUILayout.PropertyField(fillColorProp);
            }
            if (fillType == FillType.Texture)
            {
                EditorGUILayout.PropertyField(fillTextureProp);
                EditorGUILayout.PropertyField(fillScaleProp);
            }
            if (fillType >= FillType.Gradient && fillType < FillType.Texture)
            {
                EditorGUILayout.PropertyField(fillColor2Prop);
            }
            if (fillType >= FillType.Gradient)
            {
                EditorGUILayout.PropertyField(fillOffsetProp);
                EditorGUILayout.PropertyField(fillRotationProp);
            }
            if (fillType == FillType.Grid || fillType == FillType.Stripes)
            {
                EditorGUILayout.PropertyField(lineSizeProp);
            }
            if (fillType == FillType.Grid || fillType == FillType.Stripes ||
                fillType == FillType.CheckerBoard)
            {
                EditorGUILayout.PropertyField(gridSizeProp);
            }

            EditorGUI.BeginDisabledGroup(Selection.objects.Length != 1);
            if (GUILayout.Button("Convert to Sprite"))
            {
                ConvertToSprite(shape);
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.EndDisabledGroup();

            serializedObject.ApplyModifiedProperties();

            // if the material has been destroyed, configure everything again.
            // or if the shape has been re-enabled after being converted to a sprite,
            // attempt to restore the scale it had previously
            if (shape.enabled && (!shape.IsConfigured() || shape.wasConverted))
            {
                Undo.RecordObjects(shape.GetUndoObjects().ToArray(),
                                   "Re-enable Shapes2D Component");
                shape.Configure();
                if (shape.wasConverted)
                {
                    shape.RestoreFromConversion();
                }
                // combine with the re-enable action
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
            }
        }