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


C# Texture2D.SetPixel方法代码示例

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


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

示例1: makeOutline

    public void makeOutline(string tag)
    {
        this.tag = tag;

        int resolution = 256;
        int lineThickness = 5;
        wireTexture = new Texture2D(resolution, resolution);
        for (int i = 0; i < resolution; i++)
        {
            for (int j = 0; j < resolution; j++)
            {
                wireTexture.SetPixel(i, j, Color.clear);
                if (i < lineThickness || j < lineThickness || i > (resolution - 1) - lineThickness || j > (resolution-1) - lineThickness)
                {
                    if(tag == "Input")
                    {
                        wireTexture.SetPixel(i, j, Color.blue);
                    }
                    else if(tag == "Output")
                    {
                        wireTexture.SetPixel(i, j, Color.red);
                    }
                    else
                    {
                        wireTexture.SetPixel(i, j, Color.green);
                    }
                }
            }
        }
        wireTexture.Apply();
    }
开发者ID:jnguye14,项目名称:GATETutor,代码行数:31,代码来源:DataCell.cs

示例2: Start

 void Start()
 {
     // Calculates the size of the current screen
     float screenHeight = Camera.main.orthographicSize;
     float screenRatioXtoY = (float)Screen.width / (float)Screen.height;
     float actualScreenWidth = (screenRatioXtoY * 2f * screenHeight);
     // Scales the background
     transform.localScale = new Vector3(actualScreenWidth/10, 1f, screenHeight/5);
     // Sets up the button size w.r.t. the actual screen
     buttonWidth = Screen.width / 4;
     buttonHeight = Screen.height / 16;
     // Resizes button and colors it
     int borderSize = 5;
     Color32 borderColor = new Color32(168, 29, 29, 255);
     resizedButton = new Texture2D(Screen.width / 3, Screen.height / 8);
     for (int x = 0; x <= resizedButton.width; x++)
     {
         for (int y = 0; y <= resizedButton.height; y++)
         {
             if (x < borderSize || y < borderSize || x > resizedButton.width - borderSize || y > resizedButton.height - borderSize)
             {
                 resizedButton.SetPixel(x, y, borderColor);
             }
             else
             {
                 resizedButton.SetPixel(x, y, Color.yellow);
             }
         }
     }
     resizedButton.Apply();
 }
开发者ID:weasel8,项目名称:SuperRaccoon,代码行数:31,代码来源:Credits.cs

示例3: OnImageLoad

    public void OnImageLoad(string imgPath, Texture2D tex)
    {
        Data.Instance.SetRoomFromLocalFiles(true);

        float currAspect = Screen.currentResolution.width * 0.8f / Screen.currentResolution.height;
        float texAspect = tex.width / tex.height;
        if (texAspect > currAspect) {
            Texture2D result = new Texture2D ((int)(tex.width * 1.2f), (int)(tex.height * 1.2f), tex.format, true);
            for (int y = 0; y < result.height; y++) {
                for (int x = 0; x < result.width; x++) {
                    if (y > (result.height * 0.1f) && y < (result.height * 0.9f) && x > (result.width * 0.1f) && x < (result.width * 0.9f)) {
                        result.SetPixel (x, y, tex.GetPixel (x - (int)(tex.width * 0.1f), y - (int)(tex.height * 0.1f)));
                    } else {
                        result.SetPixel (x, y, Color.black);
                    }
                }
            }
            result.Apply ();
            Data.Instance.lastPhotoTexture = result;
        } else {
            Data.Instance.lastPhotoTexture = tex;
        }

        Data.Instance.LoadLevel("ConfirmPhoto");
    }
开发者ID:pontura,项目名称:ArtPlacer,代码行数:25,代码来源:Rooms.cs

示例4: Update

	// Update is called once per frame
	void Update () 
	{
		if(mGen == null)
			mGen = FindObjectOfType<MazeGenerator>();
		else if(m == null && mGen != null)
		{
			m = mGen.currentMaze();
			if(m != null)
			{
				Texture2D t = new Texture2D((int)m.Dimensions().x, (int)m.Dimensions().y, TextureFormat.ARGB4444, false);
				for(int x=0; x<t.width; x++)
				{
					for(int y=0; y<t.height; y++)
					{
						if(m.GetCell(x,y).isWall)
							t.SetPixel(x,y,Color.black);
						else
							t.SetPixel(x,y,Color.white);
					}
				}
				t.anisoLevel = 0;
				t.filterMode = FilterMode.Point;
				t.Apply();
				im.sprite = Sprite.Create(t, new Rect(0,0,t.width,t.height), Vector2.one/2);
			}
		}
	}
开发者ID:Blueteak,项目名称:MazeWar,代码行数:28,代码来源:MiniMap.cs

