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


C# Rect.Set方法代码示例

本文整理汇总了C#中UnityEngine.Rect.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Set方法的具体用法?C# Rect.Set怎么用?C# Rect.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Rect的用法示例。


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

示例1: Start

    // Use this for initialization
    void Start()
    {
        float verticalSize   = Camera.main.orthographicSize * 2.0f;
        float horizontalSize = verticalSize * Screen.width / Screen.height;

        GameObject rock = GameObject.Find ("Rock");
        MapGeneratorInternal generator = new MapGeneratorInternal (new Vector2(horizontalSize, verticalSize));

        for (int i = 0; i < 10000; i++) {
            generator.Generate ();
        }

        Rect center1 = new Rect ();
        Rect center2 = new Rect ();
        Rect center3 = new Rect ();

        center1.Set (horizontalSize / 2, 0, horizontalSize / 100, verticalSize);
        center2.Set (0, verticalSize / 2, horizontalSize, verticalSize / 100);
        center2.Set (horizontalSize * 0.45f, verticalSize * 0.45f, horizontalSize * 0.10f, verticalSize * 0.10f);

        foreach(var rect in generator.Rects){
            if(Random.Range(0,2) != 0)
                continue;

            if(rect.Overlaps(center1) || rect.Overlaps(center2))
                continue;

            Vector3 center = new Vector3(rect.x + rect.width/2 - horizontalSize/2, rect.y + rect.height / 2-verticalSize/2);
            GameObject rock2 = Instantiate (rock, center, Quaternion.identity) as GameObject;
            PolyMesh a = rock2.GetComponent<PolyMesh> ();

            a.makeUnique ();

            a.keyPoints.Clear ();
            a.isCurve.Clear ();

            a.keyPoints.Add(new Vector3(-rect.width/2, -rect.height/2));
            a.keyPoints.Add(new Vector3(rect.width/2, -rect.height/2));
            a.keyPoints.Add(new Vector3(rect.width/2, rect.height/2));
            a.keyPoints.Add(new Vector3(-rect.width/2, rect.height/2));

            for(int i =0; i< a.keyPoints.Count; i++)
                a.isCurve.Add(false);

            a.BuildMesh ();

        }
    }
开发者ID:Nican,项目名称:imgd4100,代码行数:49,代码来源:MapGenerator.cs

示例2: CaculateInteractiveRect

    public static Rect CaculateInteractiveRect( Rect r1, Rect r2 )
    {
        Rect result = new Rect(r1);

        if( result.xMin < r2.xMin )
        {
            result.xMin = r2.xMin;
        }
        if( result.yMin < r2.yMin )
        {
            result.yMin = r2.yMin;
        }
        if( result.xMax > r2.xMax )
        {
            result.xMax = r2.xMax;
        }
        if( result.yMax > r2.yMax )
        {
            result.yMax = r2.yMax;
        }

        if( result.width < 0 || result.height < 0 )
        {
            result.Set(0,0,0,0);
        }

        return result;
    }
开发者ID:p0e0o0p0l0e0,项目名称:test-woniu,代码行数:28,代码来源:NGUIMath.cs

示例3: OnGUI

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        //get data
        SerializedProperty axisX = property.FindPropertyRelative("axisX");
        SerializedProperty axisY = property.FindPropertyRelative("axisY");
        SerializedProperty axisZ = property.FindPropertyRelative("axisZ");

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

        float width = position.width;
        width /= 4.0f;
        position.Set(position.x, position.y, width, position.height);

        GUIContent labelAxis = new GUIContent("X");
        EditorGUIUtility.labelWidth = GUI.skin.label.CalcSize(labelAxis).x*3;
        axisX.boolValue = EditorGUI.Toggle(position, labelAxis, axisX.boolValue);
        position.x += width;

        labelAxis = new GUIContent("Y");
        axisY.boolValue = EditorGUI.Toggle(position, labelAxis, axisY.boolValue);
        position.x += width;

        labelAxis = new GUIContent("Z");
        axisZ.boolValue = EditorGUI.Toggle(position, labelAxis, axisZ.boolValue);

        EditorGUI.EndProperty();
    }
