当前位置: 首页>>代码示例>>C#>>正文


C# AnchorPoint类代码示例

本文整理汇总了C#中AnchorPoint的典型用法代码示例。如果您正苦于以下问题:C# AnchorPoint类的具体用法?C# AnchorPoint怎么用?C# AnchorPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AnchorPoint类属于命名空间,在下文中一共展示了AnchorPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Awake

 void Awake()
 {
     if (instance != null)
     {
         Debug.LogError("Singleton AnchorPoint already found...");
         Destroy(gameObject);
     }
     else
     {
         instance = this;
     }
 }
开发者ID:Csmidget,项目名称:Fine-Motor-Training,代码行数:12,代码来源:AnchorPoint.cs

示例2: SetupRect

 /// <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;
 }
开发者ID:zukeru,项目名称:ageofasura,代码行数:27,代码来源:AtavismWindowTemplate.cs

示例3: AnchorConvert

 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");
     }
 }
开发者ID:shalves,项目名称:Ext.NET.Community,代码行数:26,代码来源:Fx.cs

示例4: Create

    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();

//.........这里部分代码省略.........
开发者ID:kamisama366095,项目名称:DarkChess,代码行数:101,代码来源:CreatePlane.cs

示例5: Initialize

 public void Initialize(GameObject owner, AnchorPoint anchor)
 {
     this.gameObject = owner;
     animations = new Dictionary<string, Animation>();
     SetAnchorPoint(anchor);
 }
开发者ID:Thunderchen,项目名称:CavemanRunner,代码行数:6,代码来源:Renderer.cs

示例6: SetAnchorPoint

        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);
        }
开发者ID:Thunderchen,项目名称:CavemanRunner,代码行数:11,代码来源:Renderer.cs

示例7: NearestAnchor

        //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);
        }
开发者ID:gdlprj,项目名称:duscusys,代码行数:67,代码来源:ShapeUtils.cs

示例8: FindCameraFor

	/// <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;
				}
			}
		}
	}
开发者ID:Henry-T,项目名称:UnityPG,代码行数:39,代码来源:UIRect.cs

示例9: GetLocalPos

	/// <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;
	}
开发者ID:zhang00lei,项目名称:2048,代码行数:18,代码来源:UIRect.cs

示例10: CreateTileTemplate

		/// <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);
		}
开发者ID:dgkae,项目名称:UnitySlippyMap,代码行数:9,代码来源:TileBehaviour.cs

示例11: DrawDots

        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;
//.........这里部分代码省略.........
开发者ID:samuto,项目名称:designscript,代码行数:101,代码来源:DrawingUtilities.cs

示例12: Anchor

 /// <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;
 }
开发者ID:benfoster,项目名称:ImageResizer.FluentExtensions,代码行数:10,代码来源:AlignmentExpression.cs

示例13: CreateFrozen

 /// <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;
 }
开发者ID:borkaborka,项目名称:gmit,代码行数:7,代码来源:Placement.cs

示例14: Awake

	private void Awake() {
		rigid = GetComponent<Rigidbody2D>();
		anchorPoint = GetComponentInChildren<AnchorPoint>();
		anchorableID = currentAnchorableID++;
		WhitTools.Assert(anchorPoint != null, "object has no anchor point!");
	}
开发者ID:wtrebella,项目名称:Grappler,代码行数:6,代码来源:Anchorable.cs

示例15: GetLocalPos

	/// <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;
	}
开发者ID:hoangwin,项目名称:2-ca-rs-tim-berman,代码行数:15,代码来源:UIRect.cs


注:本文中的AnchorPoint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。