示例5: DoDrawTextureCircle

        public void DoDrawTextureCircle(Texture2D tex, int cx, int cy, int r, Color col)
        {
            //Color32 _col = (Color32)col;

               int x, y, px, nx, py, ny, d;

              // Color32[] tempArray = tex.GetPixels32();

               for (x = 0; x <= r; x++)
               {
             d = (int)Mathf.Ceil(Mathf.Sqrt(r * r - x * x));
             for (y = 0; y <= d; y++)
             {
              px = cx + x;
              nx = cx - x;
              py = cy + y;
              ny = cy - y;

             tex.SetPixel(px, py, col);
              	tex.SetPixel(nx, py, col);

             	 tex.SetPixel(px, ny, col);
             	 tex.SetPixel(nx, ny, col);

             // tempArray[py*1024 + px] = _col;
             // tempArray[py*1024 + nx] = _col;
             // tempArray[ny*1024 + px] = _col;
               //   tempArray[ny*1024 + nx] = _col;
             }
               }
             //  tex.SetPixels32(tempArray);
               tex.Apply ();
        }
开发者ID:ironicnet,项目名称:PlayMakerCustomActions_U3,代码行数:33,代码来源:TextureDrawCircle.cs

示例6: OnRenderImage

        public void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            CheckResources();
            originalTex = new Texture2D(source.width, source.height);

            // change texture. every white pixel should be transparent after this
            int y = 0;
            while (y < originalTex.height)
            {
                int x = 0;
                while (x < originalTex.width)
                {
                    Color colorAtPixel = new Color();
                    colorAtPixel = originalTex.GetPixel(x, y);
                    if (colorAtPixel[0] == 1 && colorAtPixel[1] == 1 && colorAtPixel[2] == 1 && colorAtPixel[3] == 1)
                    {
                        originalTex.SetPixel(x, y, Color.clear);
                    }
                    else
                    {
                        originalTex.SetPixel(x, y, new Color(colorAtPixel[0], colorAtPixel[1], colorAtPixel[2], colorAtPixel[3] ));
                    }
                    ++x;
                }
                ++y;
            }
            originalTex.Apply();

            transparentMaterial.SetTexture("_MainTex", originalTex);

            Graphics.Blit(source, destination, transparentMaterial, 0);
        }
开发者ID:unia-intsim-ws1516,项目名称:group07-tran-stifter,代码行数:32,代码来源:MakeWhiteTransparent.cs

示例7: Render

        public Texture2D Render(bool active, float scale)
        {
            float radius = Radius * scale;
            int side = (int)radius * 2;
            var tex = new Texture2D(side, side);
            tex.hideFlags = HideFlags.HideAndDontSave;
            tex.filterMode = FilterMode.Point;

            // Top right quadrant
            for (int x = 0; x < side; x++) {
                for (int y = 0; y < side; y++) {
                    float xSqr = Mathf.Pow(x - radius, 2);
                    float ySqr = Mathf.Pow(y - radius, 2);

                    float radOutlineSqr = Mathf.Pow(radius, 2);
                    float radiusOutline = radius - Outline * scale;
                    float radSqr = Mathf.Pow(radiusOutline, 2);

                    if (xSqr + ySqr < radSqr) {
                        if (active) {
                            tex.SetPixel(x, y, _AntiAlias(xSqr, ySqr, radSqr, radius, _mainActiveColor, _outlineColor));
                        } else {
                            tex.SetPixel(x, y, _AntiAlias(xSqr, ySqr, radSqr, radius, _mainColor, _outlineColor));
                        }
                    } else if (xSqr + ySqr < radOutlineSqr) {
                        tex.SetPixel(x, y, _AntiAlias(xSqr, ySqr, radOutlineSqr, radiusOutline, _outlineColor, _clearColor));
                    } else {
                        tex.SetPixel(x, y, _clearColor);
                    }
                }
            }

            tex.Apply();
            return tex;
        }
开发者ID:BrettRToomey,项目名称:forge,代码行数:35,代码来源:OutletRenderer.cs

