Inheritance: MonoBehaviour
コード例 #1
0
 void Awake()
 {
     if (instance != null)
     {
         Debug.LogError("Singleton AnchorPoint already found...");
         Destroy(gameObject);
     }
     else
     {
         instance = this;
     }
 }
コード例 #2
0
        public Boolean Viewport_MouseMove(Point sceneCoordinates, MouseEventArgs e)
        {
            Boolean needRedraw = false;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (SelectedObject != null)
                {
                    if (leftMouseDown)
                    {
                        double translateX = (sceneCoordinates.X - previousPosition.X);
                        double translateY = (sceneCoordinates.Y - previousPosition.Y);
                        if (SelectedObject is ResizableRectangleElement)
                        {
                            ResizableRectangleElement componentPainter = (ResizableRectangleElement)SelectedObject;
                            componentPainter.Translate(translateX, translateY);
                            AutosarApplication.GetInstance().ActiveComposition.UpdateConnections();
                            needRedraw = true;
                        }
                        else if (SelectedObject is AnchorPoint)
                        {
                            AnchorPoint anchor = (AnchorPoint)SelectedObject;
                            anchor.Move(translateX, translateY);
                            AutosarApplication.GetInstance().ActiveComposition.UpdateConnections();
                            needRedraw = true;
                        }
                        else if (SelectedObject is PortPainter)
                        {
                            PortPainter portPainter = (PortPainter)SelectedObject;
                            TranslatePortPainter(portPainter, sceneCoordinates, translateX, translateY);
                            AutosarApplication.GetInstance().ActiveComposition.UpdateConnections();
                            needRedraw = true;
                        }
                    }
                }
                previousPosition = sceneCoordinates;
            }
            return(needRedraw);
        }
コード例 #3
0
 /// <summary>
 /// Creates and returns a Rect based on the anchor and sizes specified
 /// </summary>
 /// <returns>The rect.</returns>
 /// <param name="anchor">Anchor.</param>
 public static Rect SetupRect(AnchorPoint anchor, float offsetX, float offsetY, float width, float height)
 {
     Rect rect = new Rect();
     if (anchor == AnchorPoint.TopLeft) {
         rect = new Rect(offsetX, offsetY, width, height);
     } else if (anchor == AnchorPoint.TopRight) {
         rect = new Rect(Screen.width - width - offsetX, offsetY, width, height);
     } else if (anchor == AnchorPoint.BottomLeft) {
         rect = new Rect(offsetX, Screen.height - height - offsetY, width, height);
     } else if (anchor == AnchorPoint.BottomRight) {
         rect = new Rect(Screen.width - width - offsetX, Screen.height - height - offsetY, width, height);
     } else if (anchor == AnchorPoint.Top) {
         rect = new Rect(((Screen.width - width) / 2) + offsetX, offsetY, width, height);
     } else if (anchor == AnchorPoint.Bottom) {
         rect = new Rect(((Screen.width - width) / 2) + offsetX, Screen.height - height - offsetY, width, height);
     } else if (anchor == AnchorPoint.Left) {
         rect = new Rect(offsetX, ((Screen.height - height) / 2) + offsetY, width, height);
     } else if (anchor == AnchorPoint.Right) {
         rect = new Rect(Screen.width - width - offsetX, ((Screen.height - height) / 2) + offsetY, width, height);
     }
     return rect;
 }
コード例 #4
0
ファイル: InventoryGUI.cs プロジェクト: MaximeEngel/Imagiro
    public void SelectAnchorPoint()
    {
        RaycastHit hit;
        Vector3    startPosRay = Input.mousePosition;

        if (gameController.VRMode)
        {
            startPosRay.x = Screen.width / 2;
            startPosRay.y = Screen.height / 2;
        }
        if (Physics.Raycast(this.inventoryCamera.ScreenPointToRay(startPosRay), out hit))
        {
            if (hit.collider.GetComponent <AnchorPoint> ())
            {
                AnchorPoint pointedAnchor = hit.collider.GetComponent <AnchorPoint> ();
                if (this.selectedAnchor == null)
                {
                    this.selectedAnchor = pointedAnchor;
                    pointedAnchor.Select();
                    return;
                }
                if (this.selectedAnchor.Equals(pointedAnchor))
                {
                    this.selectedAnchor = null;
                    pointedAnchor.Deselect();
                    return;
                }
                //if (this.selectedAnchor.transform.parent.Equals (pointedAnchor.transform.parent)) {
                if (this.selectedAnchor.GetComponentInParent <RotateByDragging>().Equals(pointedAnchor.GetComponentInParent <RotateByDragging>()))
                {
                    this.selectedAnchor.Deselect();
                    this.selectedAnchor = pointedAnchor;
                    pointedAnchor.Select();
                    return;
                }
                this.ConnectAnchors(pointedAnchor);
            }
        }
    }
コード例 #5
0
        /// <summary>
        ///     Resizes canvas to specified width and height to selected anchor.
        /// </summary>
        /// <param name="width">New width of canvas.</param>
        /// <param name="height">New height of canvas.</param>
        /// <param name="anchor">
        ///     Point that will act as "starting position" of resizing. Use pipe to connect horizontal and
        ///     vertical.
        /// </param>
        public void ResizeCanvas(int width, int height, AnchorPoint anchor, bool addToUndo = true)
        {
            int oldWidth  = Width;
            int oldHeight = Height;

            int offsetX = GetOffsetXForAnchor(Width, width, anchor);
            int offsetY = GetOffsetYForAnchor(Height, height, anchor);

            Thickness[] newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0))
                                     .ToArray();

            object[] processArgs        = { newOffsets, width, height };
            object[] reverseProcessArgs = { Width, Height };

            if (addToUndo)
            {
                StorageBasedChange change = new(this, Layers);
                ResizeCanvas(newOffsets, width, height);

                UndoManager.AddUndoChange(change.ToChange(
                                              RestoreDocumentLayersProcess,
                                              reverseProcessArgs,
                                              ResizeCanvasProcess,
                                              processArgs,
                                              "Resize canvas"));
            }
            else
            {
                ResizeCanvas(newOffsets, width, height);
            }

            if (oldWidth == Width && Height == oldHeight)
            {
                return;
            }

            DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height));
        }