开发者ID:MaturuturuStudios,项目名称:Drop,代码行数:29,代码来源:AxisBooleanDrawer.cs

示例4: OnGUI

 void OnGUI()
 {
     Rect rect = new Rect(0, 0, 200, 20);
     GUI.Label(rect, "Mesh Vertex Count: " + vertexCount);
     rect.Set(rect.xMin, rect.yMin + 20, rect.width, rect.height);
     GUI.Label(rect, "Mesh Triangle Count: " + triangleCount);
     rect.Set(rect.xMin, rect.yMin + 20, rect.width, rect.height);
     GUI.Label(rect, "Mesh Count: " + objPool.Count);
     rect.Set(rect.xMin, rect.yMin + 20, rect.width, rect.height);
     GUI.Label(rect, "Total Vertex Count: " + vertexCount * objPool.Count);
     rect.Set(rect.xMin, rect.yMin + 20, rect.width, rect.height);
     GUI.Label(rect, "Total Triangle Count: " + triangleCount * objPool.Count);
     rect.Set(rect.xMin, rect.yMin + 20, rect.width, rect.height);
     if (GUI.Button(rect, "Add Obj"))
     {
         GameObject newObj = GameObject.Instantiate(obj) as GameObject;
         newObj.transform.parent = root;
         newObj.transform.localPosition = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(0f, 1f));
         objPool.Add(newObj);
     }
     rect.Set(rect.xMin, rect.yMin + 20, rect.width, rect.height);
     if (GUI.Button(rect, "Run Static Batch"))
     {
         StaticBatchingUtility.Combine(root.gameObject);
     }
     rect.Set(rect.xMin, rect.yMin + 20, rect.width, rect.height);
 }
开发者ID:WaylandGod,项目名称:learn_unity,代码行数:27,代码来源:BatchTest.cs

示例5: Node

 public Node(Vector2 dimension, Vector2 position)
 {
     Rectangle = new Rect (position, dimension);
     Rectangle.Set ((int)Rectangle.xMin, (int)Rectangle.yMin, (int)Rectangle.width, (int)Rectangle.height);
     LeftChild = null;
     RightChild = null;
     Room = null;
     Level = 0;
 }
开发者ID:Ramzawulf,项目名称:FinalProject,代码行数:9,代码来源:Node.cs

示例6: DrawCrossHair

    public static void DrawCrossHair(SelectionType mode)
    {
        int cursorSizeX = 5;
        int cursorSizeY = 5;
        Color col = Color.green;
        Color tra = new Color(0.0f, 0.0f, 0.0f, 0.0f);

        // Initialize crosshair texture
        Texture2D tex = new Texture2D(cursorSizeX, cursorSizeY);
        for (int x = 0; x < cursorSizeX; x++) {
            for (int y = 0; y < cursorSizeY; y++) {
                if (x == 2 || y == 2)
                    tex.SetPixel(x, y, col);
                else
                    tex.SetPixel(x, y, tra);
            }
        }
        tex.SetPixel(2, 2, col);
        tex.Apply();

        // Determine where to draw crosshair
        Rect finalPos = new Rect();
        switch(mode) {
        case SelectionType.MIDDLE_SCREEN:
            finalPos.Set(
                (Screen.width/2) - (cursorSizeX/2),
                (Screen.height/2) - (cursorSizeY/2),
                cursorSizeX,
                cursorSizeY
                );
            break;
        case SelectionType.MOUSE:
            finalPos.Set(
                Event.current.mousePosition.x - (cursorSizeX/2),
                Event.current.mousePosition.y - (cursorSizeY/2),
                cursorSizeX,
                cursorSizeY
                );
            break;
        }

        // Draw crosshair
        GUI.DrawTexture (finalPos, tex);
    }
