SetPixel() public method

Sets pixel color at coordinates (x,y).

public SetPixel ( int x, int y, Color color ) : void
x int
y int
color Color
return void
コード例 #1
0
        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 ();
        }
コード例 #2
0
        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
        }
コード例 #3
0
    private Texture2D MakePicture(int textureSize)
    {
        var generatedtTexture = new Texture2D(textureSize, textureSize, TextureFormat.ARGB32, false);
        var halftexture = generatedtTexture.height / 2;
        var transparentColor = new Color(0, 0, 0, 0);
        float sqrRadius = halftexture * halftexture;

        for (int horiz = 0; horiz < textureSize; ++horiz)
        {
            for (int vert = 0; vert < textureSize; ++vert)
            {
                if (((vert - halftexture) * (vert - halftexture) + (horiz - halftexture) * (horiz - halftexture)) < sqrRadius)
                {
                    if (Mathf.Abs((vert - halftexture) * (vert - halftexture) -(horiz - halftexture)) <= 2
                        || Mathf.Abs((horiz - halftexture) * (horiz - halftexture) - (vert - halftexture))<= 2)
                        generatedtTexture.SetPixel(horiz, vert, Color.black);
                    else
                        generatedtTexture.SetPixel(horiz, vert, Color.white);
                }
                else
                    generatedtTexture.SetPixel(horiz, vert, transparentColor);
            }
        }
        generatedtTexture.Apply();
        return generatedtTexture;
    }
コード例 #4
0
ファイル: OutletRenderer.cs プロジェクト: BrettRToomey/forge
        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;
        }
コード例 #5
0
    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;
    }
コード例 #6
0
        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);
        }
コード例 #7
0
    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;
    }
コード例 #8
0
    void OnWizardCreate()
    {
        int potWidth = 1;

        while (potWidth < frameWidth * frames)
            potWidth *= 2;

        int potHeight = 1;

        while (potHeight < frameHeight)
            potHeight *= 2;

        Texture2D texture = new Texture2D(potWidth, potHeight);

        for (int i = 0; i < frameWidth * frames; i++)
        {
            for (int j = 0; j < frameHeight; j++)
            {
                if (i % frameWidth == 0 || i % frameWidth == frameWidth - 1 ||
                    j == 0 || j == frameHeight - 1)
                    texture.SetPixel(i, j, gridColor);
                else texture.SetPixel(i, j, backColor);
            }
        }

        File.WriteAllBytes(AssetDatabase.GetAssetPath(Selection.activeObject) +
            "/" + textureName + ".png", texture.EncodeToPNG());

        AssetDatabase.Refresh();
    }
コード例 #9
0
 void Start()
 {
     texture = new Texture2D(1, 1);
     texture.SetPixel(1, 1, greenColor);
     background = new Texture2D(1,1);
     texture.SetPixel (1,1,grayColor);
 }
コード例 #10
0
ファイル: QRcodeCreater.cs プロジェクト: Cabris/unity_lab
    public void CreateCode(string code)
    {
        int QRwidth = 256; // 圖形寬
        int QRheight = 256; //圖形高
        QRCodeWriter writer=new QRCodeWriter();
        BitMatrix bm = writer.encode(code, BarcodeFormat.QR_CODE, QRwidth, QRheight);
        Texture2D t2d=new Texture2D(QRwidth,QRheight);
        r.material.mainTexture=t2d;

        int width = bm.Width;
        int height = bm.Height;

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                //bm.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("Red") : ColorTranslator.FromHtml("Yellow");
                if(bm[x, y]){
                    t2d.SetPixel(x, y,Color.black);
                }else{
                    t2d.SetPixel(x, y,Color.white);
                }
            }
        }
        t2d.Apply();
    }
コード例 #11
0
ファイル: GLUtils.cs プロジェクト: Skoth/KSPCommEngr
 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;
 }
コード例 #12
0
	private Texture2D getTexture(float alph){

		float alpha = Mathf.Clamp01 (alph);

		if (textureForMaterial == null || lastAlpha  != alpha) {

			lastAlpha = alpha;

			textureForMaterial = new Texture2D (400,400);
		
			int borderWidth = 5;
			Color bordercolor = new Color(103f/255f, 230f/255f, 236f/255f, alpha);


			for (int x = 0; x < textureForMaterial.width; x++) {

				for (int y = 0; y < textureForMaterial.height; y++) {

					if ((x < borderWidth || x > textureForMaterial.width - borderWidth) || (y < borderWidth || y > textureForMaterial.height - borderWidth)) {
						textureForMaterial.SetPixel (x, y, bordercolor);
					} else {
						textureForMaterial.SetPixel (x, y, Color.clear);
					}

				}

			}

			textureForMaterial.Apply ();

		}

		return textureForMaterial;

	}
コード例 #13
0
ファイル: Credits.cs プロジェクト: weasel8/SuperRaccoon
 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();
 }
コード例 #14
0
ファイル: DataCell.cs プロジェクト: jnguye14/GATETutor
    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();
    }
コード例 #15
0
ファイル: Drawing.cs プロジェクト: Xangotrick/CYGNUS
    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;
    }
コード例 #16
0
ファイル: Point.cs プロジェクト: kirkor93/TSK
 private void CreateSprite(Color pointColor)
 {
     Texture2D tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
     tex.SetPixel(0, 0, new Color(1.0f, 1.0f, 1.0f, 1.0f));
     tex.SetPixel(0, 0, pointColor);
     _sprite = Sprite.Create(tex, new Rect(Vector2.zero, Vector2.one), Vector2.one * 0.5f);
 }