コード例 #6
0
ファイル: YttDocument.cs プロジェクト: Queki/YTSubConverter
        private static int GetJustificationId(AnchorPoint anchorPoint)
        {
            switch (anchorPoint)
            {
            case AnchorPoint.TopLeft:
            case AnchorPoint.MiddleLeft:
            case AnchorPoint.BottomLeft:
                return(0);

            case AnchorPoint.TopCenter:
            case AnchorPoint.Center:
            case AnchorPoint.BottomCenter:
                return(2);

            case AnchorPoint.TopRight:
            case AnchorPoint.MiddleRight:
            case AnchorPoint.BottomRight:
                return(1);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #7
0
    public void SpreadTrackingForceAcrossAnchors()
    {
        if (_amountOfAnchors < 1)
        {
            return;
        }
        if (_anchorsTarget == null)
        {
            return;
        }

        _currentTargetPosition  = _anchorsTarget.position;
        _currrentTargetRotation = _anchorsTarget.rotation;

        for (int i = 0; i < _amountOfAnchors; i++)
        {
            _currrentTrackingAnchor = _anchors [i];
            _currrentPointOfForce   = _currrentTrackingAnchor.pointOfForce.position;

            _currrenTrackingForce =
                ((_currentTargetPosition
                  + (_currrentTargetRotation * _currrentTrackingAnchor.offset))
                 - _currrentPointOfForce).normalized;

            itsRigidbody.AddForceAtPosition
                ((_currrentTrackingAnchor.trackingForce
                  * _trackingForceMultiplier)
                * _currrenTrackingForce,
                _currrentPointOfForce,
                ForceMode.Acceleration);

#if UNITY_EDITOR
            Debug.DrawLine(_currrentPointOfForce,
                           (_currentTargetPosition + (_currrentTargetRotation * _currrentTrackingAnchor.offset)), Color.blue);
#endif
        }
    }
コード例 #8
0
ファイル: Line.cs プロジェクト: stadoblech/Rounded-Corners
    public Ray GetPointOnLine(float t)
    {
        float lineLength = GetLineLength();

        Assert.IsTrue(lineLength > 0, "Line must have some length to get point on it. Probably points are on top of each other.");

        float segmentPercent = 0;
        float totalPercent   = 0;

        AnchorPoint p0 = null;
        AnchorPoint p1 = null;

        int pointsCount = AnchorPoints.Count;

        if (ClosedLine)
        {
            pointsCount++;
        }

        for (int i = 0; i < pointsCount - 1; i++)
        {
            p0 = AnchorPoints[i];
            p1 = AnchorPoints[(i + 1) % AnchorPoints.Count];

            segmentPercent = GetSegmentLength(p0, p1) / lineLength;

            if (totalPercent + segmentPercent > t || Mathf.Approximately(totalPercent + segmentPercent, t))
            {
                break;
            }
            else
            {
                totalPercent += segmentPercent;
            }
        }
        return(GetSegmentNormal(p0, p1, (t - totalPercent) / segmentPercent));
    }
コード例 #9
0
        public void DeleteAnchor(Point closestPoint)
        {
            if (anchors.Count == 0)
            {
                return;
            }

            AnchorPoint closestAnchor = anchors[0];
            double      minDistance   = MathUtility.Distance(closestAnchor.Position, closestPoint);

            for (int i = 1; i < anchors.Count; i++)
            {
                double currDistance = MathUtility.Distance(anchors[i].Position, closestPoint);
                if (currDistance < minDistance)
                {
                    closestAnchor = anchors[i];
                    minDistance   = currDistance;
                }
            }

            anchors.Remove(closestAnchor);

            UpdateLines();
        }
コード例 #10
0
        private void createFighters(List <Entity> list, Transform parent, AnchorPoint side)
        {
            foreach (Entity e in list)
            {
                Transform name   = addText(parent, e.name).rt().Anchor(side).TextAdjustWidth().setName(e.name);
                int       toSide = 10; if (side == AnchorPoint.Right)
                {
                    toSide *= -1;
                }
                switch (parent.childCount)
                {
                case 1: name.rt().Move(toSide, 0);      break;

                case 2: name.rt().Move(toSide, 50);     break;

                case 3: name.rt().Move(toSide, 100);    break;

                case 4: name.rt().Move(toSide, -50);    break;

                case 5: name.rt().Move(toSide, -100);   break;
                }
                e.hp.addTextUpdate(addText(name, e.hp.ToString(), e.name + "HP").bestFit(false).fontSize(-4, true).rt().Anchor(AnchorPoint.BotCenter).Move(0, -10).TextAdjustWidth().setName("Health").text());
            }
        }
コード例 #11
0
ファイル: UIRect.cs プロジェクト: seunghak123/Flaredream
    /// <summary>
    /// Helper function that gets the specified anchor's position relative to the chosen transform.
    /// </summary>

    protected Vector3 GetLocalPos(AnchorPoint ac, Transform trans)
    {
        if (ac.targetCam == null)
        {
            FindCameraFor(ac);
        }
        if (anchorCamera == null || ac.targetCam == null)
        {
            return(cachedTransform.localPosition);
        }

        Rect    rect    = ac.targetCam.rect;
        Vector3 viewPos = ac.targetCam.WorldToViewportPoint(ac.target.position);
        Vector3 pos     = new Vector3((viewPos.x * rect.width) + rect.x, (viewPos.y * rect.height) + rect.y, viewPos.z);

        pos = mCam.ViewportToWorldPoint(pos);
        if (trans != null)
        {
            pos = trans.InverseTransformPoint(pos);
        }
        pos.x = Mathf.Floor(pos.x + 0.5f);
        pos.y = Mathf.Floor(pos.y + 0.5f);
        return(pos);
    }
コード例 #12
0
        /// <summary>
        ///     Resizes canvas to specified width and height to selected anchor.
        /// </summary>
        /// <param name="width">New width of canvas.</param>
        /// <param name="height">New height of canvas.</param>
        /// <param name="anchor">
        ///     Point that will act as "starting position" of resizing. Use pipe to connect horizontal and
        ///     vertical.
        /// </param>
        public void ResizeCanvas(int width, int height, AnchorPoint anchor)
        {
            int oldWidth  = Width;
            int oldHeight = Height;

            int offsetX = GetOffsetXForAnchor(Width, width, anchor);
            int offsetY = GetOffsetYForAnchor(Height, height, anchor);

            Thickness[] oldOffsets = Layers.Select(x => x.Offset).ToArray();
            Thickness[] newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0))
                                     .ToArray();

            object[] processArgs        = { newOffsets, width, height };
            object[] reverseProcessArgs = { oldOffsets, Width, Height };

            ResizeCanvas(newOffsets, width, height);
            UndoManager.AddUndoChange(new Change(
                                          ResizeCanvasProcess,
                                          reverseProcessArgs,
                                          ResizeCanvasProcess,
                                          processArgs,
                                          "Resize canvas"));
            DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height));
        }
コード例 #13
0
    public void DrawEditor()
    {
        widthInVerticies   = (int)EditorGUILayout.Slider(widthInVerticiesTT, widthInVerticies, 1f, 255f);
        heightInVerticies  = (int)EditorGUILayout.Slider(heightInVerticiesTT, heightInVerticies, 1f, 255f);
        widthInWorldUnits  = (int)EditorGUILayout.Slider(widthInWorldUnitsTT, widthInWorldUnits, 1f, 128f);
        heightInWorldUnits = (int)EditorGUILayout.Slider(heightInWorldUnitsTT, heightInWorldUnits, 1f, 128f);

        addCollider    = (bool)EditorGUILayout.Toggle("Add a Collider", addCollider);
        twoSided       = (bool)EditorGUILayout.Toggle("Make the Mesh two sided", twoSided);
        createAtOrigin = (bool)EditorGUILayout.Toggle("Create Mesh at the Origin", createAtOrigin);

        orientation = (Orientation)EditorGUILayout.EnumPopup("Mesh Orientation", orientation);
        anchor      = (AnchorPoint)EditorGUILayout.EnumPopup("Mesh Anchor Point", anchor);

        optionalName = (string)EditorGUILayout.TextField("Mesh Name", optionalName);

        bool buttonTest = GUILayout.Button("Create Mesh");

        if (buttonTest)
        {
            HexLatticeMesh.GetCamera();
            this.CreateMesh();
        }
    }
コード例 #14
0
ファイル: UIRect.cs プロジェクト: Henry-T/UnityPG
	/// <summary>
	/// Helper function -- attempt to find the camera responsible for the specified anchor.
	/// </summary>

	void FindCameraFor (AnchorPoint ap)
	{
		// If we don't have a target or have a rectangle to work with, camera isn't needed
		if (ap.target == null || ap.rect != null)
		{
			ap.cam = null;
			mAnchorCam = null;
		}
		else
		{
			// Find the camera responsible for the target object
			ap.cam = NGUITools.FindCameraForLayer(ap.target.gameObject.layer);

			// No camera found? Clear the references
			if (ap.cam == null)
			{
				ap.target = null;
				mAnchorCam = null;
				return;
			}
			
			// Find the camera responsible for this rectangle
			if (mAnchorCam == null)
			{
				mAnchorCam = NGUITools.FindCameraForLayer(cachedGameObject.layer);

				// No camera found? Clear the references
				if (mAnchorCam == null)
				{
					ap.target = null;
					ap.cam = null;
				}
			}
		}
	}
コード例 #15
0
ファイル: UIRect.cs プロジェクト: zhang00lei/2048
	/// <summary>
	/// Helper function -- attempt to find the camera responsible for the specified anchor.
	/// </summary>

	void FindCameraFor (AnchorPoint ap)
	{
		// If we don't have a target or have a rectangle to work with, camera isn't needed
		if (ap.target == null || ap.rect != null)
		{
			ap.targetCam = null;
		}
		else
		{
			// Find the camera responsible for the target object
			ap.targetCam = NGUITools.FindCameraForLayer(ap.target.gameObject.layer);
		}
	}
