public static void OpenTestWindow()
    {
        VectorShapeEditor testWindow = EditorWindow.GetWindow(typeof(VectorShapeEditor)) as VectorShapeEditor;

        testWindow.titleContent.text = "Testing...";

        PointShape testPoint = new PointShape(-2, 0);

        testPoint.colorOutline = Color.black;

        PolyShape testLine = new PolyShape(new Vector2(-1, 0), 0.4f, 4);

        testLine.colorOutline = Color.black;
        for (int i = 0; i < testLine.vertices.Length; i++)
        {
            testLine.vertices[i].segmentCurves = true;
        }
        testLine.closed = false;

        CircleShape testCircle = new CircleShape(new Vector2(0, 0), 0.4f);

        testCircle.colorOutline = Color.black;

        PolyShape testPoly3 = new PolyShape(new Vector2(1, 2), 0.45f, 3);

        testPoly3.colorOutline = Color.black;
        PolyShape testPoly4 = new PolyShape(new Vector2(1, 1), 0.50f, 4);

        testPoly4.colorOutline = Color.black;
        testPoly4.RotateAround(new Vector2(1, 1), 45);
        PolyShape testPoly5 = new PolyShape(new Vector2(1, 0), 0.45f, 5);

        testPoly5.colorOutline = Color.black;
        PolyShape testPoly6 = new PolyShape(new Vector2(1, -1), 0.45f, 6);

        testPoly6.colorOutline = Color.black;
        testPoly6.RotateAround(new Vector2(1, -1), 30);

        PolyShape testShape = new PolyShape(new Vector2(2, 0), 0.4f, 4);

        testShape.colorOutline = Color.black;
        for (int i = 0; i < testShape.vertices.Length; i++)
        {
            testShape.vertices[i].segmentCurves = true;
        }

        testWindow.backgroundColor = Color.white;
        testWindow.Shapes          = new List <VectorShape>()
        {
            testPoint, testLine, testCircle, testPoly3, testPoly4, testPoly5, testPoly6, testShape
        };
        //testWindow.Selection = new List<VectorShape>() { testLine, testShape, testPoly5 };
        testWindow.Focus();
    }
Пример #2
0
    public static void OpenEditor(SerializedShape shape)
    {
        VectorShapeEditor editorWindow = EditorWindow.GetWindow(typeof(VectorShapeEditor)) as VectorShapeEditor;

        if (editorWindow.OnCheckSave())
        {
            editorWindow.targetShape       = shape;
            editorWindow.titleContent.text = shape.name;
            editorWindow.Shapes            = shape.components;
            editorWindow.Focus();
        }
    }
Пример #3
0
    public static void OpenTestWindow()
    {
        VectorShapeEditor testWindow = EditorWindow.GetWindow(typeof(VectorShapeEditor)) as VectorShapeEditor;

        testWindow.titleContent.text = "New Shape";

        EllipseShape testEllipse = new EllipseShape(Vector2.one, 1f, 2f, 22.5f);

        testEllipse.colorOutline = Color.green;
        PolyShape testRect = new PolyShape(testEllipse.ShapeBounds);

        testWindow.Shapes = new List <VectorShape>()
        {
            testEllipse, testRect
        };

        testWindow.Focus();
    }
