コード例 #1
0
ファイル: QuickPolygon.cs プロジェクト: dkorobov2/stripes
        public void Reset()
        {
            GetComponent <MeshRenderer>().sharedMaterial = Material;
            GetComponent <MeshFilter>().sharedMesh       = Mesh;

            SquareShape   = new SquareShape();
            CircleShape   = new CircleShape();
            StarShape     = new StarShape();
            DiamondShape  = new DiamondShape();
            TriangleShape = new TriangleShape();
            HexagonShape  = new HexagonShape();
            PentagonShape = new PentagonShape();


            FacingModifier = new FacingModifier();
            StandardBorder = new StandardBorder();

            EmptyFill          = new EmptyFill();
            SingleColorFill    = new SingleColorFill();
            LinearGradientFill = new LinearGradientFill();
            RadialGradientFill = new RadialGradientFill();

            StandardBorder = new StandardBorder();

            ProportionsModifier  = new ProportionsModifier();
            SortingLayerModifier = new SortingLayerModifier();
            PivotModifier        = new PivotModifier();
        }
コード例 #2
0
 public void SnapPivot(float snapRadius)
 {
     // Find a location that is not futher away than the snap radius from the pivot point.
     foreach (PivotSnapLocation pivotSnapLocation in Enum.GetValues(typeof(PivotSnapLocation)))
     {
         if (pivotSnapLocation != PivotSnapLocation.Custom)
         {
             Vector2 snapLocation = PivotModifier.CalculatePivotSnapLocation(pivotSnapLocation);
             if (Vector2.Distance(currentHandleShape.PivotModifier.Pivot, snapLocation) <= snapRadius)
             {
                 for (int i = 0; i < targets.Length; i++)
                 {
                     QuickPolygon shape = (QuickPolygon)targets[i];
                     shape.PivotModifier.Pivot             = snapLocation;
                     shape.PivotModifier.pivotSnapLocation = pivotSnapLocation;
                 }
             }
         }
     }
 }
コード例 #3
0
        private void HandlePivots(SceneView sceneView)
        {
            for (int i = 0; i < targets.Length; i++)
            {
                currentHandleShape = (QuickPolygon)targets[i];
                if (currentHandleShape == null)
                {
                    continue;
                }
                // Handle movement vector is just used to check if the user moved the handle in the last frame.
                Vector3 handlePosition = Handles.FreeMoveHandle(currentHandleShape.transform.position,
                                                                Quaternion.identity, Mathf.Min(currentHandleShape.ProportionsModifier.width,
                                                                                               currentHandleShape.ProportionsModifier.height) * pivotHandleSize, Vector3.zero,
                                                                DrawPivotHandle);
                Vector3 handleMovement = handlePosition - currentHandleShape.transform.position;
                Plane   plane;
                if (targets.Length == 1 && !currentHandleShape.IsCircle())
                {
                    int[] list = currentHandleShape.Shape.uniform && !(currentHandleShape.Shape is StarShape) && currentHandleShape.Shape.roundings[0] <= 1
                                                ? currentHandleShape.Shape.GetData().BorderVertices
                                                : currentHandleShape.Shape.GetData().RoundableVertices;
                    bool rmb  = (Event.current.type == EventType.MouseUp && Event.current.button == 0);
                    bool drag = (Event.current.type == EventType.MouseDrag && Event.current.button == 0);

                    if (drag)
                    {
                        dragging = true;
                    }
                    if (dragging && rmb)
                    {
                        rmb      = false;
                        dragging = false;
                    }

                    if (showRoundingSlider.Length != list.Length)
                    {
                        showRoundingSlider = new bool[list.Length];
                        for (int j = 0; j < showRoundingSlider.Length; j++)
                        {
                            showRoundingSlider[j] = false;
                        }
                    }
                    for (int j = 0; j < list.Length; j++)
                    {
                        Vector3 polygonCenter = currentHandleShape.transform.position - currentHandleShape.ToPivotVector() + currentHandleShape.Shape.GetData().Vertices[0];
                        Vector3 position      = polygonCenter + 0.95f * (-polygonCenter + currentHandleShape.transform.TransformPoint(currentHandleShape.LastData.Vertices[list[j]]));
                        if (rmb)
                        {
                            plane = new Plane(currentHandleShape.transform.forward, currentHandleShape.transform.position);
                            Ray   ray   = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                            float enter = 100.0f;
                            if (plane.Raycast(ray, out enter))
                            {
                                Vector3 mouseWorldPosition = ray.GetPoint(enter);
                                if (Vector3.Distance(mouseWorldPosition, position) < currentHandleShape.GetUniformScale() * 0.1f)
                                {
                                    showRoundingSlider[j] = !showRoundingSlider[j];
                                    EditorUtility.SetDirty(target);
                                }
                            }
                        }
                        Color c = roundingHandleBorderColor;
                        c.a           = showRoundingSlider[j] ? 1 : 0.2f;
                        Handles.color = c;
                        Handles.DrawSolidDisc(position, currentHandleShape.transform.forward, Mathf.Min(currentHandleShape.ProportionsModifier.width, currentHandleShape.ProportionsModifier.height) * 0.05f);
                        c             = roundingHandleFillColor;
                        c.a           = showRoundingSlider[j] ? 1 : 0.0f;
                        Handles.color = c;
                        Handles.DrawSolidDisc(position, currentHandleShape.transform.forward, Mathf.Min(currentHandleShape.ProportionsModifier.width, currentHandleShape.ProportionsModifier.height) * 0.03f);
                    }
                }
                if (GUI.changed && handleMovement.sqrMagnitude > 0.0f)
                {
                    Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    plane = new Plane(currentHandleShape.transform.forward, currentHandleShape.transform.position);
                    float enter = 100.0f;
                    if (plane.Raycast(ray, out enter))
                    {
                        Vector3 pivotWorldPosition = ray.GetPoint(enter);
                        Vector3 pivotLocalPosition = currentHandleShape.transform.InverseTransformPoint(pivotWorldPosition);

                        Undo.RecordObjects(targets, "Pivot Modify");

                        Vector2 pivotNormalized = PivotModifier.CalculatePivotNormalized(pivotLocalPosition,
                                                                                         Helpers.CalculateBounds(currentHandleShape.LastData, currentHandleShape.HaveBorder()));

                        for (int j = 0; j < targets.Length; j++)
                        {
                            QuickPolygon shape = (QuickPolygon)targets[j];
                            shape.PivotModifier.Pivot             = pivotNormalized;
                            shape.PivotModifier.pivotSnapLocation = PivotSnapLocation.Custom;
                        }

                        // Try to snap the pivot if the user is holding control.
                        if (Event.current.control)
                        {
                            SnapPivot(pivotSnapRange);
                        }
                        else
                        {
                            SnapPivot(0.0f);
                        }
                        RefreshTargets();

                        EditorUtility.SetDirty(target);
                    }
                }
            }
        }