本文整理汇总了C#中UnityEngine.Texture2D.SetPixels32方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.SetPixels32方法的具体用法?C# Texture2D.SetPixels32怎么用?C# Texture2D.SetPixels32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Texture2D
的用法示例。
在下文中一共展示了Texture2D.SetPixels32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start()
{
_block = new CRoomCellTypeManager(
_cellSize, 10, new Color32(0, 0, 200, 200), new Color32(250, 250, 250, 255), new Color32(250, 0, 0, 255));
_map._AreaList.Add(new CMapCreator.CArea());
_map._AreaList[0].ResetArea(50, 50, 50);
_map._AreaList[0].Produce();
_prefab = (GameObject)Resources.Load("Prefabs/Room");
foreach (CMapCreator.CArea.CCrawler cc in _map._AreaList[0]._evaCrawler.GetCells())
{
int[,] __room = cc.GetRoomData();
Texture2D __t2d = new Texture2D(__room.GetLength(0) * (_cellSize - _borderSize) + _borderSize,
__room.GetLength(1) * (_cellSize - _borderSize) + _borderSize, TextureFormat.RGBA32, false);
for (int x = 0; x < __t2d.width; x++)
{
for (int y = 0; y < __t2d.height; y++)
__t2d.SetPixel(x, y, _transparent);
}
for (int x = 0; x < __room.GetLength(0); x++)
{
for (int y = 0; y < __room.GetLength(1); y++)
{
if (__room[x, y] > 0 &&
(__room[x, y] & (int)ERoomFlag.UpWall) == 0 &&
(__room[x, y] & (int)ERoomFlag.LeftWall) == 0)
__t2d.SetPixels32(x * (_cellSize - _borderSize), y * (_cellSize - _borderSize), _block.GetSize(),
_block.GetSize(), _block.GetColorBlock((ERoomFlag)__room[x, y]), 0);
}
for (int y = 0; y < __room.GetLength(1); y++)
{
if (__room[x, y] > 0 &&
((__room[x, y] & (int)ERoomFlag.UpWall) != 0 ||
(__room[x, y] & (int)ERoomFlag.LeftWall) != 0))
__t2d.SetPixels32(x * (_cellSize - _borderSize), y * (_cellSize - _borderSize), _block.GetSize(),
_block.GetSize(), _block.GetColorBlock((ERoomFlag)__room[x, y]), 0);
}
}
__t2d.Apply();
GameObject g = Instantiate(_prefab) as GameObject;
CRoomRender obj = g.GetComponent<CRoomRender>();
obj.SetTexture(__t2d);
obj.SetData(cc);
}
Debug.Log("Rooms:" + _map._AreaList[0]._evaCrawler.GetCrawlerCount());
}
示例2: generateTexture
public Texture2D generateTexture(MapProvider provider, BBox bbox, int i, int j, string OSMFileName)
{
string[] proj = OSMFileName.Split(new char[] {'/', '\\'});
string projectName = proj[proj.Length - 1];
if (File.Exists(tileFolder + "/final/" + provider.ToString("G") + "_" + projectName + "_" + i + "_" + j + ".png"))
{
byte[] fileData;
fileData = File.ReadAllBytes(tileFolder + "/final/" + provider.ToString("G") + "_" + projectName + "_" + i + "_" + j + ".png");
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(fileData);
return texture;
}
Texture2D uncroppedTexture = generateUncroppedTexture(bbox, provider, i, j);
Rect cropWindow = generateCroppingRect(bbox);
Texture2D finalTexture = CropTexture(uncroppedTexture, cropWindow);
if (!Directory.Exists(tileFolder + "/final/"))
Directory.CreateDirectory(tileFolder + "/final/");
var tex = new Texture2D(finalTexture.width, finalTexture.height);
tex.SetPixels32(finalTexture.GetPixels32());
tex.Apply(false);
File.WriteAllBytes(tileFolder + "/final/" + provider.ToString("G") + "_" + projectName + "_" + i + "_" + j + ".png", tex.EncodeToPNG());
return finalTexture;
}
示例3: Update
// Update is called once per frame
void Update()
{
img = camTex.GetPixels32();
Texture2D texture = new Texture2D(camTex.width, camTex.height);
texture.SetPixels32(img);
//send screenshot
if (Input.GetKeyDown(KeyCode.Space)){
//convert
Texture2D tex2d = new Texture2D(camTex.width, camTex.height);
tex2d.SetPixels32(img);
byte[] bytes = tex2d.EncodeToPNG();
//send data
StartCoroutine("accessToServer", bytes);
//accessToServer(bytes);
print("finish capture and send");
}
//debug
else if (Input.GetKeyDown(KeyCode.Q))
{
result_txt = "test_txt";
camTex.Stop();
CameraFade.StartAlphaFade(Color.white, false, 1f, 0f, () => { Application.LoadLevel("SummonResultScene"); });
}
}
示例4: Start
void Start()
{
Texture2D mip = new Texture2D(tileTex.width, tileTex.height, TextureFormat.ARGB32, true, false);
{
tileTex.filterMode = FilterMode.Point;
var pdata = tileTex.GetPixels32(0);
mip.SetPixels32(pdata, 0);
mip.Apply(true);
}
int width = tileTex.width;
int layer = 0;
while (width > tileSplit)
{
width /= 2;
layer++;
Debug.Log("p layer:" + layer);
Texture2D m = new Texture2D(width, width, TextureFormat.ARGB32, false, true);
m.filterMode = FilterMode.Point;
var d = mip.GetPixels32(layer);
m.SetPixels32(d, 0);
m.Apply();
mipTileTex.Add(m);
}
GameObject.Destroy(mip);
wordData = new worldData[srcTex.width * srcTex.height];
scale = srcTex.width;
}
示例5: WriteImageToTexture
void WriteImageToTexture(Texture2D tex)
{
// NOTE: This method only works when unity is rendering with OpenGL ("unity.exe -force-opengl"). This is *much* faster
// then Texture2D::SetPixels32 which we would have to use otherwise
// NOTE: The native texture id needs a +1 if we are rendering to GUI
if (openGl) {
//Gl.glBindTexture(Gl.GL_TEXTURE_2D, (null == target) ? tex.GetNativeTextureID() + 1 : tex.GetNativeTextureID());
//Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, 0, 0, (int)inputSize.x, (int)inputSize.y, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, Image.ImageMapPtr);
GL.BindTexture(GL.TEXTURE_2D, (null == target) ? tex.GetNativeTextureID() + 1 : tex.GetNativeTextureID());
GL.TexSubImage2D(GL.TEXTURE_2D, 0, 0, 0, (int)inputSize.x, (int)inputSize.y, GL.RGB, GL.UNSIGNED_BYTE, Image.ImageMapPtr);
return;
}
// The slow method: copy image map data to a manager buffer, and then create a Color32
// for each pixel
Marshal.Copy(Image.ImageMapPtr, rawImageMap, 0, rawImageMap.Length);
int src = 0;
int dst = 0;
for (int row = 0; row < (int)inputSize.y; row++) {
for (int col = 0; col < (int)inputSize.x; col++) {
imageMapPixels[dst] = new Color32(rawImageMap[src], rawImageMap[src + 1], rawImageMap[src + 2], 255);
src += 3;
dst++;
}
dst += (int)(outputSize.x - inputSize.x);
}
tex.SetPixels32(imageMapPixels);
tex.Apply();
}
示例6: LoadTexDistanceField
void LoadTexDistanceField(string name)
{
#if UNITY_STANDALONE
string filename = System.IO.Path.Combine(Application.streamingAssetsPath, name + ".png");
string filename_df = System.IO.Path.Combine(Application.streamingAssetsPath, name + "_df.png");
//if (System.IO.File.Exists(filename_df))
//{
// Texture2D tex = new Texture2D(1, 1);
// tex.LoadImage(System.IO.File.ReadAllBytes(filename_df));
// texs[name] = tex;
//}
//else
{
Texture2D tex = new Texture2D(1, 1);
tex.LoadImage(System.IO.File.ReadAllBytes(filename));//加载原始图片
Color32[] _bsdata = tex.GetPixels32(0);
KDTree2D tree = new KDTree2D();
List<KDTree2D.Train> treedata = new List<KDTree2D.Train>();
FindBorder(tex.width,tex.height,_bsdata, treedata);//四次采样寻找边界,并把在边界上的点填入点集
var node = tree.CreatKDTree(treedata);//用KDTree来查找最近点
int w = tex.width;
int h = tex.height;
DateTime t1 = DateTime.Now;
float maxlen = (float)Mathf.Sqrt(w * w + h * h) / 4;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
var near = tree.KDTreeFindNearest(node, new KDTree2D.Train() { positionX = x, positionY = y });
float d = (float)Mathf.Sqrt((near.point.positionX - x) * (near.point.positionX - x)
+ (near.point.positionY - y) * (near.point.positionY - y));
if (_bsdata[y * w + x].a < 128)
{
d *= -1;
_bsdata[y * w + x]= _bsdata[(int)near.point.positionY * w + (int)near.point.positionX];
}
float dist = d / maxlen;
if (dist < -1) dist = -1;
if (dist > 1) dist = 1;
var b = (byte)(128 + 127.0f * dist);
_bsdata[y * w + x].a = b;//替换原alpha值为距离值,形状内>128,形状外<128
}
}
DateTime t2 = DateTime.Now;
Debug.Log("t=" + (t2 - t1).TotalSeconds);
tex.SetPixels32(_bsdata);
tex.Apply();
System.IO.File.WriteAllBytes(filename_df, tex.EncodeToPNG());//保存为新文件
texs[name] = tex;
}
#endif
}
示例7: createFrame
public static Texture2D createFrame(int width, int height, int borderSize, Color32 borderColor, Color32 innerColor)
{
int size=width * height;
Texture2D texture = new Texture2D(width,height);
Color32[] pixels = new Color32[size];
int firstRowEnd = width * borderSize;
int lastRowStart = size - width * borderSize;
int leftBound = borderSize;
int rightBound = width - borderSize;
int remainder;
for (int i = 0; i < pixels.Length; i++) {
if (i<firstRowEnd || i > lastRowStart)
pixels[i]=borderColor;
else {
remainder = i % width;
if (remainder < leftBound || remainder >= rightBound)
pixels[i]=borderColor;
else
pixels[i]=innerColor;
}
}
texture.SetPixels32(pixels);
texture.Apply();
return texture;
}
示例8: MirrorTexture
public static Texture2D MirrorTexture(this Texture2D _inputTex, bool _mirrorHorizontally,
bool _mirrorVertically)
{
int _texWidth = _inputTex.width;
int _texWidthMinus1 = _texWidth - 1;
int _texHeight = _inputTex.height;
int _texHeightMinus1 = _texHeight - 1;
// Pixels
Color32[] _inputTexPixels = _inputTex.GetPixels32(0);
Color32[] _mirrorTexPixels = new Color32[_inputTexPixels.Length];
for (int _yCord = 0; _yCord < _texHeight; _yCord++)
{
int _sourceIndex = _yCord * _texWidth;
int _destYCord = _mirrorVertically ? (_texHeightMinus1 - _yCord) : _yCord;
int _destIndex = _destYCord * _texWidth;
for (int _xCord = 0; _xCord < _texWidth; _xCord++)
{
int _destXCord = _mirrorHorizontally ? (_texWidthMinus1 - _xCord) : _xCord;
_mirrorTexPixels[_destIndex + _destXCord] = _inputTexPixels[_sourceIndex++];
}
}
// Create mirrored texture
Texture2D _mirrorTex = new Texture2D(_texWidth, _texHeight,
_inputTex.format, false);
_mirrorTex.SetPixels32(_mirrorTexPixels, 0);
_mirrorTex.Apply();
Debug.Log("[TextureExtensions:Mirror] Output W=" + _mirrorTex.width + " H=" + _mirrorTex.height);
return _mirrorTex;
}
示例9: FixTransparency
//=========================================================================
// Methods created by petrucio -> http://answers.unity3d.com/questions/238922/png-transparency-has-white-borderhalo.html
//
// Copy the values of adjacent pixels to transparent pixels color info, to
// remove the white border artifact when importing transparent .PNGs.
public static void FixTransparency(Texture2D texture)
{
Color32[] pixels = texture.GetPixels32();
int w = texture.width;
int h = texture.height;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
int idx = y * w + x;
Color32 pixel = pixels[idx];
if (pixel.a == 0)
{
bool done = false;
if (!done && x > 0) done = TryAdjacent(ref pixel, pixels[idx - 1]); // Left pixel
if (!done && x < w - 1) done = TryAdjacent(ref pixel, pixels[idx + 1]); // Right pixel
if (!done && y > 0) done = TryAdjacent(ref pixel, pixels[idx - w]); // Top pixel
if (!done && y < h - 1) done = TryAdjacent(ref pixel, pixels[idx + w]); // Bottom pixel
pixels[idx] = pixel;
}
}
}
texture.SetPixels32(pixels);
texture.Apply();
}
示例10: NoiseTexture
void NoiseTexture(int size, bool mono)
{
var path = EditorUtility.SaveFilePanel("Save Noise Texture", "Assets", "noise" + size, "png");
if (path != "") {
var tex = new Texture2D(size, size, TextureFormat.ARGB32, false);
var s2 = size * size;
var cols = new Color32[s2];
for (int i = 0; i < s2; ++i) {
if (mono) {
var r = (byte)Random.Range(0, 256);
cols[i] = new Color32(r, r, r, 255);
}
else {
cols[i] = new Color32((byte)Random.Range(0, 256), (byte)Random.Range(0, 256), (byte)Random.Range(0, 256), 255);
}
}
tex.SetPixels32(cols);
tex.Apply();
System.IO.File.WriteAllBytes(path, tex.EncodeToPNG());
AssetDatabase.Refresh();
Object.DestroyImmediate(tex);
path = "Assets" + path.Remove(0, Application.dataPath.Length);
// tex = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
textureImporter.textureFormat = TextureImporterFormat.ARGB32;
textureImporter.anisoLevel = 0;
AssetDatabase.ImportAsset(path);
// EditorUtility.CompressTexture(tex, TextureFormat.ARGB32, 0);
//tex.format = TextureFormat.ARGB32;
}
}
示例11: Start
// Use this for initialization
void Start()
{
SpriteTexture = spriterender.sprite.texture;
Color32[] pix = spriterender.sprite.texture.GetPixels32();
// System.Array.Reverse(pix);
SpriteTexture = new Texture2D(spriterender.sprite.texture.width, spriterender.sprite.texture.height);
SpriteTexture.SetPixels32(pix);
for (int x = 0; x < SpriteTexture.width; x++)
{
for (int y = 0; y < SpriteTexture.height; y++)
{
Color col = SpriteTexture.GetPixel(x,y);
SpriteTexture.SetPixel(x, y, new Color(col.r,col.g, col.b, 1));
}
}
SpriteTexture.Apply();
Rect rec = new Rect(0,0,SpriteTexture.width,SpriteTexture.height);
spriterender.sprite = Sprite.Create(SpriteTexture, rec, new Vector2(0.5f, 0.5f));
}
示例12: GetCurrentTexture
public Texture2D GetCurrentTexture()
{
Texture2D t = new Texture2D(320,240,TextureFormat.ARGB32,false);
t.SetPixels32(mipmapImg(kinect.getColor(),640,480));
t.Apply(false);
return t;
}
示例13: Convert
static void Convert(string origpath, string filename, string destpath)
{
FSNEditorUtils.MakeTargetDirectory(destpath); // 타겟 경로 확보
var assetpath = destpath + "/" + filename;
var absolutepath = Application.dataPath + "/../" + assetpath;
//Debug.LogFormat("asset path : {0}, absolute target path : {1}", assetpath, absolutepath);
if (AssetDatabase.AssetPathToGUID(assetpath) != null) // 복사하려는 위치에 해당 어셋이 이미 존재한다면 기존 것은 삭제
AssetDatabase.DeleteAsset(assetpath);
AssetDatabase.CopyAsset(origpath, assetpath); // 변경하려는 어셋을 복제하여 타겟 경로에 넣는다.
AssetDatabase.Refresh();
var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetpath);
var converted = new Texture2D(texture.width, texture.height, TextureFormat.ARGB32, false);
var origcolors = texture.GetPixels32();
var len = origcolors.Length;
for (int i = 0; i < len; i++) // 픽셀마다 알파곱 계산
{
var color = origcolors[i];
var alpha = (int)color.a;
color.r = (byte)(color.r * alpha / 255);
color.g = (byte)(color.g * alpha / 255);
color.b = (byte)(color.b * alpha / 255);
origcolors[i] = color;
}
converted.SetPixels32(origcolors);
System.IO.File.WriteAllBytes(absolutepath, converted.EncodeToPNG()); // 실제 파일로 write
AssetDatabase.ImportAsset(assetpath);
var importer = AssetImporter.GetAtPath(assetpath) as TextureImporter; // 텍스쳐 옵션 설정
importer.textureType= TextureImporterType.Advanced;
importer.alphaIsTransparency = false; // premultiplied alpha texture는 이 옵션을 꺼줘야 한다.
importer.SaveAndReimport();
}
示例14: TilesetPropertiesWindow
public TilesetPropertiesWindow (TilesetWindow parent)
{
_parent = parent;
_overlay = new Texture2D(OverlaySize, OverlaySize, TextureFormat.ARGB32, false);
_highlight1 = new Texture2D(OverlaySize, OverlaySize, TextureFormat.ARGB32, false);
_highlight2 = new Texture2D(OverlaySize, OverlaySize, TextureFormat.ARGB32, false);
var colorO = new Color32(255, 255, 0, 127);
var colorsO = Util.InitilizeArray(OverlaySize, colorO);
_overlay.SetPixels32(colorsO);
_overlay.Apply();
var colorH1 = new Color32(255, 0, 255, 127);
var colorsH1 = Util.InitilizeArray(OverlaySize, colorH1);
_highlight1.SetPixels32(colorsH1);
_highlight1.Apply();
var colorH2 = new Color32(0, 255, 255, 127);
var colorsH2 = Util.InitilizeArray(OverlaySize, colorH2);
_highlight2.SetPixels32(colorsH2);
_highlight2.Apply();
}
示例15: GetImage
public Texture2D GetImage()
{
Texture2D texture = new Texture2D (deviceCamera.width, deviceCamera.height);
texture.SetPixels32 (deviceCamera.GetPixels32 ());
texture.Apply ();
return texture;
}