コード例 #16
0
ファイル: Anchorable.cs プロジェクト: wtrebella/Grappler
	private void Awake() {
		rigid = GetComponent<Rigidbody2D>();
		anchorPoint = GetComponentInChildren<AnchorPoint>();
		anchorableID = currentAnchorableID++;
		WhitTools.Assert(anchorPoint != null, "object has no anchor point!");
	}
コード例 #17
0
 public static bool IsLeftAligned(AnchorPoint anchorPoint)
 {
     return(anchorPoint == AnchorPoint.TopLeft ||
            anchorPoint == AnchorPoint.MiddleLeft ||
            anchorPoint == AnchorPoint.BottomLeft);
 }
コード例 #18
0
ファイル: Placement.cs プロジェクト: borkaborka/gmit
 /// <summary>Creates a frozen <see cref="Placement"/> instance from the given parameters.</summary>
 public static Placement CreateFrozen(DockPosition dock, AnchorPoint anchor) {
    var p = new Placement { Dock = dock, Anchor = anchor };
    p.Freeze();
    return p;
 }
コード例 #19
0
ファイル: Renderer.cs プロジェクト: Thunderchen/CavemanRunner
 public void Initialize(GameObject owner, AnchorPoint anchor)
 {
     this.gameObject = owner;
     animations = new Dictionary<string, Animation>();
     SetAnchorPoint(anchor);
 }
コード例 #20
0
 public AnchorPoint(AnchorPoint previousPoint = null, AnchorPoint nextPoint = null)
 {
     PreviousPoint = previousPoint;
     NextPoint     = nextPoint;
     PointType     = PointType.None;
 }
コード例 #21
0
ファイル: Fx.cs プロジェクト: shalves/Ext.NET.Community
 public static string AnchorConvert(AnchorPoint anchor)
 {
     switch (anchor)
     {
         case AnchorPoint.TopLeft:
             return "tl";
         case AnchorPoint.Top:
             return "t";
         case AnchorPoint.TopRight:
             return "tr";
         case AnchorPoint.Left:
             return "l";
         case AnchorPoint.Center:
             return "c";
         case AnchorPoint.Right:
             return "r";
         case AnchorPoint.BottomLeft:
             return "bl";
         case AnchorPoint.Bottom:
             return "b";
         case AnchorPoint.BottomRight:
             return "br";
         default:
             throw new ArgumentOutOfRangeException("anchor");
     }
 }