开发者ID:nkf,项目名称:gamedev2014_20minexp,代码行数:44,代码来源:GUIHelpers.cs

示例7: GetCameraBounds

        public static Rect GetCameraBounds(Camera _camera, float _tolerance = 5)
        {
            Rect _rct = new Rect(0, 0, 0, 0);

            Vector3 upperLeft = _camera.ViewportToWorldPoint(new Vector3(0, 0, _camera.farClipPlane));
            Vector3 lowerRight = _camera.ViewportToWorldPoint(new Vector3(1, 1, _camera.farClipPlane));
            _rct.Set(upperLeft.x - _tolerance, upperLeft.y - _tolerance, lowerRight.x - upperLeft.x + _tolerance * 2, lowerRight.y - upperLeft.y + _tolerance * 2);

            return _rct;
        }
开发者ID:tmkebr,项目名称:Untitled,代码行数:10,代码来源:VLSViewer.cs

示例8: OnGUI

 void OnGUI()
 {
     if (!finished)
     {
       Rect moveRect = new Rect((Screen.width - 300) - 25, Screen.height * 0.5f, 300, 30);
       GUI.Label(moveRect, "Shadow's Name:");
       moveRect.Set(moveRect.left, moveRect.top + 30, moveRect.width, moveRect.height);
       shadowsName = GUI.TextField(moveRect, shadowsName, 28);
       moveRect.Set(moveRect.left, moveRect.top + 45, moveRect.width, moveRect.height);
       GUI.Label(moveRect, "Your Name:");
       moveRect.Set(moveRect.left, moveRect.top + 30, moveRect.width, moveRect.height);
       yourName = GUI.TextField(moveRect, yourName, 28);
       moveRect.Set(moveRect.left, moveRect.top + 45, moveRect.width, moveRect.height);
       if (GUI.Button(moveRect, "Submit to Hall of Shadows"))
       {
     ShadowSerializer.SerializeMyShadow(shadowContoller.toyContainer);
     StartCoroutine(ShadowSerializer.Submit(shadowsName, yourName, HALL_OF_SHADOWS));
     finished = true;
       }
       moveRect.Set(moveRect.left, moveRect.top + 45, moveRect.width, moveRect.height);
       if (GUI.Button(moveRect, "Don't Submit (But Finish)"))
       {
     ShadowSerializer.SerializeMyShadow(shadowContoller.toyContainer);
     Application.LoadLevel(HALL_OF_SHADOWS);
       }
       moveRect.Set(moveRect.left, moveRect.top + 45, moveRect.width, moveRect.height);
       if (GUI.Button(moveRect, "Continue Working on Shadow"))
       {
     shadowContoller.CancelZoom();
       }
     }
 }
开发者ID:hitchh1k3r,项目名称:LD33-Sweet-Dreams,代码行数:32,代码来源:GUIInput.cs