示例8: DrawRectWithOutline

        public static void DrawRectWithOutline( Rect rect, Color color, Color colorOutline )
        {
            #if UNITY_EDITOR
            Vector3[] rectVerts = { new Vector3(rect.x, rect.y, 0),
                new Vector3(rect.x + rect.width, rect.y, 0),
                new Vector3(rect.x + rect.width, rect.y + rect.height, 0),
                new Vector3(rect.x, rect.y + rect.height, 0) };
            Handles.DrawSolidRectangleWithOutline(rectVerts, color, colorOutline);
            #else
            Texture2D texture = new Texture2D(1, 1);
            texture.SetPixel(0,0,colorOutline);
            texture.Apply();

            Rect rLine = new Rect( rect.x, rect.y, rect.width, 1 );
            GUI.DrawTexture(rLine, texture);
            rLine.y = rect.y + rect.height - 1;
            GUI.DrawTexture(rLine, texture);
            rLine = new Rect( rect.x, rect.y+1, 1, rect.height-2 );
            GUI.DrawTexture(rLine, texture);
            rLine.x = rect.x + rect.width - 1;
            GUI.DrawTexture(rLine, texture);

            rect.x += 1;
            rect.y += 1;
            rect.width -= 2;
            rect.height -= 2;
            texture.SetPixel(0,0,color);
            texture.Apply();
            GUI.DrawTexture(rect, texture);
            #endif
        }
开发者ID:JumberlackCoding,项目名称:TopDownRPG,代码行数:31,代码来源:UtilsGuiDrawing.cs

示例9: DrawLine

    public static void DrawLine(Vector2 start, Vector2 end, Color acolor, float width, bool abool = false)
    {
        Color GUIcolor = GUI.color;
        GUI.color = acolor;
        if (!lineTex)
        {
            lineTex = new Texture2D(1, 1, TextureFormat.ARGB32, true);
            lineTex.SetPixel(1, 1, Color.white);
            lineTex.Apply();
        }
        if (!aaLineTex)
        {
            aaLineTex = new Texture2D(1, 3, TextureFormat.ARGB32, true);
            aaLineTex.SetPixel(0, 0, new Color(1, 1, 1, 0));
            aaLineTex.SetPixel(0, 1, Color.white);
            aaLineTex.SetPixel(0, 2, new Color(1, 1, 1, 0));
            aaLineTex.Apply();
        }
        Vector2 d = end - start;
        float a = Mathf.Rad2Deg * Mathf.Atan(d.y / d.x);
        if (d.x < 0)
            a += 180;

        int width2 = (int)Mathf.Ceil(width / 2);

        GUIUtility.RotateAroundPivot(a, start);
        GUI.DrawTexture(new Rect(start.x, start.y - width2, d.magnitude, width), lineTex);
        GUIUtility.RotateAroundPivot(-a, start);
        GUI.color = GUIcolor;
    }
开发者ID:Xangotrick,项目名称:CYGNUS,代码行数:30,代码来源:Drawing.cs

示例10: DrawConnection

 public static void DrawConnection(Vector2 ptA, Vector2 ptB, Color color, float width)
 {
     float iA = Vector2.Angle(ptA, ptB);
     Color savedColor = GUI.color;
     Matrix4x4 savedMatrix = GUI.matrix;
     Vector2 rectPtA = new Vector2(ptA.x, Screen.height - ptA.y);
     float angle = (ptB.y < rectPtA.y) ? -Vector2.Angle(ptB - rectPtA, Vector2.right) : Vector2.Angle(ptB - rectPtA, Vector2.right);
     GUIUtility.RotateAroundPivot(angle, rectPtA);
     float mag = (ptB - rectPtA).magnitude;
     Texture2D lineTex = new Texture2D(128, 128);
     for(int i = 0; i < lineTex.width; ++i)
     {
         //
         for(int j = 0; j < lineTex.height/2; ++j)
         {
             lineTex.SetPixel(i, j, new Color(j, j, j, 1f));
         }
         for (int j = lineTex.height / 2; j < lineTex.height; ++j)
         {
             lineTex.SetPixel(i, j, new Color(lineTex.height - j, lineTex.height - j, lineTex.height - j, 1f));
         }
     }
     lineTex.Apply();
     GUI.DrawTexture(new Rect(ptA.x, rectPtA.y, mag, width), lineTex);
     GUI.color = savedColor;
     GUI.matrix = savedMatrix;
 }
开发者ID:Skoth,项目名称:KSPCommEngr,代码行数:27,代码来源:GLUtils.cs

示例11: pick

    public static Texture2D pick(int[,] pPatternMark,int pPickPatternID,
        Texture2D pSource, zzPointBounds pBounds, zzPoint pOutSize)
    {
        Texture2D lOut = new Texture2D(pOutSize.x, pOutSize.y, TextureFormat.ARGB32, false);
        var lMin = pBounds.min;
        var lMax = pBounds.max;
        var lDrawOffset = -lMin;
        for (int lY = lMin.y; lY < lMax.y; ++lY)
        {
            var lDrawedPointY = lY + lDrawOffset.y;
            for (int lX = lMin.x; lX < lMax.x; ++lX)
            {
                var lColor = pPatternMark[lX, lY] == pPickPatternID
                    ? pSource.GetPixel(lX, lY) : Color.clear;

                lOut.SetPixel(lX + lDrawOffset.x, lDrawedPointY, lColor);
            }
            for (int i = lMax.x+lDrawOffset.x; i < lOut.width; ++i)
            {
                lOut.SetPixel(i, lDrawedPointY, Color.clear);
            }
        }
        for (int lY = lMax.y + lDrawOffset.y; lY < lOut.height; ++lY)
        {
            for (int lX = 0; lX < lOut.width; ++lX)
                lOut.SetPixel(lX, lY, Color.clear);
        }
        lOut.Apply();
        return lOut;
    }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:30,代码来源:zzImagePatternPicker.cs