コード例 #22
0
ファイル: Overlay.cs プロジェクト: alanoliveira/garou-toremo
 private void DrawShadedText(Graphics gfx, Font font, float fontSize, IBrush brush, IBrush shade, float shadeSize, float x, float y, AnchorPoint anchor, string text)
 {
     if (anchor == AnchorPoint.RIGHT)
     {
         Point directionalStringSize = gfx.MeasureString(font, fontSize, text);
         x = gfx.Width - x - directionalStringSize.X;
     }
     gfx.DrawText(font, fontSize, shade, x + shadeSize, y, text);
     gfx.DrawText(font, fontSize, shade, x - shadeSize, y, text);
     gfx.DrawText(font, fontSize, shade, x, y + shadeSize, text);
     gfx.DrawText(font, fontSize, shade, x, y - shadeSize, text);
     gfx.DrawText(font, fontSize, brush, x, y, text);
 }
        internal static AnchorPattern Ancorare(int index)
        {
            AnchorPattern ap = new AnchorPattern();
            AnchorPoint   apo1, apo2, apo3;

            if (index == 0) //AND
            {
                apo1 = new AnchorPoint(0, 25, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(0, 57, true, false, MarkStyle.Circle, Color.Blue);
                apo3 = new AnchorPoint(89, 42, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                ap.Points.Add(apo3);
                return(ap);
            }
            else if (index == 1) //OR
            {
                apo1 = new AnchorPoint(0, 27, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(0, 59, true, false, MarkStyle.Circle, Color.Blue);
                apo3 = new AnchorPoint(89, 44, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                ap.Points.Add(apo3);
                return(ap);
            }
            else if (index == 2) //XOR
            {
                apo1 = new AnchorPoint(0, 27, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(0, 59, true, false, MarkStyle.Circle, Color.Blue);
                apo3 = new AnchorPoint(89, 44, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                ap.Points.Add(apo3);
                return(ap);
            }
            else if (index == 3) //NOT
            {
                apo1 = new AnchorPoint(0, 45, true, false, MarkStyle.Circle, Color.Blue);
                apo2 = new AnchorPoint(89, 45, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                ap.Points.Add(apo2);
                return(ap);
            }
            else if (index == 4) //INPUT 0
            {
                apo1 = new AnchorPoint(89, 43, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                return(ap);
            }
            else if (index == 5) //INPUT 1
            {
                apo1 = new AnchorPoint(89, 43, false, true, MarkStyle.Circle, Color.Green);

                ap.Points.Add(apo1);
                return(ap);
            }
            else if (index == 6) //OUTPUT (terminator)
            {
                apo1 = new AnchorPoint(0, 43, true, false, MarkStyle.Circle, Color.Blue);

                ap.Points.Add(apo1);
                return(ap);
            }
            else
            {
                return(null);
            }
        }
コード例 #24
0
        internal static void DrawDots(DrawingContext drawingContext, DotTypes types, Point p, AnchorPoint anchor, bool selected)
        {
            int gridSize = Configurations.DotGridSize;
            int cellSize = gridSize / 3; //3x3 grid
            Size rectSize = new Size(2, 2);
            Rect rect = new Rect();
            p.X = (int)p.X;
            p.Y = (int)p.Y;
            Point pt = p;

            switch (anchor)
            {
                case AnchorPoint.TopLeft:
                    break;
                case AnchorPoint.TopRight:
                    p.X -= gridSize;
                    break;
                case AnchorPoint.BottomLeft:
                    p.Y -= gridSize;
                    break;
                case AnchorPoint.BottomRight:
                    p.X -= gridSize;
                    p.Y -= gridSize;
                    break;
                default:
                    throw new InvalidOperationException();
            }

            if (types.HasFlag(DotTypes.TopLeft))
            {
                pt = p;
                pt.Offset(0, 0);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.Top))
            {
                pt = p;
                pt.Offset(cellSize, 0);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.TopRight))
            {
                pt = p;
                pt.Offset(2 * cellSize, 0);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.MiddleLeft))
            {
                pt = p;
                pt.Offset(0, cellSize);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.Middle))
            {
                pt = p;
                pt.Offset(0, cellSize);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.MiddleRight))
            {
                pt = p;
                pt.Offset(2 * cellSize, cellSize);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.BottomLeft))
            {
                pt = p;
                pt.Offset(0, 2 * cellSize);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.Bottom))
            {
                pt = p;
                pt.Offset(cellSize, 2 * cellSize);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }

            if (types.HasFlag(DotTypes.BottomRight))
            {
                pt = p;
                pt.Offset(2 * cellSize, 2 * cellSize);
                rect = new Rect(pt, rectSize);
                DrawSmallDots(drawingContext, selected, rect);
            }
            return;
        }
コード例 #25
0
ファイル: Tile.cs プロジェクト: divisiondeariza/mapa-de-calor
 public static Tile CreateTileTemplate(AnchorPoint anchorPoint)
 {
     return(CreateTileTemplate("[Tile Template]", anchorPoint));
 }
コード例 #26
0
 /// <summary>
 /// Determines how to anchor the image when padding or cropping
 /// </summary>
 /// <param name="anchorPoint">The position of the anchor point</param>
 /// <returns></returns>
 public ResizeExpression Anchor(AnchorPoint anchorPoint)
 {
     builder.SetParameter(AlignmentCommands.Anchor, anchorPoint.ToString().ToLowerInvariant());
     return this;
 }
コード例 #27
0
ファイル: Tile.cs プロジェクト: divisiondeariza/mapa-de-calor
        public static Tile CreateTileTemplate(string tileName, AnchorPoint anchorPoint)
        {
            GameObject   tileTemplate = new GameObject(tileName);
            Tile         tile         = tileTemplate.AddComponent <Tile>();
            MeshFilter   meshFilter   = tileTemplate.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = tileTemplate.AddComponent <MeshRenderer>();
            BoxCollider  boxCollider  = tileTemplate.AddComponent <BoxCollider>();



            // add the geometry
            Mesh mesh = meshFilter.mesh;

            switch (anchorPoint)
            {
            case AnchorPoint.TopLeft:
                mesh.vertices = new Vector3[] {
                    new Vector3(1.0f, 0.0f, 0.0f),
                    new Vector3(1.0f, 0.0f, -1.0f),
                    new Vector3(0.0f, 0.0f, -1.0f),
                    new Vector3(0.0f, 0.0f, 0.0f)
                };
                break;

            case AnchorPoint.TopCenter:
                mesh.vertices = new Vector3[] {
                    new Vector3(0.5f, 0.0f, 0.0f),
                    new Vector3(0.5f, 0.0f, -1.0f),
                    new Vector3(-0.5f, 0.0f, -1.0f),
                    new Vector3(-0.5f, 0.0f, 0.0f)
                };
                break;

            case AnchorPoint.TopRight:
                mesh.vertices = new Vector3[] {
                    new Vector3(0.0f, 0.0f, 0.0f),
                    new Vector3(0.0f, 0.0f, -1.0f),
                    new Vector3(-1.0f, 0.0f, -1.0f),
                    new Vector3(-1.0f, 0.0f, 0.0f)
                };
                break;

            case AnchorPoint.MiddleLeft:
                mesh.vertices = new Vector3[] {
                    new Vector3(1.0f, 0.0f, 0.5f),
                    new Vector3(1.0f, 0.0f, -0.5f),
                    new Vector3(0.0f, 0.0f, -0.5f),
                    new Vector3(0.0f, 0.0f, 0.5f)
                };
                break;

            case AnchorPoint.MiddleRight:
                mesh.vertices = new Vector3[] {
                    new Vector3(0.0f, 0.0f, 0.5f),
                    new Vector3(0.0f, 0.0f, -0.5f),
                    new Vector3(-1.0f, 0.0f, -0.5f),
                    new Vector3(-1.0f, 0.0f, 0.5f)
                };
                break;

            case AnchorPoint.BottomLeft:
                mesh.vertices = new Vector3[] {
                    new Vector3(1.0f, 0.0f, 1.0f),
                    new Vector3(1.0f, 0.0f, 0.0f),
                    new Vector3(0.0f, 0.0f, 0.0f),
                    new Vector3(0.0f, 0.0f, 1.0f)
                };
                break;

            case AnchorPoint.BottomCenter:
                mesh.vertices = new Vector3[] {
                    new Vector3(0.5f, 0.0f, 1.0f),
                    new Vector3(0.5f, 0.0f, 0.0f),
                    new Vector3(-0.5f, 0.0f, 0.0f),
                    new Vector3(-0.5f, 0.0f, 1.0f)
                };
                break;

            case AnchorPoint.BottomRight:
                mesh.vertices = new Vector3[] {
                    new Vector3(0.0f, 0.0f, 1.0f),
                    new Vector3(0.0f, 0.0f, 0.0f),
                    new Vector3(-1.0f, 0.0f, 0.0f),
                    new Vector3(-1.0f, 0.0f, 1.0f)
                };
                break;

            default:     // MiddleCenter
                mesh.vertices = new Vector3[] {
                    new Vector3(0.5f, 0.0f, 0.5f),
                    new Vector3(0.5f, 0.0f, -0.5f),
                    new Vector3(-0.5f, 0.0f, -0.5f),
                    new Vector3(-0.5f, 0.0f, 0.5f)
                };
                break;
            }
            mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3 };

            // add normals
            mesh.normals = new Vector3[] { Vector3.up, Vector3.up, Vector3.up, Vector3.up };
            // add uv coordinates
            mesh.uv = new Vector2[] { new Vector2(1.0f, 1.0f), new Vector2(1.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(0.0f, 1.0f) };

            // add a material
            string shaderName = "Somian/Unlit/Transparent";
            Shader shader     = Shader.Find(shaderName);

#if DEBUG_LOG
            Debug.Log("DEBUG: shader for tile template: " + shaderName + ", exists: " + (shader != null));
#endif

            tile.material = meshRenderer.material = new Material(shader);

            // setup the collider
            boxCollider.size = new Vector3(1.0f, 0.0f, 1.0f);
            //boxCollider.size = new Vector3(1.0f, 0.5f, 1.0f);
            boxCollider.center = new Vector3(0.0f, 0.0f, 0.5f);

            return(tile);
        }
コード例 #28
0
 public static bool IsRightAligned(AnchorPoint anchorPoint)
 {
     return(anchorPoint == AnchorPoint.TopRight ||
            anchorPoint == AnchorPoint.MiddleRight ||
            anchorPoint == AnchorPoint.BottomRight);
 }
コード例 #29
0
ファイル: Renderer.cs プロジェクト: Thunderchen/CavemanRunner
        public void SetAnchorPoint(AnchorPoint anchor)
        {
            anchorPoint = anchor;

               if (anchorPoint == AnchorPoint.Center)
               renderOffset = new Vector2((float)gameObject.collider.Bounds.Width / 2, (float)gameObject.collider.Bounds.Height / 2);
               else if (anchorPoint == AnchorPoint.TopLeft)
               renderOffset = Vector2.Zero;
               else if (anchorPoint == AnchorPoint.BottomMiddle)
               renderOffset = new Vector2((float)gameObject.collider.Bounds.Width / 2, gameObject.collider.Bounds.Height);
        }
コード例 #30
0
 public static bool IsMiddleAligned(AnchorPoint anchorPoint)
 {
     return(anchorPoint == AnchorPoint.MiddleLeft ||
            anchorPoint == AnchorPoint.Center ||
            anchorPoint == AnchorPoint.MiddleRight);
 }
コード例 #31
0
ファイル: GPOS.Others.cs プロジェクト: cs-phillips/PixelFarm
            public static AnchorPoint CreateFrom(BinaryReader reader, long beginAt)
            {
                AnchorPoint anchorPoint = new AnchorPoint();

                reader.BaseStream.Seek(beginAt, SeekOrigin.Begin);

                switch (anchorPoint.format = reader.ReadUInt16())
                {
                default: throw new NotSupportedException();

                case 1:
                {
                    // AnchorFormat1 table: Design units only
                    //AnchorFormat1 consists of a format identifier (AnchorFormat) and a pair of design unit coordinates (XCoordinate and YCoordinate)
                    //that specify the location of the anchor point.
                    //This format has the benefits of small size and simplicity,
                    //but the anchor point cannot be hinted to adjust its position for different device resolutions.
                    //Value     Type    Description
                    //USHORT    AnchorFormat    Format identifier, = 1
                    //SHORT     XCoordinate     Horizontal value, in design units
                    //SHORT     YCoordinate     Vertical value, in design units
                    anchorPoint.xcoord = reader.ReadInt16();
                    anchorPoint.ycoord = reader.ReadInt16();
                }
                break;

                case 2:
                {
                    //Anchor Table: Format 2

                    //Like AnchorFormat1, AnchorFormat2 specifies a format identifier (AnchorFormat) and
                    //a pair of design unit coordinates for the anchor point (Xcoordinate and Ycoordinate).

                    //For fine-tuning the location of the anchor point,
                    //AnchorFormat2 also provides an index to a glyph contour point (AnchorPoint)
                    //that is on the outline of a glyph (AnchorPoint).***
                    //Hinting can be used to move the AnchorPoint. In the rendered text,
                    //the AnchorPoint will provide the final positioning data for a given ppem size.

                    //Example 16 at the end of this chapter uses AnchorFormat2.


                    //AnchorFormat2 table: Design units plus contour point
                    //Value     Type    Description
                    //USHORT    AnchorFormat    Format identifier, = 2
                    //SHORT     XCoordinate     Horizontal value, in design units
                    //SHORT     YCoordinate     Vertical value, in design units
                    //USHORT    AnchorPoint     Index to glyph contour point

                    anchorPoint.xcoord = reader.ReadInt16();
                    anchorPoint.ycoord = reader.ReadInt16();
                    anchorPoint.refGlyphContourPoint = reader.ReadUInt16();
                }
                break;

                case 3:
                {
                    //Anchor Table: Format 3

                    //Like AnchorFormat1, AnchorFormat3 specifies a format identifier (AnchorFormat) and
                    //locates an anchor point (Xcoordinate and Ycoordinate).
                    //And, like AnchorFormat 2, it permits fine adjustments in variable fonts to the coordinate values.
                    //However, AnchorFormat3 uses Device tables, rather than a contour point, for this adjustment.

                    //With a Device table, a client can adjust the position of the anchor point for any font size and device resolution.
                    //AnchorFormat3 can specify offsets to Device tables for the the X coordinate (XDeviceTable)
                    //and the Y coordinate (YDeviceTable).
                    //If only one coordinate requires adjustment,
                    //the offset to the Device table may be set to NULL for the other coordinate.

                    //In variable fonts, AnchorFormat3 must be used to reference variation data to adjust anchor points for different variation instances,
                    //if needed.
                    //In this case, AnchorFormat3 specifies an offset to a VariationIndex table,
                    //which is a variant of the Device table used for variations.
                    //If no VariationIndex table is used for a particular anchor point X or Y coordinate,
                    //then that value is used for all variation instances.
                    //While separate VariationIndex table references are required for each value that requires variation,
                    //two or more values that require the same variation-data values can have offsets that point to the same VariationIndex table, and two or more VariationIndex tables can reference the same variation data entries.

                    //Example 17 at the end of the chapter shows an AnchorFormat3 table.


                    //AnchorFormat3 table: Design units plus Device or VariationIndex tables
                    //Value     Type    Description
                    //USHORT    AnchorFormat    Format identifier, = 3
                    //SHORT     XCoordinate     Horizontal value, in design units
                    //SHORT     YCoordinate     Vertical value, in design units
                    //Offset    XDeviceTable    Offset to Device table (non-variable font) / VariationIndex table (variable font) for X coordinate, from beginning of Anchor table (may be NULL)
                    //Offset    YDeviceTable    Offset to Device table (non-variable font) / VariationIndex table (variable font) for Y coordinate, from beginning of Anchor table (may be NULL)

                    anchorPoint.xcoord             = reader.ReadInt16();
                    anchorPoint.ycoord             = reader.ReadInt16();
                    anchorPoint.xdeviceTableOffset = reader.ReadInt16();
                    anchorPoint.ydeviceTableOffset = reader.ReadInt16();
                }
                break;
                }
                return(anchorPoint);
            }
コード例 #32
0
ファイル: Placement.cs プロジェクト: borkaborka/gmit
 /// <summary>Creates a frozen <see cref="Placement"/> instance from the given parameters.</summary>
 public static Placement CreateFrozen(DockPosition dock, AnchorPoint anchor, Thickness margin, Size size) {
    var p = new Placement { Dock = dock, Anchor = anchor, Margin = margin };
    p.SetFixedSize(size);
    p.Freeze();
    return p;
 }
コード例 #33
0
        private void AddInterpolatedPoints(Curve curve, AnchorPoint point1, AnchorPoint point2, AnchorPoint point3, AnchorPoint point4, int steps)
        {
            var interpolatedPoints = _pointsCalculator.GetInterpolatedPoints(point1.Position, point2.Position, point3.Position, point4.Position,
                                                                             point2.Tension, point2.Continuity, point2.Bias, steps);

            curve.Points.AddRange(interpolatedPoints);
        }
コード例 #34
0
 /// <summary>
 /// Gets the position of the component.
 /// </summary>
 public Vector2 GetPosition(Rectangle bounds, Rectangle parentBounds)
 {
     return(AnchorPoint.ToVector2() - new Vector2(OffsetX, OffsetY));
 }
コード例 #35
0
    public static Mesh Create(string name, float width, float length, int widthSegments, int lengthSegments, 
                              Orientation orientation, AnchorPoint anchor)
    {
        /*
        widthSegments = 1;
        lengthSegments = 1;
        Orientation orientation = Orientation.Horizontal;
        AnchorPoint anchor = AnchorPoint.Center;
        */
        Vector2 anchorOffset;
        switch (anchor)
        {
            case AnchorPoint.TopLeft:
                anchorOffset = new Vector2(-width/2.0f, length/2.0f);
                break;
            case AnchorPoint.TopHalf:
                anchorOffset = new Vector2(0.0f, length/2.0f);
                break;
            case AnchorPoint.TopRight:
                anchorOffset = new Vector2(width/2.0f, length/2.0f);
                break;
            case AnchorPoint.RightHalf:
                anchorOffset = new Vector2(width/2.0f, 0.0f);
                break;
            case AnchorPoint.BottomRight:
                anchorOffset = new Vector2(width/2.0f, -length/2.0f);
                break;
            case AnchorPoint.BottomHalf:
                anchorOffset = new Vector2(0.0f, -length/2.0f);
                break;
            case AnchorPoint.BottomLeft:
                anchorOffset = new Vector2(-width/2.0f, -length/2.0f);
                break;
            case AnchorPoint.LeftHalf:
                anchorOffset = new Vector2(-width/2.0f, 0.0f);
                break;
            //case AnchorPoint.Center:
            default:
                anchorOffset = Vector2.zero;
                break;
        }

        var m = new Mesh
                    {
                        name = name
                    };

        var hCount2 = widthSegments + 1;
        var vCount2 = lengthSegments + 1;
        var numTriangles = widthSegments * lengthSegments * 6;
        var numVertices = hCount2 * vCount2;

        var vertices = new Vector3[numVertices];
        var uvs = new Vector2[numVertices];
        var triangles = new int[numTriangles];

        var index = 0;
        var uvFactorX = 1.0f / widthSegments;
        var uvFactorY = 1.0f / lengthSegments;
        var scaleX = width / widthSegments;
        var scaleY = length / lengthSegments;
        for (var y = 0.0f; y < vCount2; y++)
        {
            for (var x = 0.0f; x < hCount2; x++)
            {
                if (orientation == Orientation.Horizontal)
                {
                    vertices[index] = new Vector3(x*scaleX - width/2f - anchorOffset.x, 0.0f,
                                                  y*scaleY - length/2f - anchorOffset.y);
                }
                else
                {
                    vertices[index] = new Vector3(x*scaleX - width/2f - anchorOffset.x,
                                                  y*scaleY - length/2f - anchorOffset.y, 0.0f);
                }
                uvs[index++] = new Vector2(x*uvFactorX, y*uvFactorY);
            }
        }

        index = 0;
        for (var y = 0; y < lengthSegments; y++)
        {
            for (var x = 0; x < widthSegments; x++)
            {
                triangles[index] = (y*hCount2) + x;
                triangles[index + 1] = ((y + 1)*hCount2) + x;
                triangles[index + 2] = (y*hCount2) + x + 1;

                triangles[index + 3] = ((y + 1)*hCount2) + x;
                triangles[index + 4] = ((y + 1)*hCount2) + x + 1;
                triangles[index + 5] = (y*hCount2) + x + 1;
                index += 6;
            }
        }

        m.vertices = vertices;
        m.uv = uvs;
        m.triangles = triangles;
        m.RecalculateNormals();

        m.RecalculateBounds();

        return m;
    }
コード例 #36
0
ファイル: NavGrid.cs プロジェクト: Notloc/Adventure-3
        //Creates the NavGrid's nodes
        public void ResizeGrid(int newWidth, int newHeight, AnchorPoint anchor)
        {
            //Return if the inputs are invalid
            if (newWidth < 0 || newHeight < 0)
            {
                return;
            }

            //If there is no existing grid, just make a new empty one and return
            if (width == 0 || height == 0)
            {
                width  = newWidth;
                height = newHeight;
                nodes  = new Node[width * height];
                return;
            }



            //Create the new empty grid
            Node[] newNodes = new Node[newWidth * newHeight];

            int xStart = 0, xEnd = 0;
            int yStart = 0, yEnd = 0;

            int xOffset = 0, yOffset = 0;
            int xMovement = 0, yMovement = 0;

            //Calculate where to insert the data into the new grid based on the selected anchor
            switch (anchor)
            {
            case AnchorPoint.NORTH_EAST:
                //X
                if (newWidth >= width)
                {
                    xStart    = newWidth - width;
                    xEnd      = newWidth;
                    xMovement = -xStart;
                }
                else
                {
                    xStart    = 0;
                    xEnd      = newWidth;
                    xOffset   = width - newWidth;
                    xMovement = xOffset;
                }

                //Y
                if (newHeight >= height)
                {
                    yStart    = newHeight - height;
                    yEnd      = newHeight;
                    yMovement = -yStart;
                }
                else
                {
                    yStart    = 0;
                    yEnd      = newHeight;
                    yOffset   = height - newHeight;
                    yMovement = yOffset;
                }
                break;

            case AnchorPoint.NORTH_WEST:
                //X
                xStart = 0;
                xEnd   = Mathf.Min(newWidth, width);

                //Y
                if (newHeight >= height)
                {
                    yStart    = newHeight - height;
                    yEnd      = newHeight;
                    yMovement = -yStart;
                }
                else
                {
                    yStart    = 0;
                    yEnd      = newHeight;
                    yOffset   = height - newHeight;
                    yMovement = yOffset;
                }
                break;

            case AnchorPoint.SOUTH_EAST:
                //X
                if (newWidth >= width)
                {
                    xStart    = newWidth - width;
                    xEnd      = newWidth;
                    xMovement = -xStart;
                }
                else
                {
                    xStart    = 0;
                    xEnd      = newWidth;
                    xOffset   = width - newWidth;
                    xMovement = xOffset;
                }

                yStart = 0;
                yEnd   = Mathf.Min(newHeight, height);
                break;

            case AnchorPoint.SOUTH_WEST:

                xStart = 0;
                xEnd   = Mathf.Min(newWidth, width);

                yStart = 0;
                yEnd   = Mathf.Min(newHeight, height);
                break;

            default:
                return;
            }

            //Insert old data into the new grid
            for (int y = yStart; y < yEnd; y++)
            {
                for (int x = xStart; x < xEnd; x++)
                {
                    int newIndex = (newWidth * y) + x;
                    int oldIndex = (width * (y - yStart + yOffset)) + (x - xStart + xOffset);
                    newNodes[newIndex] = nodes[oldIndex];
                }
            }

            //Update variables
            nodes  = newNodes;
            width  = newWidth;
            height = newHeight;

            positionOffset += new Vector3(xMovement, 0, yMovement);
        }
コード例 #37
0
        internal static bool Load(TextLayout layout, System.Xml.XPath.XPathNavigator r)
        {
            switch (r.Name)
            {
            case "TextLabel":
                bool        okay;
                int         x        = 0;
                int         y        = 0;
                Color       color    = Color.Black;
                string      name     = "NoName";
                string      fontname = "Default";
                AnchorPoint anchor   = AnchorPoint.TopLeft;
                bool        everokay = false;
                bool        center   = false;
                bool        right    = false;
                TextLabel   label    = null;
                for (okay = r.MoveToFirstAttribute(); okay; okay = r.MoveToNextAttribute())
                {
                    everokay = true;
                    switch (r.Name)
                    {
                    case "AlignCenter":
                        center = Convert.ToBoolean(r.Value);
                        break;

                    case "AlignRight":
                        right = Convert.ToBoolean(r.Value);
                        break;

                    case "color":
                        color = Color.FromArgb(Convert.ToInt32(r.Value));
                        break;

                    case "font":
                        fontname = r.Value;
                        break;

                    case "Name":
                        name = r.Value;
                        break;

                    case "X":
                        x = Convert.ToInt32(r.Value);
                        break;

                    case "Y":
                        y = Convert.ToInt32(r.Value);
                        break;

                    case "Anchor":
                        switch (r.Value)
                        {
                        case "TopLeft":
                            anchor = AnchorPoint.TopLeft;
                            break;

                        case "TopRight":
                            anchor = AnchorPoint.TopRight;
                            break;

                        case "BottomLeft":
                            anchor = AnchorPoint.BottomLeft;
                            break;

                        case "BottomRight":
                            anchor = AnchorPoint.BottomRight;
                            break;
                        }
                        break;
                    }
                }
                label = new TextLabel(name, x, y, anchor, fontname, color);
                if (label != null)
                {
                    label.bDrawRightJustified = right;
                    label.bHorizCenter        = center;
                    layout.placements.Add(label);
                }
                if (everokay)
                {
                    r.MoveToParent();
                }
                break;
            }
            return(false);
        }
コード例 #38
0
ファイル: TileBehaviour.cs プロジェクト: dgkae/UnitySlippyMap
		/// <summary>
		/// Creates a tile template GameObject.
		/// </summary>
		/// <returns>The tile template.</returns>
		/// <param name="anchorPoint">Anchor point.</param>
		public static TileBehaviour CreateTileTemplate (AnchorPoint anchorPoint)
		{
			return CreateTileTemplate ("[Tile Template]", anchorPoint);
		}
コード例 #39
0
 public static bool IsCenterAligned(AnchorPoint anchorPoint)
 {
     return(anchorPoint == AnchorPoint.TopCenter ||
            anchorPoint == AnchorPoint.Center ||
            anchorPoint == AnchorPoint.BottomCenter);
 }
コード例 #40
0
ファイル: TileBehaviour.cs プロジェクト: dgkae/UnitySlippyMap
		/// <summary>
		/// Creates a tile template GameObject.
		/// </summary>
		/// <returns>The tile template.</returns>
		/// <param name="tileName">Tile name.</param>
		/// <param name="anchorPoint">Anchor point.</param>
		public static TileBehaviour CreateTileTemplate (string tileName, AnchorPoint anchorPoint)
		{
			GameObject tileTemplate = new GameObject (tileName);
			TileBehaviour tile = tileTemplate.AddComponent<TileBehaviour> ();
			MeshFilter meshFilter = tileTemplate.AddComponent<MeshFilter> ();
			MeshRenderer meshRenderer = tileTemplate.AddComponent<MeshRenderer> ();
			BoxCollider boxCollider = tileTemplate.AddComponent<BoxCollider> ();
			
			// add the geometry
			Mesh mesh = meshFilter.mesh;
			switch (anchorPoint) {
			case AnchorPoint.TopLeft:
				mesh.vertices = new Vector3[] {
				new Vector3 (1.0f, 0.0f, 0.0f),
				new Vector3 (1.0f, 0.0f, -1.0f),
				new Vector3 (0.0f, 0.0f, -1.0f),
				new Vector3 (0.0f, 0.0f, 0.0f)
			};
				break;
			case AnchorPoint.TopCenter:
				mesh.vertices = new Vector3[] {
				new Vector3 (0.5f, 0.0f, 0.0f),
				new Vector3 (0.5f, 0.0f, -1.0f),
				new Vector3 (-0.5f, 0.0f, -1.0f),
				new Vector3 (-0.5f, 0.0f, 0.0f)
			};
				break;
			case AnchorPoint.TopRight:
				mesh.vertices = new Vector3[] {
				new Vector3 (0.0f, 0.0f, 0.0f),
				new Vector3 (0.0f, 0.0f, -1.0f),
				new Vector3 (-1.0f, 0.0f, -1.0f),
				new Vector3 (-1.0f, 0.0f, 0.0f)
			};
				break;
			case AnchorPoint.MiddleLeft:
				mesh.vertices = new Vector3[] {
				new Vector3 (1.0f, 0.0f, 0.5f),
				new Vector3 (1.0f, 0.0f, -0.5f),
				new Vector3 (0.0f, 0.0f, -0.5f),
				new Vector3 (0.0f, 0.0f, 0.5f)
			};
				break;
			case AnchorPoint.MiddleRight:
				mesh.vertices = new Vector3[] {
				new Vector3 (0.0f, 0.0f, 0.5f),
				new Vector3 (0.0f, 0.0f, -0.5f),
				new Vector3 (-1.0f, 0.0f, -0.5f),
				new Vector3 (-1.0f, 0.0f, 0.5f)
			};
				break;
			case AnchorPoint.BottomLeft:
				mesh.vertices = new Vector3[] {
				new Vector3 (1.0f, 0.0f, 1.0f),
				new Vector3 (1.0f, 0.0f, 0.0f),
				new Vector3 (0.0f, 0.0f, 0.0f),
				new Vector3 (0.0f, 0.0f, 1.0f)
			};
				break;
			case AnchorPoint.BottomCenter:
				mesh.vertices = new Vector3[] {
				new Vector3 (0.5f, 0.0f, 1.0f),
				new Vector3 (0.5f, 0.0f, 0.0f),
				new Vector3 (-0.5f, 0.0f, 0.0f),
				new Vector3 (-0.5f, 0.0f, 1.0f)
			};
				break;
			case AnchorPoint.BottomRight:
				mesh.vertices = new Vector3[] {
				new Vector3 (0.0f, 0.0f, 1.0f),
				new Vector3 (0.0f, 0.0f, 0.0f),
				new Vector3 (-1.0f, 0.0f, 0.0f),
				new Vector3 (-1.0f, 0.0f, 1.0f)
			};
				break;
			default: // MiddleCenter
				mesh.vertices = new Vector3[] {
				new Vector3 (0.5f, 0.0f, 0.5f),
				new Vector3 (0.5f, 0.0f, -0.5f),
				new Vector3 (-0.5f, 0.0f, -0.5f),
				new Vector3 (-0.5f, 0.0f, 0.5f)
			};
				break;
			}
			mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3 };
		
			// add normals
			mesh.normals = new Vector3[] {
				Vector3.up,
				Vector3.up,
				Vector3.up,
				Vector3.up
			};
			// add uv coordinates
			mesh.uv = new Vector2[] {
				new Vector2 (1.0f, 1.0f),
				new Vector2 (1.0f, 0.0f),
				new Vector2 (0.0f, 0.0f),
				new Vector2 (0.0f, 1.0f)
			};
			
			// add a material
			string shaderName = "Somian/Unlit/Transparent";
			Shader shader = Shader.Find (shaderName);
			
#if DEBUG_LOG
		Debug.Log("DEBUG: shader for tile template: " + shaderName + ", exists: " + (shader != null));
#endif
			
			tile.material = meshRenderer.material = new Material (shader);
			
			// setup the collider
			boxCollider.size = new Vector3 (1.0f, 0.0f, 1.0f);
		
			return tile;
		}