Пример #4
0
    // Draw the property inside the given rect
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // Using BeginProperty / EndProperty on the parent property means that
        // prefab override logic works on the entire property.
        EditorGUI.BeginProperty(position, label, property);

        // Bail if the ScriptableObject hasn't been initialized
        if (property.objectReferenceValue == null)
        {
            EditorGUI.PropertyField(position, property);
            return;
        }

        // Draw label
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        SerializedObject propertyObject = new SerializedObject(property.objectReferenceValue);

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        // Calculate rects
        Rect shapeSettingsRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
        Rect colorSettingsRect = new Rect(position.x, shapeSettingsRect.yMax + padding, position.width, EditorGUIUtility.singleLineHeight);

        Rect editButtonRect = new Rect(shapeSettingsRect);

        editButtonRect.x     = shapeSettingsRect.xMax - editButtonWidth;
        editButtonRect.width = editButtonWidth;

        //Rect shapeDescriptionRect = new Rect(shapeSettingsRect);
        //shapeDescriptionRect.x = shapeSettingsRect.x;
        //shapeDescriptionRect.xMax = editButtonRect.x - padding;

        //string shapeType = property.objectReferenceValue.GetType().Name;
        //int trimIndex = shapeType.LastIndexOf("Shape");
        //if (trimIndex > 0)
        //{
        //	shapeType = shapeType.Substring(0, trimIndex);
        //}
        //GUIContent shapeLabelContent = new GUIContent(shapeType, "Kind of shape.");

        //GUIStyle rightJustified = new GUIStyle(GUI.skin.label);
        //rightJustified.alignment = TextAnchor.MiddleRight;
        //EditorGUI.LabelField(shapeDescriptionRect, shapeLabelContent, rightJustified);

        if (GUI.Button(editButtonRect, editButtonContent, EditorStyles.miniButton))
        {
            SerializedShape serializedShape = property.objectReferenceValue as SerializedShape;

            VectorShapeEditor.OpenEditor(serializedShape);

            EditorUtility.SetDirty(serializedShape);
        }
        //EditorGUI.PropertyField(shapeSettingsRect, property, GUIContent.none);

        /*
         * // Go right to left so we overflow back into the label space on small windows
         * Rect fillColorRect = new Rect(colorSettingsRect);
         * fillColorRect.width = colorChooserWidth;
         * fillColorRect.x = colorSettingsRect.xMax - fillColorRect.width;
         * Rect fillLabelRect = new Rect(colorSettingsRect);
         * fillLabelRect.width = fillLabelWidth;
         * fillLabelRect.x = fillColorRect.x - fillLabelRect.width - padding;
         *
         * Rect penColorRect = new Rect(colorSettingsRect);
         * penColorRect.width = colorChooserWidth;
         * penColorRect.x = fillLabelRect.x - penColorRect.width - padding;
         * Rect penSizeRect = new Rect(colorSettingsRect);
         * penSizeRect.width = penSizeWidth;
         * penSizeRect.x = penColorRect.x - penSizeRect.width - padding;
         * Rect penLabelRect = new Rect(colorSettingsRect);
         * penLabelRect.width = penLabelWidth;
         * penLabelRect.x = penSizeRect.x - penLabelRect.width;
         *
         * EditorGUI.BeginChangeCheck();
         * EditorGUI.LabelField(penLabelRect, penLabelContent);
         * SerializedProperty penSize = propertyObject.FindProperty("penSize");
         * SerializedProperty colorOutline = propertyObject.FindProperty("colorOutline");
         * EditorGUI.PropertyField(penSizeRect, penSize, GUIContent.none);
         * colorOutline.colorValue = EditorGUI.ColorField(penColorRect, GUIContent.none, colorOutline.colorValue, false, true, false);
         *
         * EditorGUI.LabelField(fillLabelRect, fillLabelContent);
         * SerializedProperty colorFill = propertyObject.FindProperty("colorFill");
         * colorFill.colorValue = EditorGUI.ColorField(fillColorRect, GUIContent.none, colorFill.colorValue, false, true, false);
         *
         * if (EditorGUI.EndChangeCheck() || propertyObject.hasModifiedProperties)
         * {
         *      SerializedProperty shapeDirty = propertyObject.FindProperty("shapeDirty");
         *      if (shapeDirty != null) shapeDirty.boolValue = true;
         *      SerializedProperty meshDirty = propertyObject.FindProperty("meshDirty");
         *      if (meshDirty != null) meshDirty.boolValue = true;
         *
         *      propertyObject.ApplyModifiedProperties();
         *      propertyObject.Update();
         * }
         */

        // Set indent back to what it was
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }
Пример #5
0
    public static void OpenTestWindow()
    {
        VectorShapeEditor testWindow = EditorWindow.GetWindow(typeof(VectorShapeEditor)) as VectorShapeEditor;

        testWindow.titleContent.text = "Testing...";

        /*
         *
         * PointShape testPoint = new PointShape(-2, 0);
         * testPoint.colorOutline = Color.black;
         *
         * PolyShape testLine = new PolyShape(new Vector2(-1, 0), 0.4f, 4);
         * testLine.colorOutline = Color.black;
         * for (int i = 0; i < testLine.vertices.Length; i++)
         * {
         *      testLine.vertices[i].segmentCurves = true;
         * }
         * testLine.closed = false;
         *
         * CircleShape testCircle = new CircleShape(new Vector2(0, 0), 0.4f);
         * testCircle.colorOutline = Color.black;
         *
         * PolyShape testPoly3 = new PolyShape(new Vector2(1, 2), 0.45f, 3);
         * testPoly3.colorOutline = Color.black;
         * PolyShape testPoly4 = new PolyShape(new Vector2(1, 1), 0.50f, 4);
         * testPoly4.colorOutline = Color.black;
         * testPoly4.RotateAround(new Vector2(1, 1), 45);
         * PolyShape testPoly5 = new PolyShape(new Vector2(1, 0), 0.45f, 5);
         * testPoly5.colorOutline = Color.black;
         * PolyShape testPoly6 = new PolyShape(new Vector2(1, -1), 0.45f, 6);
         * testPoly6.colorOutline = Color.black;
         * testPoly6.RotateAround(new Vector2(1, -1), 30);
         *
         * PolyShape testShape = new PolyShape(new Vector2(2, 0), 0.4f, 4);
         * testShape.colorOutline = Color.black;
         * for (int i = 0; i < testShape.vertices.Length; i++)
         * {
         *      testShape.vertices[i].segmentCurves = true;
         * }
         *
         * testWindow.Shapes = new List<VectorShape>() { testPoint, testLine, testCircle, testPoly3, testPoly4, testPoly5, testPoly6, testShape };
         * testWindow.Focus();
         *
         * string tempPath = Application.dataPath + "/test.svg";
         * System.IO.Stream stream = new System.IO.FileStream(tempPath, System.IO.FileMode.OpenOrCreate);
         * VectorShapeSVGExporter exporter = new VectorShapeSVGExporter();
         * Rect bounds = new Rect(-5, -5, 10, 10);
         * exporter.Open(stream, bounds, VectorShapeSVGExporter.Unit.Centimeters);
         * exporter.AddShapeGroup(testWindow.Shapes, "TestGroup");
         * exporter.Close();
         * stream.Close();
         */

        //EllipseShape testEllipse = new EllipseShape(Vector2.zero, 1f, 2f, 22.5f);
        //testEllipse.colorOutline = Color.green;
        //PolyShape testRect = new PolyShape(testEllipse.ShapeBounds);
        //testWindow.Shapes = new List<VectorShape>() { testEllipse, testRect };

        //TextAsset asset = Resources.Load("Flipper_Left_SVG") as TextAsset;
        //testWindow.Shapes = VectorShapeFilesSVG.ReadSVG(new System.IO.StringReader(asset.text));

        //TextAsset asset = Resources.Load("InlineDrop_DXF") as TextAsset;
        //TextAsset asset = Resources.Load("Saucer_DXF") as TextAsset;
        //TextAsset asset = Resources.Load("LaneGuide_1500_DXF") as TextAsset;
        TextAsset asset = Resources.Load("Playfield_DXF") as TextAsset;

        //TextAsset asset = Resources.Load("ThreeTarget_DXF") as TextAsset;
        testWindow.Shapes = VectorShapeFilesDXF.ReadDXF(new System.IO.MemoryStream(asset.bytes));

        testWindow.Focus();
    }