示例12: ProgressUpdate

 public static Texture2D ProgressUpdate(Texture2D tex, float progress, Color overlayColor)
 {
     progress = 1-progress;
     Texture2D thisTex = new Texture2D(tex.width, tex.height);
     Vector2 centre = new Vector2(Mathf.Ceil(thisTex.width/2), Mathf.Ceil(thisTex.height/2)); //find the centre pixel
     for(int y = 0; y < thisTex.height; y++){
         for(int x = 0; x < thisTex.width; x++){
             float angle = Mathf.Atan2(x-centre.x, y-centre.y)*Mathf.Rad2Deg*-1; //find the angle between the centre and this pixel (between -180 and 180)
             if(angle < 0){
                 angle += 360; //change angles to go from 0 to 360
             }
             Color pixColor = tex.GetPixel(x, y);
             if(angle <= progress*360.0){ //if the angle is less than the progress angle blend the overlay colour
                 pixColor = new Color(
                     (pixColor.r*pixColor.a*(1-overlayColor.a))+(overlayColor.r*overlayColor.a),
                     (pixColor.g*pixColor.a*(1-overlayColor.a))+(overlayColor.g*overlayColor.a),
                     (pixColor.b*pixColor.a*(1-overlayColor.a))+(overlayColor.b*overlayColor.a)
                     );
                 thisTex.SetPixel(x, y, pixColor);
             }else{
                 thisTex.SetPixel(x, y, pixColor);
             }
         }
     }
     thisTex.Apply(); //apply the cahnges we made to the texture
     return thisTex;
 }
开发者ID:yakolla,项目名称:MarineVsAlien,代码行数:27,代码来源:Cooldown.cs

示例13: DrawLine

    public static void DrawLine(Point2D tFrom, Point2D tTo, Texture2D texture)
    {
        //Debug.Log ("Drawing from: " + tFrom.x + "," + tFrom.y + "  to  " + tTo.x + "," + tTo.y);

        int deltaX = tFrom.x - tTo.x;
        int deltaY = tFrom.y - tTo.y;

        int d = 2*deltaY - deltaX;

        texture.SetPixel(tFrom.x,tFrom.y,Color.black);

        int y = tFrom.y;

        for(int x = tFrom.x + 1; x< tTo.x; x+=1)
        {
            if(d > 0)
            {
                y+=1;
                //Debug.Log (x + " " + y);
                texture.SetPixel(x,y,Color.black);
                d+=(2*deltaY)-(2*deltaX);
            }
            else
            {
                //Debug.Log (x + " " + y);
                texture.SetPixel(x,y,Color.black);
                d+=(2*deltaY);
            }
        }
        texture.Apply();
    }
开发者ID:Fizzly,项目名称:MMesh,代码行数:31,代码来源:RenderUtility.cs

示例14: Start

 void Start()
 {
     texture = new Texture2D(1, 1);
     texture.SetPixel(1, 1, greenColor);
     background = new Texture2D(1,1);
     texture.SetPixel (1,1,grayColor);
 }
开发者ID:GarageGamingIndustries,项目名称:UnityGame,代码行数:7,代码来源:Healthbar.cs

示例15: CreateTexture

    public static Texture2D CreateTexture()
    {
        Texture2D texToReturn = new Texture2D(Width, Height, TextureFormat.ARGB32, false);

        for (int i=0; i<Width; i++)
        {
            for (int j=0; j<Height; j++)
            {
                if (i == 0 || i == 1 || j == 0 || j == 1 || i == Width-1 || i == Width-2 || j == Height-1 || j == Height-2 || j == Height-HealthHeight)
                {
                    texToReturn.SetPixel (i, j, BorderColour);
                }
                else if (j > Height-HealthHeight)
                {
                    //texToReturn.SetPixel (i, j, HealthColour);
                }
                else
                {
                    texToReturn.SetPixel (i, j, Color.clear);
                }
            }
        }
        texToReturn.Apply ();
        return texToReturn;
    }
开发者ID:SexySicilianSoprano,项目名称:thegreatdeepblue,代码行数:25,代码来源:Overlays.cs


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