コード例 #41
0
 public static bool IsTopAligned(AnchorPoint anchorPoint)
 {
     return(anchorPoint == AnchorPoint.TopLeft ||
            anchorPoint == AnchorPoint.TopCenter ||
            anchorPoint == AnchorPoint.TopRight);
 }
コード例 #42
0
        //returns anchor point on searchTarget nearest to pivot
        public static void NearestAnchor(Point pivot, ClientLinkable searchTarget,
                                         out AnchorPoint anchor, out Point anchorPoint,
                                         out double minDist)
        {
            anchor  = AnchorPoint.RightCenter;
            minDist = double.MaxValue;

            //double d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.TopLeft));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.TopLeft;
            //}

            var d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.TopCenter));

            if (d < minDist)
            {
                minDist = d;
                anchor  = AnchorPoint.TopCenter;
            }

            //d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.TopRight));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.TopRight;
            //}

            d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.LeftCenter));
            if (d < minDist)
            {
                minDist = d;
                anchor  = AnchorPoint.LeftCenter;
            }

            //d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.BottomLeft));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.BottomLeft;
            //}

            d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.BottomCenter));
            if (d < minDist)
            {
                minDist = d;
                anchor  = AnchorPoint.BottomCenter;
            }

            //d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.BottomRight));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.BottomRight;
            //}

            d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.RightCenter));
            if (d < minDist)
            {
                minDist = d;
                anchor  = AnchorPoint.RightCenter;
            }

            minDist     = Math.Sqrt(minDist);
            anchorPoint = GetAnchorCoords(searchTarget, anchor);
        }
