예제 #1
0
        void FixTangents()
        {
            if (shapeType == ShapeType.Polygon)
            {
                for (int i = 0; i < GetPolyPointCount(); i++)
                {
                    var pointType = GetPolyPointType(i);
                    switch (pointType)
                    {
                    case ShapePointType.Smooth:

                        Vector3 prevPos     = ShapeVertexInfoUtils.GetPolyVertexInfo(this, i - 1).position;
                        Vector3 thisPoint   = ShapeVertexInfoUtils.GetPolyVertexInfo(this, i).position;
                        Vector3 nextPos     = ShapeVertexInfoUtils.GetPolyVertexInfo(this, i + 1).position;
                        Vector3 normTangent = (prevPos - nextPos).normalized;

                        polyPointInTangents[i]  = normTangent * Vector3.Distance(prevPos, thisPoint) * .33f;
                        polyPointOutTangents[i] = -normTangent *Vector3.Distance(nextPos, thisPoint) * .33f;

                        break;

                    case ShapePointType.BezierContinous:
                        polyPointOutTangents[i] = -polyPointInTangents[i];
                        break;

                    case ShapePointType.Corner:
                        polyPointOutTangents[i] = Vector3.zero;
                        polyPointInTangents[i]  = Vector3.zero;
                        break;
                    }

                    if (!IsStrokeClosed)
                    {
                        if (i == 0)
                        {
                            polyPointInTangents[i] = -polyPointOutTangents[i];
                            continue;
                        }
                        if (i == polyPointPositions.Count - 1)
                        {
                            polyPointOutTangents[i] = -polyPointInTangents[i];
                            continue;
                        }
                    }
                }
            }
        }
예제 #2
0
        public List <ShapeVertexInfo> GetVertexInfoList()
        {
            if (IsDirty)
            {
                FixTangents();

                // read base list
                ShapeVertexInfoUtils.ReadVertexInfoList(this, vertexInfoList);

                // subdivide list
                ShapeVertexInfoUtils.SubdivideVertexInfoList(vertexInfoList, vertexInfoListSubdivided);

                IsDirty = false;
                HashId  = unchecked (HashId + 1);
            }
            return(vertexInfoListSubdivided);
        }
예제 #3
0
    public static void DrawShapeEditor(Shape shape)
    {
        bool newIsPolyColliderGenerated = shape.CreatePolyCollider;

        EditorGUI.BeginChangeCheck();
        newIsPolyColliderGenerated = EditorGUILayout.Toggle("Create Poly Collider", newIsPolyColliderGenerated);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(shape.dataContainerObject, "Edit Shape");

            shape.CreatePolyCollider = newIsPolyColliderGenerated;
            SetDataDirty(shape);
        }

        ShapePolyDimension newPolyDimension = shape.ShapeData.PolyDimension;
        ShapeType          newType          = shape.ShapeData.ShapeType;
        Vector2            newOffset        = shape.ShapeData.ShapeOffset;
        Vector2            newSize          = shape.ShapeData.ShapeSize;
        ShapeAsset         shapeAsset       = shape.ShapeAsset;
        bool newIsPolyClosed = shape.ShapeData.IsPolygonStrokeClosed;


        EditorGUI.BeginChangeCheck();
        GUILayout.Label("Shape", EditorStyles.boldLabel);
        if (shape.ShapeRenderer)
        {
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField("Rendered by", shape.ShapeRenderer, typeof(ShapeRenderer), true);
            EditorGUI.EndDisabledGroup();
        }
        else
        {
            EditorGUILayout.HelpBox("No shape renderer found. This shape will not be rendered until it is parented under a GameObject with a ShapeRenderer component attached, or a ShapeRenderer component is attached to this object", MessageType.Warning);
        }
        shapeAsset = (ShapeAsset)EditorGUILayout.ObjectField("Shape Asset", shapeAsset, typeof(ShapeAsset), false);

        GUILayout.Label("Shape", EditorStyles.boldLabel);
        newType = (ShapeType)EditorGUILayout.EnumPopup("Type", newType);
        if (newType == ShapeType.Polygon)
        {
            newPolyDimension = (ShapePolyDimension)EditorGUILayout.EnumPopup("Dimension", newPolyDimension);
            newIsPolyClosed  = EditorGUILayout.Toggle("Is Closed", newIsPolyClosed);
        }

        if (newType == ShapeType.Circle ||
            newType == ShapeType.Rectangle)
        {
            newOffset = EditorGUILayout.Vector2Field("Offset", newOffset);
            newSize   = EditorGUILayout.Vector2Field("Size", newSize);
        }

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(shape.dataContainerObject, "Edit Shape");

            shape.ShapeAsset = shapeAsset;

            ShapeType oldType = shape.ShapeData.ShapeType;

            if (newType != oldType)
            {
                shape.ShapeData.ShapeType = newType;
                if (newType == ShapeType.Polygon)
                {
                    List <ShapeVertexInfo> vertexList = new List <ShapeVertexInfo>();
                    if (oldType == ShapeType.Circle)
                    {
                        ShapeVertexInfoUtils.GetCircleVertexInfoList(shape.ShapeData, vertexList, 0);
                    }
                    if (oldType == ShapeType.Rectangle)
                    {
                        ShapeVertexInfoUtils.GetRectVertexInfoList(shape.ShapeData, vertexList, 0);
                    }
                    shape.ShapeData.AddFromVertexInfoList(vertexList);
                }
                else if (newType == ShapeType.Circle || newType == ShapeType.Rectangle)
                {
                    if (oldType == ShapeType.Polygon)
                    {
                        Bounds bounds = new Bounds();
                        for (int i = 0; i < shape.ShapeData.GetPolyPointCount(); i++)
                        {
                            Vector3 p = shape.ShapeData.GetPolyPosition(i);
                            if (i == 0)
                            {
                                bounds = new Bounds(p, Vector3.zero);
                            }
                            else
                            {
                                bounds.Encapsulate(p);
                            }
                        }

                        shape.ShapeData.ShapeSize = bounds.size;
                    }
                }
            }

            if (shape.ShapeData.ShapeType != ShapeType.Polygon)
            {
                shape.ShapeData.ClearPolyPoints();
            }

            shape.ShapeData.PolyDimension         = newPolyDimension;
            shape.ShapeData.IsPolygonStrokeClosed = newIsPolyClosed;
            shape.ShapeData.ShapeSize             = newSize;
            shape.ShapeData.ShapeOffset           = newOffset;

            SetDataDirty(shape);
        }
    }