示例9: UpdateTransform

	void UpdateTransform()
	{
		// Break out if anchor camera is not bound
		if (AnchorCamera == null) {
			return;
		}

		float pixelScale = 1; // size of one pixel
		Vector3 position = myTransform.localPosition;

		// we're ignoring perspective tk2dCameras for now
		tk2dCamera = (AnchorTk2dCamera != null && AnchorTk2dCamera.CameraSettings.projection != tk2dCameraSettings.ProjectionType.Perspective) ? AnchorTk2dCamera : null;

		Rect rect = new Rect();
		if (tk2dCamera != null) {
			rect = anchorToNativeBounds ? tk2dCamera.NativeScreenExtents : tk2dCamera.ScreenExtents;
			pixelScale = tk2dCamera.GetSizeAtDistance( 1 ); 
		}
		else {
			rect.Set(0, 0, AnchorCamera.pixelWidth, AnchorCamera.pixelHeight);
		}

		float y_bot = rect.yMin;
		float y_top = rect.yMax;
		float y_ctr = (y_bot + y_top) * 0.5f;

		float x_lhs = rect.xMin;
		float x_rhs = rect.xMax;
		float x_ctr = (x_lhs + x_rhs) * 0.5f;

		Vector3 anchoredPosition = Vector3.zero;

		switch (AnchorPoint)
		{
		case tk2dBaseSprite.Anchor.UpperLeft: 		anchoredPosition = new Vector3(x_lhs, y_top, position.z); break;
		case tk2dBaseSprite.Anchor.UpperCenter: 	anchoredPosition = new Vector3(x_ctr, y_top, position.z); break;
		case tk2dBaseSprite.Anchor.UpperRight: 		anchoredPosition = new Vector3(x_rhs, y_top, position.z); break;
		case tk2dBaseSprite.Anchor.MiddleLeft: 		anchoredPosition = new Vector3(x_lhs, y_ctr, position.z); break;
		case tk2dBaseSprite.Anchor.MiddleCenter:	anchoredPosition = new Vector3(x_ctr, y_ctr, position.z); break;
		case tk2dBaseSprite.Anchor.MiddleRight: 	anchoredPosition = new Vector3(x_rhs, y_ctr, position.z); break;
		case tk2dBaseSprite.Anchor.LowerLeft: 		anchoredPosition = new Vector3(x_lhs, y_bot, position.z); break;
		case tk2dBaseSprite.Anchor.LowerCenter: 	anchoredPosition = new Vector3(x_ctr, y_bot, position.z); break;
		case tk2dBaseSprite.Anchor.LowerRight: 		anchoredPosition = new Vector3(x_rhs, y_bot, position.z); break;
		}
		
		Vector3 screenAnchoredPosition = anchoredPosition + new Vector3(pixelScale * offset.x, pixelScale * offset.y, 0);
		if (tk2dCamera == null) { // not a tk2dCamera, we need to transform
			Vector3 worldAnchoredPosition = AnchorCamera.ScreenToWorldPoint( screenAnchoredPosition );
			if (myTransform.position != worldAnchoredPosition) {
				myTransform.position = worldAnchoredPosition;
			}
		}
		else {
			Vector3 oldPosition = myTransform.localPosition;
			if (oldPosition != screenAnchoredPosition) {
				myTransform.localPosition = screenAnchoredPosition;
			}
		}
	}
开发者ID:rlugojr,项目名称:Chromacore,代码行数:59,代码来源:tk2dCameraAnchor.cs