コード例 #17
0
 private static Texture2D CreateCheckerTex(Color c0, Color c1)
 {
   Texture2D texture2D = new Texture2D(16, 16);
   texture2D.name = "[Generated] Checker Texture";
   texture2D.hideFlags = HideFlags.DontSave;
   for (int y = 0; y < 8; ++y)
   {
     for (int x = 0; x < 8; ++x)
       texture2D.SetPixel(x, y, c1);
   }
   for (int y = 8; y < 16; ++y)
   {
     for (int x = 0; x < 8; ++x)
       texture2D.SetPixel(x, y, c0);
   }
   for (int y = 0; y < 8; ++y)
   {
     for (int x = 8; x < 16; ++x)
       texture2D.SetPixel(x, y, c0);
   }
   for (int y = 8; y < 16; ++y)
   {
     for (int x = 8; x < 16; ++x)
       texture2D.SetPixel(x, y, c1);
   }
   texture2D.Apply();
   texture2D.filterMode = UnityEngine.FilterMode.Point;
   return texture2D;
 }
コード例 #18
0
ファイル: MiniMap.cs プロジェクト: Blueteak/MazeWar
	// 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);
			}
		}
	}
コード例 #19
0
ファイル: Cooldown.cs プロジェクト: yakolla/MarineVsAlien
 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;
 }
コード例 #20
0
ファイル: Rooms.cs プロジェクト: pontura/ArtPlacer
    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");
    }
コード例 #21
0
ファイル: RenderUtility.cs プロジェクト: Fizzly/MMesh
    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();
    }
コード例 #22
0
    public void initiate(PuzzlePieceInfo piece, Texture2D outLine, Texture2D theImage)
    {
        if(!initiated)
        {
            //set object's texture to puzzle-piece shaped highlight
            Color mainImageColor;

            //Set Up
            myPuzzlePiece = new PuzzlePieceInfo();
            puzzleOutline = outLine;
            mainImageTexture = theImage;
            myPuzzlePiece = piece;

        //		Debug.Log(pictureTexture.width);
        //		Debug.Log(pictureTexture.height);
        //
        //		Debug.Log("w "+outLine.width);
        //		Debug.Log("h "+outLine.height);

            //Where does the texture start..
            int initX = myPuzzlePiece.uvX;
            int initY = myPuzzlePiece.uvY;

            //How much of the texture will be shown (uv rect)
            float textureWidth = myPuzzlePiece.uvWidth;
            float textureHeight = myPuzzlePiece.uvHeight;

            myColor = myPuzzlePiece.myColor;

            //New "Canvas" to paint on
            myTexture = new Texture2D((int)textureWidth, (int)textureHeight);

            //Clears any other color that it is not its own
            for(int y = initY; y < initY + textureHeight; y++){
                for(int x = initX; x < initX + textureWidth; x++){

                    //if pixel is not the piece's color, clear it
                    if(puzzleOutline.GetPixel(x,y) != myColor) {
                        myTexture.SetPixel(x-initX,y-initY,Color.clear);
                    }
                    else{
                        mainImageColor = mainImageTexture.GetPixel(x,y);
                        myTexture.SetPixel(x-initX, y-initY, mainImageColor);
                    }
                }
            }

            //Commit changes to texture and apply it
            myTexture.wrapMode = TextureWrapMode.Clamp;
            myTexture.Apply();
            myUITexture.mainTexture = myTexture;

            myUITexture.enabled = false;
            initiated =true;
        }
        myUITexture.mainTexture = myTexture;
        myUITexture.enabled = false;
    }
コード例 #23
0
ファイル: BattleGUI.cs プロジェクト: LiMina/adjective-animal
		void Start ()
		{
				dialogue = playerTurnString;
				turnStateMachine = GameObject.FindGameObjectWithTag ("TurnStateMachine");

				texture = new Texture2D (16, 16);
				for (int y = 0; y < texture.height; ++y) {
					for (int x = 0; x < texture.width; ++x) {
						if ((x > 2 && y > 2) && (x < texture.width - 3 && y < texture.height - 3)) {
							Color color = new Color (228f / 255f, 174f / 255f, 198f / 255f, 1f);
							texture.SetPixel (x, y, color);
						} else {
							Color color = new Color (228f / 255f, 200f / 255f, 213f / 255f, 1f);
							texture.SetPixel (x, y, color);
						}
					}
				}

				promptTexture = new Texture2D (Screen.width - 50, 50);
				for (int y = 0; y < promptTexture.height; ++y) {
					for (int x = 0; x < promptTexture.width; ++x) {
						if ((x > 2 && y > 2) && (x < promptTexture.width - 3 && y < promptTexture.height - 3)) {
							Color color = new Color (228f / 255f, 125f / 255f, 171f / 255f, 1f);
							promptTexture.SetPixel (x, y, color);
						} else {
							Color color = new Color (228f / 255f, 200f / 255f, 213f / 255f, 1f);
							promptTexture.SetPixel (x, y, color);
						}
					}
				}

				buttonTexture = new Texture2D ((int)buttonWidth, (int)buttonHeight);
				for (int y = 0; y < buttonTexture.height; ++y) {
					for (int x = 0; x < buttonTexture.width; ++x) {
						if ((x > 1 && y > 1) && (x < buttonTexture.width - 2 && y < buttonTexture.height - 2)) {
							Color color = new Color (245f / 255f, 207f / 255f, 148f / 255f, 1f);
							buttonTexture.SetPixel (x, y, color);
						} else {
							Color color = new Color (254f / 255f, 234f / 255f, 174f / 255f, 1f);
							buttonTexture.SetPixel (x, y, color);
						}
					}
				}

				buttonHoverTexture = new Texture2D (Screen.width - 200, 25);
				for (int y = 0; y < buttonHoverTexture.height; ++y) {
					for (int x = 0; x < buttonHoverTexture.width; ++x) {
						if ((x > 1 && y > 1) && (x < buttonHoverTexture.width - 2 && y < buttonHoverTexture.height - 2)) {
							Color color = new Color (254f / 255f, 234f / 255f, 174f / 255f, 1f);
							buttonHoverTexture.SetPixel (x, y, color);
						} else {
							Color color = new Color (254f / 255f, 234f / 255f, 174f / 255f, 1f);
							buttonHoverTexture.SetPixel (x, y, color);
						}
					}
				}
		}
