示例#1
0
        Tool preEditTool = Tool.None; // the tool the user had selected before clicking edit

        void OnEnable()
        {
            Shape shape = (Shape)serializedObject.targetObject;

            if (!shape.GetComponent <SpriteRenderer>() &&
                !shape.GetComponent <Image>())
            {
                if (shape.GetComponentInParent <Canvas>() == null)
                {
                    Undo.AddComponent <SpriteRenderer>(shape.gameObject);
                }
                else
                {
                    Undo.AddComponent <Image>(shape.gameObject);
                }
                // collapse into the operation that made this happen
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
                shape.Configure();
            }

            shapeTypeProp          = serializedObject.FindProperty("settings._shapeType");
            outlineSizeProp        = serializedObject.FindProperty("settings._outlineSize");
            blurProp               = serializedObject.FindProperty("settings._blur");
            outlineColorProp       = serializedObject.FindProperty("settings._outlineColor");
            roundnessPerCornerProp = serializedObject.FindProperty("settings._roundnessPerCorner");
            roundnessProp          = serializedObject.FindProperty("settings._roundness");
            roundnessTLProp        = serializedObject.FindProperty("settings._roundnessTopLeft");
            roundnessTRProp        = serializedObject.FindProperty("settings._roundnessTopRight");
            roundnessBLProp        = serializedObject.FindProperty("settings._roundnessBottomLeft");
            roundnessBRProp        = serializedObject.FindProperty("settings._roundnessBottomRight");
            innerCutoutProp        = serializedObject.FindProperty("settings._innerCutout");
            startAngleProp         = serializedObject.FindProperty("settings._startAngle");
            endAngleProp           = serializedObject.FindProperty("settings._endAngle");
            invertArcProp          = serializedObject.FindProperty("settings._invertArc");
            fillTypeProp           = serializedObject.FindProperty("settings._fillType");
            fillColorProp          = serializedObject.FindProperty("settings._fillColor");
            fillColor2Prop         = serializedObject.FindProperty("settings._fillColor2");
            fillRotationProp       = serializedObject.FindProperty("settings._fillRotation");
            fillOffsetProp         = serializedObject.FindProperty("settings._fillOffset");
            fillScaleProp          = serializedObject.FindProperty("settings._fillScale");
            gradientTypeProp       = serializedObject.FindProperty("settings._gradientType");
            gradientStartProp      = serializedObject.FindProperty("settings._gradientStart");
            gradientAxisProp       = serializedObject.FindProperty("settings._gradientAxis");
            fillTextureProp        = serializedObject.FindProperty("settings._fillTexture");
            gridSizeProp           = serializedObject.FindProperty("settings._gridSize");
            lineSizeProp           = serializedObject.FindProperty("settings._lineSize");
            triangleOffsetProp     = serializedObject.FindProperty("settings._triangleOffset");
            polygonPresetProp      = serializedObject.FindProperty("settings._polygonPreset");
            usePolygonMapProp      = serializedObject.FindProperty("settings._usePolygonMap");
            pathThicknessProp      = serializedObject.FindProperty("settings._pathThickness");
            fillPathLoopsProp      = serializedObject.FindProperty("settings._fillPathLoops");
        }
示例#2
0
    void Awake()
    {
        shapeSolid.Configure();
        shapeOutline.Configure();

        //generate category widget cache
        for (int i = 0; i < mShapeCategoryWidgetCache.Capacity; i++)
        {
            var inst = Instantiate(categoryWidgetTemplate, cacheRoot);

            inst.dragCallback       += OnCategoryDrag;
            inst.dragEndCallback    += OnCategoryDragEnd;
            inst.dragCancelCallback += OnCategoryDragCancel;

            mShapeCategoryWidgetCache.Add(inst);
        }
        categoryWidgetTemplate.gameObject.SetActive(false);

        //generate measure display caches
        for (int i = 0; i < mAngleWidgetCache.Capacity; i++)
        {
            var angleWidget = Instantiate(angleTemplate, cacheRoot);
            mAngleWidgetCache.Add(angleWidget);
        }

        angleTemplate.gameObject.SetActive(false);

        //generate length display caches
        for (int i = 0; i < mLengthWidgetCache.Capacity; i++)
        {
            var itm = Instantiate(lengthTemplate, cacheRoot);
            mLengthWidgetCache.Add(itm);
        }

        lengthTemplate.gameObject.SetActive(false);

        //generate text cache
        for (int i = 0; i < mTextCache.Capacity; i++)
        {
            var itm = Instantiate(measureTextTemplate, cacheRoot);
            mTextCache.Add(itm);
        }

        measureTextTemplate.gameObject.SetActive(false);
    }
示例#3
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());
            }
        }
示例#4
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());
            }
        }