コード例 #43
0
 public static bool IsBottomAligned(AnchorPoint anchorPoint)
 {
     return(anchorPoint == AnchorPoint.BottomLeft ||
            anchorPoint == AnchorPoint.BottomCenter ||
            anchorPoint == AnchorPoint.BottomRight);
 }
コード例 #44
0
ファイル: ShapeUtils.cs プロジェクト: gdlprj/duscusys
 public static Point GetAnchorCoords(ClientLinkable end, AnchorPoint anchorPoint)
 {
     var border = end.GetBounds();
     border.Inflate(20,20);
     switch (anchorPoint)
     {
         case AnchorPoint.TopLeft:
             return border.TopLeft;
         case AnchorPoint.TopCenter:
             return new Point(border.X + border.Width / 2, border.Y);
         case AnchorPoint.TopRight:
             return border.TopRight;
         case AnchorPoint.LeftCenter:
             return new Point(border.X, border.Y + border.Height / 2);
         case AnchorPoint.BottomLeft:
             return border.BottomLeft;
         case AnchorPoint.BottomCenter:
             return new Point(border.X + border.Width / 2, border.Y + border.Height);
         case AnchorPoint.BottomRight:
             return border.BottomRight;
         case AnchorPoint.RightCenter:
             return new Point(border.X + border.Width, border.Y + border.Height / 2);
         default:
             throw new NotSupportedException();
     }
 }