コード例 #24
0
ファイル: CustomGUI.cs プロジェクト: Hanteus/Awoken
 public static Texture2D CreateBlackTexture()
 {
     Texture2D blackTex = new Texture2D(1,2);
     blackTex.SetPixel(0, 0, Color.gray);
     blackTex.SetPixel(1, 0, Color.black);
     blackTex.Apply();
     blackTex.hideFlags = HideFlags.DontSave;
     return blackTex;
 }
コード例 #25
0
ファイル: Utils.cs プロジェクト: Meumeu/ProceduralCities
        public static Texture2D TextureFromArrayHeight(double[,] data, double minValue, double maxValue)
        {
            var colours = new GradientColorKey[] {
                RGB(176, 243, 190),
                RGB(224, 251, 178),
                RGB(184, 222, 118),
                RGB(39, 165, 42),
                RGB(52, 136, 60),
                RGB(156, 164, 41),
                RGB(248, 176, 4),
                RGB(192, 74, 2),
                RGB(135, 8, 0),
                RGB(116, 24, 5),
                RGB(108, 42, 10),
                RGB(125, 74, 43),
                RGB(156, 129, 112),
                RGB(181, 181, 181),
                RGB(218, 216, 218)
            };

            colours[0].time = 0;
            colours[1].time = 0.001f;

            for (int i = 0; i < colours.Length; i++)
            {
                colours[i].time = (float)i / (float)(colours.Length - 1);
            }

            int width = data.GetLength(0);
            int height = data.GetLength(1);

            Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    float value = Mathf.Clamp01((float)((data[x, y] - minValue) / (maxValue - minValue)));
                    if (data[x, y] <= 0)
                        tex.SetPixel(x, y, new Color(0, 0, 1));
                    else
                        for(int i = 1; i < colours.Length; i++)
                        {
                            if (value < colours[i].time)
                            {
                                float lambda = (value - colours[i - 1].time) / (colours[i].time - colours[i - 1].time);
                                tex.SetPixel(x, y, Color.Lerp(colours[i - 1].color, colours[i].color, lambda));
                                break;
                            }
                        }
                }
            }

            tex.Apply();
            return tex;
        }
コード例 #26
0
    void CreateTexture()
    {
        Texture2D texture = new Texture2D(2, 2, TextureFormat.ARGB32, false);
        //texture.SetPixel(0, 0, Color.Lerp(1.0f, 1.0f, 1.0f));
        texture.SetPixel(1, 0, Color.clear);
        texture.SetPixel(0, 1, Color.white);
        texture.SetPixel(1, 1, Color.black);

        texture.Apply();
        GetComponent<SpriteRenderer>().material.mainTexture = texture;
    }
コード例 #27
0
ファイル: WallTexture.cs プロジェクト: paulhayes/lightcycles
    void GenerateTexture()
    {
        Random.seed = seed;
        Texture2D tex = new Texture2D(size,size,TextureFormat.RGB24, false, false );
        tex.filterMode = FilterMode.Point;
        int vx = 1;
        int vy = 0;
        int x = 0;
        int y = 0;
        int nextChange = 0;
        int vxTmp = vx;

        Color[] fill = new Color[size*size];
        for(int i=size*size;i>0;i--) fill[i-1] = background;
        tex.SetPixels(fill);

        for( int i = 0; i < totalLineLength ; i++ ){
            if( i == nextChange ){
                nextChange = i + Random.Range(minLength,maxLength);
                if( Random.value < 0.5f ){
                    vxTmp = vx;
                    vx = vy;
                    vy = -vxTmp;
                }
                else {
                    vxTmp = vx;
                    vx = -vy;
                    vy = vxTmp;
                }
            }

            x+=vx;
            y+=vy;

            if( x > size ) x = 0;
            if( y > size ) y = 0;
            if( x < 0 ) x = size;
            if( y < 0 ) y = size;

            tex.SetPixel(x,y,foreground);
        }

        vx = -(int)Mathf.Sign(x);
        vy = -(int)Mathf.Sign(y);
        for( int i = Mathf.Max( x, y ); i>=0; i-- ) {
            if( x!=0 ) x+=vx;
            if( y!=0 ) y+=vy;
            tex.SetPixel(x,y,foreground);
        }

        tex.Apply();

        renderer.material.mainTexture = tex;
    }
コード例 #28
0
ファイル: Map2D.cs プロジェクト: olemstrom/the-morko
    void Draw(Map map)
    {
        IList<Room> rooms = map.GetRooms ();
        Texture2D tex = new Texture2D (map.CellCount, map.CellCount, TextureFormat.RGB24, false, true);
        Renderer rend = GetComponent<Renderer> ();
        rend.enabled = true;
        tex.filterMode = FilterMode.Point;
        tex.wrapMode = TextureWrapMode.Clamp;
        tex.DrawFilledRectangle (new Rect (0, 0, map.CellCount, map.CellCount), Color.black);

        /*foreach (Room room in rooms) {
            int height = room.GetHeight();
            int width = room.GetWidth();
            int x = room.GetX();
            int y = room.GetY();

            tex.DrawFilledRectangle (new Rect (x, y, width, height), Color.white);
        }*/

        /*
        foreach (Room room in rooms) {
            Vertex2 c = room.GetCenterPoint();
            float x = (float)scale (c.x);
            float y = (float)scale (c.y);
            tex.DrawFilledRectangle(new Rect(x, y, 3, 3), Color.cyan);
        }

        foreach(Edge e in map.allEdges) {
            //if(!map.edges.Contains(e)) tex.DrawLine(scale((int)e.start.x), scale((int)e.start.y), scale((int)e.end.x), scale((int)e.end.y), Color.blue);
        }
        */
        foreach(Edge e in map.edges) {
            //tex.DrawLine(e.start.x, e.start.y, e.end.x, e.end.y, new Color(0.5f, 0.5f, 0.5f, 0.1f));
        }

        int[,] tiles = map.ptiles;
        int h = tiles.GetLength(0);
        int w = tiles.GetLength (0);

        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                int cell = tiles[h-i-1, w-j-1];
                if(cell == PathGenerator.OPEN_ENDPOINT) {
                    tex.SetPixel(map.CellCount - j, i, Color.green);
                } else if(cell == PathGenerator.BUFFER) {
                    tex.SetPixel(map.CellCount - j, i, Color.red);
                }

            }
        }

        tex.Apply ();
        rend.material.mainTexture = tex;
    }