示例10: addModsSlider

    //--------


        private void addModsSlider(int winID)
         {
            int mod_num = mp.KeyCount;
            Rect baseRect = pv.InsideRect(this.winRect);
            Rect headerRect = new Rect(baseRect.x, baseRect.y, baseRect.width, pv.Line("H3"));
            Rect scrollRect = new Rect(baseRect.x, baseRect.y + headerRect.height + pv.Margin
                                      ,baseRect.width + pv.PropPx(5), baseRect.height - headerRect.height - pv.Margin);
            Rect conRect = new Rect(0, 0 ,scrollRect.width - pv.Sys_("HScrollBar.Width") - pv.Margin , 0);
            Rect outRect = new Rect();
            GUIStyle lStyle = "label";
            GUIStyle tStyle = "toggle";
            Color color = new Color(1f, 1f, 1f, 0.98f);

            for (int i=0; i<mod_num; i++) 
            {
                string key = mp.sKey[i];

                if (mp.CantDisable.Contains(key)) mp.bEnabled[key] = true;
                if (checkWS(key)) mp.bEnabled[key] = false;

                conRect.height += pv.Line("H1");
                if(mp.sType[key] != "toggle" && mp.bEnabled[key])
                { 
                    for (int j=0; j<mp.ValCount(key); j++) conRect.height += pv.Line("H1");
                    conRect.height += pv.Margin * 2;
                }
                else conRect.height += pv.Margin;
            }

            lStyle.normal.textColor = color;
            tStyle.normal.textColor = color;
            lStyle.fontSize = pv.Font("H3");
            drawWinHeader(headerRect, "Mods Slider", lStyle);

            // スクロールビュー
            scrollViewVector = GUI.BeginScrollView(scrollRect, scrollViewVector, conRect);

            // 各modスライダー
            outRect.Set(0, 0, conRect.width, 0);
            for (int i=0; i<mod_num; i++)
            {
                string key = mp.sKey[i];

                //----
                outRect.width = conRect.width;
                outRect.height  = pv.Line("H1");
                color = (mp.bEnabled[key]) ? new Vector4(1f, 1f, 1f, 0.98f) : new Vector4(0.8f, 0.8f, 0.8f, 0.8f);
                lStyle.normal.textColor = color;
                tStyle.normal.textColor = color;
                
                if (mp.CantDisable.Contains(key) || checkWS(key))  // ON/OFFフラグの無いmodとWIDESLIDER無効化状態でのWS必須modはトグル非表示
                {
                    string s = mp.sDescription[key]+" ("+key+")";
                    lStyle.fontSize = pv.Font("H1");
                    if (checkWS(key))
                    {
                        s = "WIDESLIDER必須:" + s;
                        lStyle.normal.textColor = new Vector4(0.8f, 0.1f, 0.1f, 0.9f);

                    }
                    GUI.Label(outRect, s, lStyle);
                }
                else
                {
                    tStyle.fontSize = pv.Font("H1");
                    mp.bEnabled[key] = GUI.Toggle(outRect, mp.bEnabled[key], mp.sDescription[key]+" ("+key+")", tStyle);
                }
                outRect.y += outRect.height;

                if (mp.sType[key] == "toggle" || !mp.bEnabled[key]) 
                {
                    outRect.y += pv.Margin;
                    continue;
                }
                //----

                int val_num = mp.ValCount(key);
                for (int j=0; j<val_num; j++)
                {
                    string prop = mp.sPropName[key][j];
                    
                    float value = mp.fValue[key][prop];
                    float vmin = mp.fVmin[key][prop];
                    float vmax = mp.fVmax[key][prop];
                    string label = mp.sLabel[key][prop] +" : "+ value.ToString("F");
                    string vType = mp.sVType[key][prop];

                    outRect.width = conRect.width;
                    outRect.height  = pv.Line("H1");
                    lStyle.fontSize = pv.Font("H1");
                    if (value < vmin) value = vmin;
                    if (value > vmax) value = vmax;
                    if (vType == "scale" && vmin < 1f)
                    {
                        if (vmin < 0f) vmin = 0f;
                        if (value < 0f) value = 0f;

//.........这里部分代码省略.........
开发者ID:k8PzhOFo0,项目名称:CM3D2.AddModsSlider.Plugin,代码行数:101,代码来源:CM3D2.AddModsSlider.Plugin.cs

示例11: ResizeTopPane

    /// <summary>
    ///   Handles the split window stuff, somewhat bodgily
    /// </summary>
    private void ResizeTopPane()
    {
        //Set up the resize collision rect
        CursorChangeRect = new Rect(0, CurrentTopPaneHeight, position.width, DividerHeight);

        var oldColor = GUI.color;
        GUI.color = SizerLineColour;
        GUI.DrawTexture(CursorChangeRect, EditorGUIUtility.whiteTexture);
        GUI.color = oldColor;
        EditorGUIUtility.AddCursorRect(CursorChangeRect,MouseCursor.ResizeVertical);

        if( Event.current.type == EventType.mouseDown && CursorChangeRect.Contains(Event.current.mousePosition))
        {
            Resize = true;
        }

        //If we've resized, store the new size and force a repaint
        if(Resize)
        {
            CurrentTopPaneHeight = Event.current.mousePosition.y;
            CursorChangeRect.Set(CursorChangeRect.x,CurrentTopPaneHeight,CursorChangeRect.width,CursorChangeRect.height);
            Repaint();
        }

        if(Event.current.type == EventType.MouseUp)
            Resize = false;

        CurrentTopPaneHeight = Mathf.Clamp(CurrentTopPaneHeight, 100, position.height-100);
    }
开发者ID:bbbscarter,项目名称:UberLogger,代码行数:32,代码来源:UberLoggerEditorWindow.cs

示例12: windowFunction

    void windowFunction(int windowID)
    {
        Layer[] layers = LayerManager.Layers.ToArray();

        scrollViewVector = GUI.BeginScrollView(layerSelectorRect, scrollViewVector, new Rect(layerSelectorRect.x, layerSelectorRect.y, layerSelectorRect.width, layers.Length*(30 + PADDING) + 20));

        Rect position = new Rect();
        for (int i = 0; i < layers.Length; i++) {
            position.Set (PADDING, i*30 + i*PADDING + 20, layerSelectorRect.width - 30 - PADDING*5, 30);
            if (GUI.Button(position, LayerManager.Layers.ElementAt(i).Name)) {
                toggleLayer(i);
            }
            position.Set (position.x + position.width + PADDING, position.y, 30, 30);
            fillTexture(colorTex, new Color(layers[i].Color.r, layers[i].Color.g, layers[i].Color.b, 1f), (BoxManager.DisplayLayer & (1 << i)) == 0);
            GUI.Box(position, colorTex);
        }

        GUI.EndScrollView();
    }
开发者ID:foxor,项目名称:GameOfLives,代码行数:19,代码来源:LayerSelector.cs

示例13: CreateFromTexturePacker

        public static tk2dSpriteCollectionData CreateFromTexturePacker(tk2dSpriteCollectionSize spriteCollectionSize, string texturePackerFileContents, Texture texture)
        {
            List<string> list = new List<string>();
            List<Rect> list2 = new List<Rect>();
            List<Rect> list3 = new List<Rect>();
            List<Vector2> list4 = new List<Vector2>();
            List<bool> list5 = new List<bool>();
            int num = 0;
            TextReader reader = new StringReader(texturePackerFileContents);
            bool item = false;
            bool flag2 = false;
            string str = string.Empty;
            Rect rect = new Rect();
            Rect rect2 = new Rect();
            Vector2 zero = Vector2.zero;
            Vector2 vector2 = Vector2.zero;
            for (string str2 = reader.ReadLine(); str2 != null; str2 = reader.ReadLine())
            {
                char ch;
                char ch2;
                if (str2.Length > 0)
                {
                    ch = str2[0];
                    switch (num)
                    {
                        case 0:
                            ch2 = ch;
                            switch (ch2)
                            {
                                case 'h':
                                    goto Label_00DE;

                                case 'i':
                                {
                                    continue;
                                }
                            }
                            if (ch2 == 'w')
                            {
                                zero.x = int.Parse(str2.Substring(2));
                            }
                            else if (ch2 == '~')
                            {
                                goto Label_00F8;
                            }
                            break;

                        case 1:
                            goto Label_0108;
                    }
                }
                continue;
            Label_00DE:
                zero.y = int.Parse(str2.Substring(2));
                continue;
            Label_00F8:
                num++;
                continue;
            Label_0108:
                ch2 = ch;
                switch (ch2)
                {
                    case 'n':
                    {
                        str = str2.Substring(2);
                        continue;
                    }
                    case 'o':
                    {
                        string[] strArray2 = str2.Split(new char[0]);
                        rect2.Set((float) int.Parse(strArray2[1]), (float) int.Parse(strArray2[2]), (float) int.Parse(strArray2[3]), (float) int.Parse(strArray2[4]));
                        flag2 = true;
                        continue;
                    }
                    case 'r':
                    {
                        item = int.Parse(str2.Substring(2)) == 1;
                        continue;
                    }
                    case 's':
                    {
                        string[] strArray = str2.Split(new char[0]);
                        rect.Set((float) int.Parse(strArray[1]), (float) int.Parse(strArray[2]), (float) int.Parse(strArray[3]), (float) int.Parse(strArray[4]));
                        continue;
                    }
                }
                if (ch2 == '~')
                {
                    list.Add(str);
                    list5.Add(item);
                    list2.Add(rect);
                    if (!flag2)
                    {
                        if (item)
                        {
                            rect2.Set(0f, 0f, rect.height, rect.width);
                        }
                        else
                        {
                            rect2.Set(0f, 0f, rect.width, rect.height);
//.........这里部分代码省略.........
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:101,代码来源:SpriteCollectionGenerator.cs

示例14: drawLoadMenu

    /// <summary>
    /// Draws the load menu.
    /// </summary>
    /// <param name="originPosition">Origin position.</param>
    void drawLoadMenu(Rect originPosition)
    {
        //originPosition.
                //TODO: load in the current saves
                originPosition.Set (originPosition.x + defaultButtonWidth, originPosition.y, defaultButtonWidth, defaultButtonHeight);
                // This will warp the player to the home base scene
                //how many saves determine how many buttons there are
                if (GUI.Button (originPosition, "Save 1")) {
                        //Application.LoadLevel ("HomeBase");

                }
    }
开发者ID:tzfyb,项目名称:DeepSpaceMine,代码行数:16,代码来源:UI.cs

示例15: UpdateTransform

    private void UpdateTransform()
    {
        if (this.AnchorCamera != null)
        {
            float sizeAtDistance = 1f;
            Vector3 localPosition = this.myTransform.localPosition;
            tk2dCamera camera = ((this.AnchorTk2dCamera == null) || (this.AnchorTk2dCamera.CameraSettings.projection == tk2dCameraSettings.ProjectionType.Perspective)) ? null : this.AnchorTk2dCamera;
            Rect rect = new Rect();
            if (camera != null)
            {
                rect = !this.anchorToNativeBounds ? camera.ScreenExtents : camera.NativeScreenExtents;
                sizeAtDistance = camera.GetSizeAtDistance(1f);
            }
            else
            {
                rect.Set(0f, 0f, this.AnchorCamera.pixelWidth, this.AnchorCamera.pixelHeight);
            }
            float yMin = rect.yMin;
            float yMax = rect.yMax;
            float y = (yMin + yMax) * 0.5f;
            float xMin = rect.xMin;
            float xMax = rect.xMax;
            float x = (xMin + xMax) * 0.5f;
            Vector3 zero = Vector3.zero;
            switch (this.AnchorPoint)
            {
                case tk2dBaseSprite.Anchor.LowerLeft:
                    zero = new Vector3(xMin, yMin, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.LowerCenter:
                    zero = new Vector3(x, yMin, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.LowerRight:
                    zero = new Vector3(xMax, yMin, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.MiddleLeft:
                    zero = new Vector3(xMin, y, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.MiddleCenter:
                    zero = new Vector3(x, y, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.MiddleRight:
                    zero = new Vector3(xMax, y, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.UpperLeft:
                    zero = new Vector3(xMin, yMax, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.UpperCenter:
                    zero = new Vector3(x, yMax, localPosition.z);
                    break;

                case tk2dBaseSprite.Anchor.UpperRight:
                    zero = new Vector3(xMax, yMax, localPosition.z);
                    break;
            }
            Vector3 position = zero + new Vector3(sizeAtDistance * this.offset.x, sizeAtDistance * this.offset.y, 0f);
            if (camera == null)
            {
                Vector3 vector4 = this.AnchorCamera.ScreenToWorldPoint(position);
                if (this.myTransform.position != vector4)
                {
                    this.myTransform.position = vector4;
                }
            }
            else if (this.myTransform.localPosition != position)
            {
                this.myTransform.localPosition = position;
            }
        }
    }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:77,代码来源:tk2dCameraAnchor.cs


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