コード例 #45
0
ファイル: UIRect.cs プロジェクト: hoangwin/2-ca-rs-tim-berman
	/// <summary>
	/// Helper function that gets the specified anchor's position relative to the chosen transform.
	/// </summary>

	protected Vector3 GetLocalPos (AnchorPoint ac, Transform trans)
	{
		if (anchorCamera == null || ac.targetCam == null)
			return cachedTransform.localPosition;

		Vector3 pos = mMyCam.ViewportToWorldPoint(ac.targetCam.WorldToViewportPoint(ac.target.position));
		if (trans != null) pos = trans.InverseTransformPoint(pos);
		pos.x = Mathf.Floor(pos.x + 0.5f);
		pos.y = Mathf.Floor(pos.y + 0.5f);
		return pos;
	}
コード例 #46
0
ファイル: ShapeUtils.cs プロジェクト: gdlprj/duscusys
        //returns anchor point on searchTarget nearest to pivot
        public static void NearestAnchor(Point pivot, ClientLinkable searchTarget,
                                         out AnchorPoint anchor, out Point anchorPoint,
                                         out double minDist)
        {
            anchor = AnchorPoint.RightCenter;
            minDist = double.MaxValue;

            //double d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.TopLeft));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.TopLeft;
            //}

            var d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.TopCenter));
            if (d < minDist)
            {
                minDist = d;
                anchor = AnchorPoint.TopCenter;
            }

            //d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.TopRight));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.TopRight;
            //}

            d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.LeftCenter));
            if (d < minDist)
            {
                minDist = d;
                anchor = AnchorPoint.LeftCenter;
            }

            //d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.BottomLeft));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.BottomLeft;
            //}

            d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.BottomCenter));
            if (d < minDist)
            {
                minDist = d;
                anchor = AnchorPoint.BottomCenter;
            }

            //d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.BottomRight));
            //if (d < minDist)
            //{
            //    minDist = d;
            //    anchor = AnchorPoint.BottomRight;
            //}

            d = Dist2(pivot, GetAnchorCoords(searchTarget, AnchorPoint.RightCenter));
            if (d < minDist)
            {
                minDist = d;
                anchor = AnchorPoint.RightCenter;
            }

            minDist = Math.Sqrt(minDist);
            anchorPoint = GetAnchorCoords(searchTarget, anchor);
        }