コード例 #29
0
        static AudioSpectrumAnalyser()
        {
            m_sampleTexture = new Texture2D( 2, 2 );
            m_sampleTexture.hideFlags = HideFlags.DontSave;

            m_sampleTexture.SetPixel( 0, 0, Color.blue );
            m_sampleTexture.SetPixel( 1, 0, Color.blue );
            m_sampleTexture.SetPixel( 0, 1, Color.blue );
            m_sampleTexture.SetPixel( 1, 1, Color.blue );
            m_sampleTexture.Apply();
        }
コード例 #30
0
ファイル: credits.cs プロジェクト: LiMina/adjective-animal
	void Start () {
		promptTexture = new Texture2D (Screen.width - 50, 50);
		for (int y = 0; y < promptTexture.height; ++y) {
			for (int x = 0; x < promptTexture.width; ++x) {
				if ((x > 2 && y > 2) && (x < promptTexture.width - 3 && y < promptTexture.height - 3)) {
					Color color = new Color (228f / 255f, 125f / 255f, 171f / 255f, 1f);
					promptTexture.SetPixel (x, y, color);
				} else {
					Color color = new Color (228f / 255f, 200f / 255f, 213f / 255f, 1f);
					promptTexture.SetPixel (x, y, color);
				}
			}
		}

		texture = new Texture2D (128, 128);
		for (int y = 0; y < texture.height; ++y) {
			for (int x = 0; x < texture.width; ++x) {
				if ((x > 2 && y > 2) && (x < texture.width - 3 && y < texture.height - 3)) {
					Color color = new Color (228f / 255f, 174f / 255f, 198f / 255f, 1f);
					texture.SetPixel (x, y, color);
				} else {
					Color color = new Color (228f / 255f, 200f / 255f, 213f / 255f, 1f);
					texture.SetPixel (x, y, color);
				}
			}
		}

		buttonTexture = new Texture2D (Screen.width - 200, 25);
		for (int y = 0; y < buttonTexture.height; ++y) {
			for (int x = 0; x < buttonTexture.width; ++x) {
				if ((x > 1 && y > 1) && (x < buttonTexture.width - 2 && y < buttonTexture.height - 2)) {
					Color color = new Color (245f / 255f, 207f / 255f, 148f / 255f, 1f);
					buttonTexture.SetPixel (x, y, color);
				} else {
					Color color = new Color (254f / 255f, 234f / 255f, 174f / 255f, 1f);
					buttonTexture.SetPixel (x, y, color);
				}
			}
		}

		buttonHoverTexture = new Texture2D (Screen.width - 200, 25);
		for (int y = 0; y < buttonHoverTexture.height; ++y) {
			for (int x = 0; x < buttonHoverTexture.width; ++x) {
				if ((x > 1 && y > 1) && (x < buttonHoverTexture.width - 2 && y < buttonHoverTexture.height - 2)) {
					Color color = new Color (254f / 255f, 234f / 255f, 174f / 255f, 1f);
					buttonHoverTexture.SetPixel (x, y, color);
				} else {
					Color color = new Color (254f / 255f, 234f / 255f, 174f / 255f, 1f);
					buttonHoverTexture.SetPixel (x, y, color);
				}
			}
		}
	}
コード例 #31
0
        void Update()
        {
            TimerManager.Instance.UpdateFunc(Time.deltaTime);

            calTime += Time.deltaTime;
            if (calTime > perTime)
            {
                calTime = 0;

                UnityEngine.Color color = UnityEngine.Color.white;
                pipeline.Render();

                for (int h = 0; h < Global.screenHeight; h++)
                {
                    for (int w = 0; w < Global.screenWidth; w++)
                    {
                        Color colorData = pipeline.backBuffer.GetColor(w, h);
                        color.r = colorData.r;
                        color.g = colorData.g;
                        color.b = colorData.b;
                        color.a = colorData.a;

                        texture.SetPixel(w, h, color);
                    }
                }
                texture.Apply();
            }
        }
コード例 #32
0
        private void ConstructForceTexture()
        {
            float w = WIDTH;
            float h = HEIGHT;

            //float top = Screen.height / 2;
            //float left = Screen.width / 2;

            _barTexture = new Texture2D((int)w, (int)h);

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    _barTexture.SetPixel(i, j, new Color(((float)j) / h, 1.0f - ((float)j) / h, 0.2f, 1.0f));
                }
            }

            _barTexture.Apply();

            _backgroundTexture = new Texture2D((int)w, (int)h);

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    _backgroundTexture.SetPixel(i, j, new Color(0.14f, 0.15f, 0.16f, 0.7f));
                }
            }

            _backgroundTexture.Apply();
        }