コード例 #47
0
ファイル: UIRect.cs プロジェクト: zhang00lei/2048
	/// <summary>
	/// Helper function that gets the specified anchor's position relative to the chosen transform.
	/// </summary>

	protected Vector3 GetLocalPos (AnchorPoint ac, Transform trans)
	{
		if (anchorCamera == null || ac.targetCam == null)
			return cachedTransform.localPosition;

		Rect rect = ac.targetCam.rect;
		Vector3 viewPos = ac.targetCam.WorldToViewportPoint(ac.target.position);
		Vector3 pos = new Vector3((viewPos.x * rect.width) + rect.x, (viewPos.y * rect.height) + rect.y, viewPos.z);
		pos = mCam.ViewportToWorldPoint(pos);
		if (trans != null) pos = trans.InverseTransformPoint(pos);
		pos.x = Mathf.Floor(pos.x + 0.5f);
		pos.y = Mathf.Floor(pos.y + 0.5f);
		return pos;
	}
コード例 #48
0
        /// <summary>
        /// Override of DoHitTest so it works with non-rectilinear line segments
        /// </summary>
        public override bool DoHitTest(IGeometryHost geometryHost, PointD hitPoint, DiagramHitTestInfo hitTestInfo, bool includeTolerance)
        {
            bool        retVal      = false;
            LineSegment hitSegment  = null;
            AnchorPoint anchorPoint = null;
            // In DSL Tools v8.2, GetHitTestTolerance is an instance method, but in DSL Tools v9.0, it is a static method.
            // We call it without a qualifier here so that it will compile against both versions.
            SizeD      tolerance = GetHitTestTolerance(hitTestInfo);
            RectangleD perimeter = this.GetPerimeterBoundingBox(geometryHost);

            perimeter.Inflate(tolerance);
            if (perimeter.Contains(hitPoint))
            {
                LineSegment[] segments     = this.CalculateSegments(geometryHost, hitTestInfo);
                int           segmentCount = segments.Length;
                for (int i = 0; i < segmentCount; ++i)
                {
                    LineSegment testSegment = segments[i];
                    RectangleD  testBounds  = GeometryHelpers.RectangleDFrom2Pts(testSegment.StartPoint, testSegment.EndPoint);
                    testBounds.Inflate(tolerance);
                    if (testBounds.Contains(hitPoint))
                    {
                        anchorPoint = TestHitAnchor(geometryHost as BinaryLinkShape, testSegment, tolerance, hitPoint);
                        if (anchorPoint != null)
                        {
                            retVal     = true;
                            hitSegment = testSegment;
                            break;
                        }
                        double distance = DistanceFromPointToLine(hitPoint, testSegment.StartPoint, testSegment.EndPoint, true);
                        if (!double.IsNaN(distance) && distance < (tolerance.Width + geometryHost.GeometryStyleSet.GetPen(geometryHost.GeometryOutlinePenId).Width / 2f))
                        {
                            retVal     = true;
                            hitSegment = testSegment;
                            break;
                        }
                    }
                }
            }
            if (hitTestInfo != null)
            {
                DiagramItem diagramItem;
                if (retVal)
                {
                    if (anchorPoint == null)
                    {
                        // In DSL Tools v8.2, CreateDiagramItem is an instance method, but in DSL Tools v9.0, it is a static method.
                        // We call it without a qualifier here so that it will compile against both versions.
                        diagramItem = CreateDiagramItem(geometryHost, hitSegment);
                    }
                    else
                    {
                        diagramItem = new DiagramItem(geometryHost as LinkShape, hitSegment, anchorPoint);
                    }
                }
                else
                {
                    diagramItem = null;
                }
                hitTestInfo.HitDiagramItem = diagramItem;
                hitTestInfo.HitGrabHandle  = null;
            }
            return(retVal);
        }
コード例 #49
0
    public static Mesh Create(string name, float width, float length, int widthSegments, int lengthSegments,
                              Orientation orientation, AnchorPoint anchor)
    {
        /*
         * widthSegments = 1;
         * lengthSegments = 1;
         * Orientation orientation = Orientation.Horizontal;
         * AnchorPoint anchor = AnchorPoint.Center;
         */
        Vector2 anchorOffset;

        switch (anchor)
        {
        case AnchorPoint.TopLeft:
            anchorOffset = new Vector2(-width / 2.0f, length / 2.0f);
            break;

        case AnchorPoint.TopHalf:
            anchorOffset = new Vector2(0.0f, length / 2.0f);
            break;

        case AnchorPoint.TopRight:
            anchorOffset = new Vector2(width / 2.0f, length / 2.0f);
            break;

        case AnchorPoint.RightHalf:
            anchorOffset = new Vector2(width / 2.0f, 0.0f);
            break;

        case AnchorPoint.BottomRight:
            anchorOffset = new Vector2(width / 2.0f, -length / 2.0f);
            break;

        case AnchorPoint.BottomHalf:
            anchorOffset = new Vector2(0.0f, -length / 2.0f);
            break;

        case AnchorPoint.BottomLeft:
            anchorOffset = new Vector2(-width / 2.0f, -length / 2.0f);
            break;

        case AnchorPoint.LeftHalf:
            anchorOffset = new Vector2(-width / 2.0f, 0.0f);
            break;

        //case AnchorPoint.Center:
        default:
            anchorOffset = Vector2.zero;
            break;
        }


        var m = new Mesh
        {
            name = name
        };

        var hCount2      = widthSegments + 1;
        var vCount2      = lengthSegments + 1;
        var numTriangles = widthSegments * lengthSegments * 6;
        var numVertices  = hCount2 * vCount2;

        var vertices  = new Vector3[numVertices];
        var uvs       = new Vector2[numVertices];
        var triangles = new int[numTriangles];

        var index     = 0;
        var uvFactorX = 1.0f / widthSegments;
        var uvFactorY = 1.0f / lengthSegments;
        var scaleX    = width / widthSegments;
        var scaleY    = length / lengthSegments;

        for (var y = 0.0f; y < vCount2; y++)
        {
            for (var x = 0.0f; x < hCount2; x++)
            {
                if (orientation == Orientation.Horizontal)
                {
                    vertices[index] = new Vector3(x * scaleX - width / 2f - anchorOffset.x, 0.0f,
                                                  y * scaleY - length / 2f - anchorOffset.y);
                }
                else
                {
                    vertices[index] = new Vector3(x * scaleX - width / 2f - anchorOffset.x,
                                                  y * scaleY - length / 2f - anchorOffset.y, 0.0f);
                }
                uvs[index++] = new Vector2(x * uvFactorX, y * uvFactorY);
            }
        }

        index = 0;
        for (var y = 0; y < lengthSegments; y++)
        {
            for (var x = 0; x < widthSegments; x++)
            {
                triangles[index]     = (y * hCount2) + x;
                triangles[index + 1] = ((y + 1) * hCount2) + x;
                triangles[index + 2] = (y * hCount2) + x + 1;

                triangles[index + 3] = ((y + 1) * hCount2) + x;
                triangles[index + 4] = ((y + 1) * hCount2) + x + 1;
                triangles[index + 5] = (y * hCount2) + x + 1;
                index += 6;
            }
        }

        m.vertices  = vertices;
        m.uv        = uvs;
        m.triangles = triangles;
        m.RecalculateNormals();

        m.RecalculateBounds();

        return(m);
    }
コード例 #50
0
ファイル: UIRect.cs プロジェクト: Henry-T/UnityPG
	/// <summary>
	/// Helper function that gets the specified anchor's position relative to the chosen transform.
	/// </summary>

	protected Vector2 GetLocalPos (AnchorPoint ac, Transform trans)
	{
		Vector3 pos = ac.cam.WorldToScreenPoint(ac.target.position);
		pos = mAnchorCam.ScreenToWorldPoint(pos);
		if (trans != null) pos = trans.InverseTransformPoint(pos);
		pos.x = Mathf.Round(pos.x);
		pos.y = Mathf.Round(pos.y);
		return pos;
	}