コード例 #33
0
    static int SetPixel(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 4)
            {
                UnityEngine.Texture2D obj = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                UnityEngine.Color arg2 = ToLua.ToColor(L, 4);
                obj.SetPixel(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 5)
            {
                UnityEngine.Texture2D obj = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                UnityEngine.Color arg2 = ToLua.ToColor(L, 4);
                int arg3 = (int)LuaDLL.luaL_checknumber(L, 5);
                obj.SetPixel(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Texture2D.SetPixel"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #34
0
        private UnityEngine.Texture2D ConstructBarTexture(float x, int width, UnityEngine.Color main, UnityEngine.Color background)
        {
            UnityEngine.Texture2D t = new UnityEngine.Texture2D(width, 16);
            int i = 0;

            for (; i < width * x; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    t.SetPixel(i, j, main);
                }
            }
            for (; i < width; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    t.SetPixel(i, j, background);
                }
            }
            t.Apply();
            return(t);
        }
コード例 #35
0
        private void ImgToTexture(Image imgToCopy, ue.Texture2D copyTo)
        {
            var bitmap = new Bitmap(imgToCopy);

            for (int x = 0; x < _width; x++)
            {
                for (int y = 0; y < _height; y++)
                {
                    var pix = bitmap.GetPixel(x, y);
                    copyTo.SetPixel(x, y, ToUeColor(pix));
                }
            }
            imgToCopy = bitmap;
        }
コード例 #36
0
        public void UpdateField(int x, int y, int _, uint color, int cost)
        {
            x   %= Constants.MiniMapSectorSize;
            y   %= Constants.MiniMapSectorSize;
            cost = GetWaypointsSafe(cost);

            Texture2D.SetPixel(x, Constants.MiniMapSectorSize - y - 1, Colors.ColorFromARGB(color));
            m_WaypointsTexture2D.SetPixel(x, Constants.MiniMapSectorSize - y - 1, Colors.ColorFrom8Bit(cost));

            m_Cost[y * Constants.MiniMapSectorSize + x] = cost;
            MinCost = System.Math.Min(MinCost, cost);
            UncommittedPixelChanges = true;
            Dirty = true;
        }
コード例 #37
0
ファイル: FogBaseData.cs プロジェクト: jccg891113/TechVeri
        public UnityEngine.Texture2D SaveTexture()
        {
            UnityEngine.Texture2D t = new UnityEngine.Texture2D(w, h, UnityEngine.TextureFormat.RGB24, false, true);
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    if (IsTransparent(i, j))
                    {
                        t.SetPixel(i, j, UnityEngine.Color.white);
                    }
                    else
                    {
                        t.SetPixel(i, j, UnityEngine.Color.blue);
                    }
                }
            }

            byte[] bytes = t.EncodeToPNG();
            global::System.IO.File.WriteAllBytes(UnityEngine.Application.dataPath + "/fogMap.png", bytes);
            UnityEngine.GameObject.DestroyImmediate(t);

            return(t);
        }
コード例 #38
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Blur a Texture2D
        /// </summary>
        /// <param name="p_Image">Source</param>
        /// <param name="p_BlurSize">Blur size</param>
        /// <returns></returns>
        public static UnityEngine.Texture2D Blur(UnityEngine.Texture2D p_Image, int p_BlurSize)
        {
            UnityEngine.Texture2D l_Blurred = new UnityEngine.Texture2D(p_Image.width, p_Image.height);

            /// Look at every pixel in the blur rectangle
            for (int l_XX = 0; l_XX < p_Image.width; l_XX++)
            {
                for (int l_YY = 0; l_YY < p_Image.height; l_YY++)
                {
                    float l_AvgR = 0, l_AvgG = 0, l_AvgB = 0, l_AvgA = 0;
                    int   l_BlurPixelCount = 0;

                    /// Average the color of the red, green and blue for each pixel in the
                    /// blur size while making sure you don't go outside the image bounds
                    for (int l_X = l_XX; (l_X < l_XX + p_BlurSize && l_X < p_Image.width); l_X++)
                    {
                        for (int l_Y = l_YY; (l_Y < l_YY + p_BlurSize && l_Y < p_Image.height); l_Y++)
                        {
                            Color l_Pixel = p_Image.GetPixel(l_X, l_Y);

                            l_AvgR += l_Pixel.r;
                            l_AvgG += l_Pixel.g;
                            l_AvgB += l_Pixel.b;
                            l_AvgA += l_Pixel.a;

                            l_BlurPixelCount++;
                        }
                    }

                    l_AvgR /= l_BlurPixelCount;
                    l_AvgG /= l_BlurPixelCount;
                    l_AvgB /= l_BlurPixelCount;
                    l_AvgA /= l_BlurPixelCount;

                    /// Now that we know the average for the blur size, set each pixel to that color
                    for (int l_X = l_XX; l_X < l_XX + p_BlurSize && l_X < p_Image.width; l_X++)
                    {
                        for (int l_Y = l_YY; l_Y < l_YY + p_BlurSize && l_Y < p_Image.height; l_Y++)
                        {
                            l_Blurred.SetPixel(l_X, l_Y, new Color(l_AvgR, l_AvgG, l_AvgB, l_AvgA));
                        }
                    }
                }
            }

            l_Blurred.Apply();
            return(l_Blurred);
        }
コード例 #39
0
 static int QPYX_SetPixel_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 4);
         UnityEngine.Texture2D QPYX_obj_YXQP = (UnityEngine.Texture2D)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Texture2D));
         int QPYX_arg0_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 2);
         int QPYX_arg1_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 3);
         UnityEngine.Color QPYX_arg2_YXQP = ToLua.ToColor(L_YXQP, 4);
         QPYX_obj_YXQP.SetPixel(QPYX_arg0_YXQP, QPYX_arg1_YXQP, QPYX_arg2_YXQP);
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
コード例 #40
0
 static int SetPixel(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         UnityEngine.Texture2D obj = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
         UnityEngine.Color arg2 = ToLua.ToColor(L, 4);
         obj.SetPixel(arg0, arg1, arg2);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #41
0
 static public int SetPixel(IntPtr l)
 {
     try {
         UnityEngine.Texture2D self = (UnityEngine.Texture2D)checkSelf(l);
         System.Int32          a1;
         checkType(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         UnityEngine.Color a3;
         checkType(l, 4, out a3);
         self.SetPixel(a1, a2, a3);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #42
0
    private static UnityTexture2D CreateTexture2D(int width, int height)
    {
        if (width <= 0 || height <= 0)
        {
            return(null);
        }
        Color          color = new Color(0, 0, 0, 0);
        UnityTexture2D tex   = new UnityTexture2D(width, height);

        for (int w = 0; w < width; w++)
        {
            for (int h = 0; h < height; h++)
            {
                tex.SetPixel(w, h, color);
            }
        }
        return(tex);
    }
コード例 #43
0
 public static int SetPixel_wrap(long L)
 {
     try
     {
         long nThisPtr             = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.Texture2D obj = get_obj(nThisPtr);
         int   arg0 = FCLibHelper.fc_get_int(L, 0);
         int   arg1 = FCLibHelper.fc_get_int(L, 1);
         Color arg2 = new Color();
         FCLibHelper.fc_get_color(L, 2, ref arg2);
         obj.SetPixel(arg0, arg1, arg2);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
コード例 #44
0
    static int SetPixel(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.Texture2D.SetPixel");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 4);
            UnityEngine.Texture2D obj = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
            int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
            int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
            UnityEngine.Color arg2 = ToLua.ToColor(L, 4);
            obj.SetPixel(arg0, arg1, arg2);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #45
0
ファイル: WZL.cs プロジェクト: isoundy000/m2client-u3d-d
 /// <summary>
 /// 获取某个索引的图片
 /// </summary>
 /// <param name="index">图片索引,从0开始</param>
 /// <returns>对应图片数据</returns>
 internal U3d.Texture2D this[uint index]
 {
     get
     {
         M2ImageInfo   ii     = ImageInfos[index];
         U3d.Texture2D result = new U3d.Texture2D(ii.Width, ii.Height);
         if (ii.Width == 0 && ii.Height == 0)
         {
             return(result);
         }
         byte[] pixels = null;
         lock (wzl_locker)
         {
             FS_wzl.Position = OffsetList[index] + 16;
             using (BinaryReader rwzl = new BinaryReader(FS_wzl))
             {
                 pixels = unzip(rwzl.ReadBytes(LengthList[index]));
             }
         }
         int p_index = 0;
         for (int h = 0; h < ii.Height; ++h)
         {
             for (int w = 0; w < ii.Width; ++w)
             {
                 // 跳过填充字节
                 if (w == 0)
                 {
                     p_index += Delphi.SkipBytes(8, ii.Width);
                 }
                 float[] pallete = Delphi.PALLETE[pixels[p_index++] & 0xff];
                 result.SetPixel(w, ii.Height - h, new U3d.Color(pallete[1], pallete[2], pallete[3], pallete[0]));
             }
         }
         result.Apply();
         return(result);
     }
 }
コード例 #46
0
 static public int SetPixel(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Texture2D self = (UnityEngine.Texture2D)checkSelf(l);
         System.Int32          a1;
         checkType(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         UnityEngine.Color a3;
         checkType(l, 4, out a3);
         self.SetPixel(a1, a2, a3);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #47
0
 /// <summary>
 /// 获取某个索引的图片
 /// </summary>
 /// <param name="index">图片索引,从0开始</param>
 /// <returns>对应图片数据</returns>
 internal U3d.Texture2D this[uint index]
 {
     get
     {
         M2ImageInfo   ii     = ImageInfos[index];
         U3d.Texture2D result = new U3d.Texture2D(ii.Width, ii.Height);
         byte[]        pixels = null;
         lock (wis_locker)
         {
             FS_wis.Position = OffsetList[index];
             using (BinaryReader rwis = new BinaryReader(FS_wis))
             {
                 // 是否压缩(RLE)
                 byte compressFlag = rwis.ReadByte();
                 FS_wis.Position += 11;
                 pixels           = rwis.ReadBytes(LengthList[index] - 12);
                 if (compressFlag == 1)
                 {
                     // 需要解压
                     pixels = unpack(pixels, pixels.Length);
                 }
             }
         }
         int p_index = 0;
         for (int h = 0; h < ii.Height; ++h)
         {
             for (int w = 0; w < ii.Width; ++w)
             {
                 float[] pallete = Delphi.PALLETE[pixels[p_index++] & 0xff];
                 result.SetPixel(w, ii.Height - h, new U3d.Color(pallete[1], pallete[2], pallete[3], pallete[0]));
             }
         }
         result.Apply();
         return(result);
     }
 }
コード例 #48
0
        private void Awake()
        {
            defaultTexture = new UE.Texture2D(1, 1);
            defaultTexture.SetPixel(0, 0, UE.Color.white);
            defaultTexture.Apply();

            transparentTexture = new UE.Texture2D(1, 1);
            transparentTexture.SetPixel(0, 0, UE.Color.clear);
            transparentTexture.Apply();

            ApiHolder.Graphics = new UnityGdi();
            ApiHolder.Input    = new UnityInput();
            ApiHolder.System   = new UnitySystem();
            ApiHolder.Timing   = new UnityTiming();

            gResources = Resources;

            Screen.width  = (int)(UE.Screen.width / Application.ScaleX);
            Screen.height = (int)(UE.Screen.height / Application.ScaleY);

            // Enum + dictionary?
            GdiImages                       = new AppGdiImages();
            GdiImages.ArrowDown             = gResources.Images.ArrowDown.ToBitmap();
            GdiImages.ArrowLeft             = gResources.Images.ArrowLeft.ToBitmap();
            GdiImages.ArrowRight            = gResources.Images.ArrowRight.ToBitmap();
            GdiImages.ArrowUp               = gResources.Images.ArrowUp.ToBitmap();
            GdiImages.Circle                = gResources.Images.Circle.ToBitmap();
            GdiImages.Checked               = gResources.Images.Checked.ToBitmap();
            GdiImages.Close                 = gResources.Images.Close.ToBitmap();
            GdiImages.CurvedArrowDown       = gResources.Images.CurvedArrowDown.ToBitmap();
            GdiImages.CurvedArrowLeft       = gResources.Images.CurvedArrowLeft.ToBitmap();
            GdiImages.CurvedArrowRight      = gResources.Images.CurvedArrowRight.ToBitmap();
            GdiImages.CurvedArrowUp         = gResources.Images.CurvedArrowUp.ToBitmap();
            GdiImages.DateTimePicker        = gResources.Images.DateTimePicker.ToBitmap();
            GdiImages.DropDownRightArrow    = gResources.Images.DropDownRightArrow.ToBitmap();
            GdiImages.FileDialogBack        = gResources.Images.FileDialogBack.ToBitmap();
            GdiImages.FileDialogFile        = gResources.Images.FileDialogFile.ToBitmap();
            GdiImages.FileDialogFolder      = gResources.Images.FileDialogFolder.ToBitmap();
            GdiImages.FileDialogRefresh     = gResources.Images.FileDialogRefresh.ToBitmap();
            GdiImages.FileDialogUp          = gResources.Images.FileDialogUp.ToBitmap();
            GdiImages.FormResize            = gResources.Images.FormResize.ToBitmap();
            GdiImages.NumericDown           = gResources.Images.NumericDown.ToBitmap();
            GdiImages.NumericUp             = gResources.Images.NumericUp.ToBitmap();
            GdiImages.RadioButton_Checked   = gResources.Images.RadioButton_Checked.ToBitmap();
            GdiImages.RadioButton_Hovered   = gResources.Images.RadioButton_Hovered.ToBitmap();
            GdiImages.RadioButton_Unchecked = gResources.Images.RadioButton_Unchecked.ToBitmap();
            GdiImages.TreeNodeCollapsed     = gResources.Images.TreeNodeCollapsed.ToBitmap();
            GdiImages.TreeNodeExpanded      = gResources.Images.TreeNodeExpanded.ToBitmap();

            GdiImages.Cursors.Default  = gResources.Images.Cursors.Default.ToBitmap();
            GdiImages.Cursors.Hand     = gResources.Images.Cursors.Hand.ToBitmap();
            GdiImages.Cursors.Help     = gResources.Images.Cursors.Help.ToBitmap();
            GdiImages.Cursors.HSplit   = gResources.Images.Cursors.HSplit.ToBitmap();
            GdiImages.Cursors.IBeam    = gResources.Images.Cursors.IBeam.ToBitmap();
            GdiImages.Cursors.SizeAll  = gResources.Images.Cursors.SizeAll.ToBitmap();
            GdiImages.Cursors.SizeNESW = gResources.Images.Cursors.SizeNESW.ToBitmap();
            GdiImages.Cursors.SizeNS   = gResources.Images.Cursors.SizeNS.ToBitmap();
            GdiImages.Cursors.SizeNWSE = gResources.Images.Cursors.SizeNWSE.ToBitmap();
            GdiImages.Cursors.SizeWE   = gResources.Images.Cursors.SizeWE.ToBitmap();
            GdiImages.Cursors.VSplit   = gResources.Images.Cursors.VSplit.ToBitmap();

            ApplicationResources.Images = GdiImages;
            ApplicationResources.Fonts  = new List <string>();

            if (Resources != null && Resources.Fonts != null)
            {
                for (int i = 0; i < Resources.Fonts.Count; i++)
                {
                    var font = Resources.Fonts[i];
                    if (font != null)
                    {
                        ApplicationResources.Fonts.Add(font.fontNames[0]);
                    }
                }
            }

            Cursors.images = GdiImages.Cursors;

            lastWidth  = UE.Screen.width;
            lastHeight = UE.Screen.height;

            controller           = new Application();
            controller.Resources = GdiImages;
            controller.UpdatePaintClipRect();

            Control.uwfDefaultController = controller;

#if UNITY_EDITOR
            MouseHook.MouseUp += (sender, args) => Inspect(sender);
#endif
        }
コード例 #49
0
 /// <summary>
 /// 获取某个索引的图片
 /// </summary>
 /// <param name="index">图片索引,从0开始</param>
 /// <returns>对应图片数据</returns>
 internal U3d.Texture2D this[uint index]
 {
     get
     {
         M2ImageInfo   ii     = ImageInfos[index];
         U3d.Texture2D result = new U3d.Texture2D(ii.Width, ii.Height);
         byte[]        pixels = null;
         lock (wil_locker)
         {
             FS_wil.Position = OffsetList[index] + 8;
             int pixelLength = OffsetList[index + 1] - OffsetList[index];
             if (pixelLength < 13)
             {
                 return(result);
             }
             pixels = BR_wil.ReadBytes(pixelLength);
         }
         if (ColorCount == 8)
         {
             int p_index = 0;
             for (int h = ii.Height - 1; h >= 0; --h)
             {
                 for (int w = 0; w < ii.Width; ++w)
                 {
                     // 跳过填充字节
                     if (w == 0)
                     {
                         p_index += Delphi.SkipBytes(8, ii.Width);
                     }
                     float[] pallete = Delphi.PALLETE[pixels[p_index++] & 0xff];
                     result.SetPixel(w, ii.Height - h, new U3d.Color(pallete[1], pallete[2], pallete[3], pallete[0]));
                 }
             }
         }
         else if (ColorCount == 16)
         {
             using (MemoryStream mspixels = new MemoryStream(pixels))
             {
                 using (BinaryReader rpixels = new BinaryReader(mspixels))
                 {
                     int p_index = 0;
                     for (int h = ii.Height - 1; h >= 0; --h)
                     {
                         for (int w = 0; w < ii.Width; ++w, p_index += 2)
                         {
                             // 跳过填充字节
                             if (w == 0)
                             {
                                 p_index += Delphi.SkipBytes(16, ii.Width);
                             }
                             short pdata = rpixels.ReadInt16();
                             float br    = (((pdata & 0xF800) >> 8) / 255f); //byte br = (byte) ((data & 0b1111_1000_0000_0000) >> 8);// 由于是与16位做与操作,所以多出了后面8位
                             float bg    = (((pdata & 0x7E0) >> 3) / 255f);  //byte bg = (byte) ((data & 0b0000_0111_1110_0000) >> 3);// 多出了3位,在强转时前8位会自动丢失
                             float bb    = (((pdata & 0x1F) << 3) / 255f);   //byte bb = (byte) ((data & 0b0000_0000_0001_1111) << 3);// 少了3位
                             result.SetPixel(w, ii.Height - h, new U3d.Color(br, bg, bb));
                         }
                     }
                 }
             }
         }
         result.Apply();
         return(result);
     }
 }
コード例 #50
0
 public void SetPixel(int x, int y, Color color)
 {
     texture.SetPixel(x, texture.height - y - 1, color.ToUnityColor());
 }
コード例 #51
0
            // Build voxel object
            public virtual float Build(Storage voxels, Bounds bounds)
            {
                // Check for given array
                if (voxels != null)
                {
                    if (!building)
                    {
                        int existingIndex;
                        int x, y, z;

                        // Get iterator
                        if (iterator == null)
                        {
                            iterator        = voxels.GetIterator();
                            currentIndex    = 0;
                            currentProgress = 0;
                        }

                        if (colorAssignments == null)
                        {
                            // Create empty list to color assignments to
                            colorAssignments = new Dictionary <Color, int>();
                        }
                        else
                        {
                            // Get current color index from existing hash map
                            currentIndex = colorAssignments.Count;
                        }

                        // Process voxels in steps
                        for (int number = 0; number < 256; ++number)
                        {
                            // Retrieve color and coordinate for current cell
                            Color color = iterator.GetNextColor(out x, out y, out z);

                            // Check for valid voxel
                            if (color.a > 0)
                            {
                                // Add assignment between color and vertex index, if it is not already included
                                if (!colorAssignments.TryGetValue(color, out existingIndex))
                                {
                                    colorAssignments.Add(color, currentIndex++);
                                }
                            }
                            else
                            {
                                iterator = null;
                                break;
                            }
                        }

                        // Return current progress when building has not been finished
                        if (iterator != null)
                        {
                            return(currentProgress = (float)iterator.Number / (float)(voxels.Count + 1) * 0.5f);
                        }
                        else
                        {
                            building = true;
                            texture  = null;
                        }
                    }

                    if (colorAssignments != null)
                    {
                        CoordinateAssignment assignment;
                        int column = 0, line = 0;

                        // Compute resolution to fit all voxels into a 2D surface
                        int textureWidth  = (int)Math.Pow(2, Math.Ceiling(Math.Log(Math.Sqrt(colorAssignments.Count)) / Math.Log(2)));
                        int textureHeight = (int)Math.Ceiling((double)colorAssignments.Count / (double)textureWidth);

                        // Make height 2^n, too, if flag is set
                        if (powerOfTwo)
                        {
                            textureHeight = (int)Math.Pow(2, Math.Ceiling(Math.Log((float)textureHeight) / Math.Log(2)));
                        }

                        //// Change resolution, if current does not match the required resolution
                        //if (texture != null && ((texture.width != textureWidth) || (texture.height != textureHeight)))
                        //{
                        //    try
                        //    {
                        //        texture.Resize(textureWidth, textureHeight, TextureFormat.ARGB32, false);

                        //        // Fill texture and calculate texture coordinates
                        //        foreach (KeyValuePair<Color, int> currentPixel in colorAssignments)
                        //        {
                        //            texture.SetPixel(column = currentPixel.Value % texture.width, line = currentPixel.Value / texture.width, currentPixel.Key);
                        //        }

                        //        iterator = null;
                        //    }
                        //    catch (System.Exception)
                        //    {
                        //        texture = null;
                        //    }
                        //}

                        if (texture == null)
                        {
                            if (textureWidth != 0 && textureHeight != 0)
                            {
                                // Create new texture instance
                                texture = new UnityEngine.Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false);
                                if (texture != null)
                                {
                                    texture.filterMode = FilterMode.Point;
                                    texture.wrapMode   = TextureWrapMode.Clamp;
                                }
                            }

                            iterator = null;
                        }

                        if (texture != null)
                        {
                            // Check for non-empty array
                            if (voxels.Count > 0)
                            {
                                // Get iterator
                                if (iterator == null)
                                {
                                    iterator        = voxels.GetIterator();
                                    currentIndex    = 0;
                                    currentProgress = 0;

                                    // Create array to store coordinates to
                                    coordinateAssignments = new CoordinateAssignment[voxels.Count];
                                }

                                // Process voxels in steps
                                for (int number = 0; number < texture.width; ++number)
                                {
                                    // Retrieve color and coordinate for current cell
                                    int   index = iterator.Number;
                                    Color color = iterator.GetNextColor(out assignment.source.x, out assignment.source.y, out assignment.source.z);

                                    // Check for valid voxel
                                    if (color.a > 0)
                                    {
                                        // Get index for current color
                                        if (colorAssignments.TryGetValue(color, out currentIndex))
                                        {
                                            // Store color as pixel
                                            texture.SetPixel(column = currentIndex % texture.width, line = currentIndex / texture.width, color);

                                            // Calculate coordinate for center of the current texel
                                            assignment.target.x = ((float)column + 0.5f) / (float)texture.width;
                                            assignment.target.y = ((float)line + 0.5f) / (float)texture.height;

                                            // Store assigned coordinates to array
                                            coordinateAssignments[index] = assignment;
                                        }
                                    }
                                    else
                                    {
                                        iterator = null;
                                        break;
                                    }
                                }

                                // Return current progress when building has not been finished
                                if (iterator != null)
                                {
                                    return(currentProgress = (float)iterator.Number / (float)(voxels.Count + 1) * 0.5f + 0.5f);
                                }

                                // Unset remaining texels
                                for (column = colorAssignments.Count % texture.width, line = colorAssignments.Count / texture.width; line < texture.height; ++line)
                                {
                                    for (; column < texture.width; ++column)
                                    {
                                        texture.SetPixel(column, line, Color.clear);
                                    }

                                    column = 0;
                                }
                            }
                        }
                    }
                }

                // Check for texture and color array
                if (texture != null)
                {
                    // Apply color changes on texture
                    texture.Apply();
                }

                // Reset current processing data
                currentIndex     = 0;
                iterator         = null;
                colorAssignments = null;
                building         = false;

                return(currentProgress = 1);
            }