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


C# Texture2D.SetPixel方法代码示例

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


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

示例1: MakePixel

 public static Texture2D MakePixel(Color color)
 {
     Texture2D tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
     tex.SetPixel(0, 0, color);
     tex.Apply();
     return tex;
 }
开发者ID:Naphier,项目名称:NGTools,代码行数:7,代码来源:TextureExtensions.cs

示例2: CreateDummyTexture

 private Texture2D CreateDummyTexture(int width, int height)
 {
   Texture2D texture2D = new Texture2D(width, height);
   for (int y = 0; y < height; ++y)
   {
     for (int x = 0; x < width; ++x)
     {
       Color color = (x & y) <= 0 ? Color.gray : Color.white;
       texture2D.SetPixel(x, y, color);
     }
   }
   texture2D.Apply();
   return texture2D;
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:14,代码来源:Local.cs

示例3: GetTextureForSprite

    // Returns a texture for a given sprite, if the sprite is a region sprite, a new texture is returned
    public Texture2D GetTextureForSprite(int spriteId)
    {
        var param = spriteCollectionProxy.textureParams[spriteId];
        if (spriteId != cachedSpriteId)
        {
            ClearTextureCache();
            cachedSpriteId = spriteId;
        }

        if (param.extractRegion)
        {
            if (cachedSpriteTexture == null)
            {
                var tex = param.texture;
                cachedSpriteTexture = new Texture2D(param.regionW, param.regionH);
                for (int y = 0; y < param.regionH; ++y)
                {
                    for (int x = 0; x < param.regionW; ++x)
                    {
                        cachedSpriteTexture.SetPixel(x, y, tex.GetPixel(param.regionX + x, param.regionY + y));
                    }
                }
                cachedSpriteTexture.Apply();
            }

            return cachedSpriteTexture;
        }
        else
        {
            return param.texture;
        }
    }
开发者ID:Gahzi,项目名称:BrutalArena,代码行数:33,代码来源:tk2dSpriteCollectionEditorPopup.cs

示例4: GetThumbnailTexture

    public static Texture2D GetThumbnailTexture(tk2dSpriteCollectionData gen, int spriteId)
    {
        // If we already have a cached texture which matches the requirements, use that
        foreach (var thumb in thumbnailCache)
        {
            if (thumb.cachedTexture	!= null && thumb.cachedSpriteCollection	== gen && thumb.cachedSpriteId == spriteId)
                return thumb.cachedTexture;
        }

        // Generate a texture
        var param = gen.spriteDefinitions[spriteId];
        if (param.sourceTextureGUID == null || param.sourceTextureGUID.Length != 0)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(param.sourceTextureGUID);
            if (assetPath.Length > 0)
            {
                Texture2D tex = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;
                if (tex != null)
                {
                    SCGE.SpriteThumbnailCache thumbnail = new SCGE.SpriteThumbnailCache();

                    if (param.extractRegion)
                    {
                        Texture2D localTex = new Texture2D(param.regionW, param.regionH);
                        for (int y = 0; y < param.regionH; ++y)
                        {
                            for (int x = 0; x < param.regionW; ++x)
                            {
                                localTex.SetPixel(x, y, tex.GetPixel(param.regionX + x, param.regionY + y));
                            }
                        }
                        localTex.Apply();
                        thumbnail.cachedTexture = localTex;
                    }
                    else
                    {
                        thumbnail.cachedTexture = tex;
                    }

                    // Prime cache for next time
                    thumbnail.cachedSpriteCollection = gen;
                    thumbnail.cachedSpriteId = spriteId;
                    thumbnailCache.Add(thumbnail);

                    return thumbnail.cachedTexture;
                }
            }
        }

        // Failed to get thumbnail
        if (blankTexture == null)
        {
            int w = 64, h = 64;
            blankTexture = new Texture2D(w, h);
            for (int y = 0; y < h; ++y)
            {
                for (int x = 0; x < w; ++x)
                {
                    blankTexture.SetPixel(x, y, Color.magenta);
                }
            }
            blankTexture.Apply();
        }

        SCGE.SpriteThumbnailCache blankThumbnail = new SCGE.SpriteThumbnailCache();
        blankThumbnail.cachedTexture = blankTexture;
        blankThumbnail.cachedSpriteCollection = gen;
        blankThumbnail.cachedSpriteId = spriteId;
        thumbnailCache.Add(blankThumbnail);

        return blankTexture;
    }
开发者ID:jhoe123,项目名称:Yonatan-Project,代码行数:72,代码来源:tk2dSpriteThumbnailCache.cs

示例5: GenerateTextureFromHeightMap

 public static Texture2D GenerateTextureFromHeightMap(TerrainHeightMap heightMap)
 {
     Texture2D tex = new Texture2D(TerrainChunkObject.TERRAIN_CHUNK_TEXTURE_RESOLUTION_SIZE, TerrainChunkObject.TERRAIN_CHUNK_TEXTURE_RESOLUTION_SIZE);
     tex.filterMode = FilterMode.Point;
     for (int x = 0; x < tex.width; x++)
     {
         for (int y = 0; y < tex.height; y++)
         {
             Color c = new Color();
             if (heightMap.GetFloat(x, y) > heightMap.highestFloat * 0.8f)
             {
                 c = Color.white;
             }
             else if (heightMap.GetFloat(x, y) > heightMap.highestFloat * 0.65f)
             {
                 c = new Color(0.65f, 0.65f, 0.65f);
             }
             else if (heightMap.GetFloat(x, y) < heightMap.highestFloat * 0.45f)
             {
                 c = Color.blue;
             }
             else
             {
                 c = Color.green;
             }
             c *= heightMap.GetFloat(x, y) / heightMap.totalStrength;
             tex.SetPixel(x, y, c);
         }
     }
     tex.Apply();
     return tex;
 }
开发者ID:DaanRuiter,项目名称:3D-Terrain,代码行数:32,代码来源:TerrainChunkObject.cs

示例6: GenerateColorTexture

        public static Texture2D GenerateColorTexture(Color mainColor, Texture2D texture)
        {
            int width = texture.width;
            int height = texture.height;

            var hsvColor = ConvertRgbToHsv((int)(mainColor.r * 255), (int)(mainColor.g * 255), (int)(mainColor.b * 255));

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var adjustedColor = hsvColor;
                    adjustedColor.V = (float)y / height;
                    adjustedColor.S = (float)x / width;
                    var color = ConvertHsvToRgb(adjustedColor.H, adjustedColor.S, adjustedColor.V);
                    texture.SetPixel(x, y, color);
                }
            }

            texture.Apply();

            return texture;
        }
开发者ID:illvisation,项目名称:cellVIEW_bdbox,代码行数:23,代码来源:HSVUtil.cs

示例7: DrawCharacter


//.........这里部分代码省略.........
                        this.smoothAparition = 0;
                        typeCloth = (int)Hat.TypeHat.None;
                    }
                    rect.x += (Screen.width / 40 + Screen.width / 20);

                    if (GUI.Button(rect, Resources.Load<Texture2D>("Sprites/Cosmetics/HatIcon"), skin.GetStyle("Square")))
                    {
                        this.smoothAparition = 0;
                        typeCloth = (int)Hat.TypeHat.TopHat;
                    }
                    rect.x += (Screen.width / 40 + Screen.width / 20);

                    if (GUI.Button(rect, Resources.Load<Texture2D>("Sprites/Cosmetics/StrawHatIcon"), skin.GetStyle("Square")))
                    {
                        this.smoothAparition = 0;
                        typeCloth = (int)Hat.TypeHat.StrawHat;
                    }
                    rect.x += (Screen.width / 40 + Screen.width / 20);

                    if (GUI.Button(rect, Resources.Load<Texture2D>("Sprites/Cosmetics/CowBoyIcon"), skin.GetStyle("Square")))
                    {
                        this.smoothAparition = 0;
                        typeCloth = (int)Hat.TypeHat.CowBoy;
                    }

                    foreach (Hat h in Clothing.Hats)
                        if (this.typeCloth == (int)h.GetTypeHat)
                        {
                            x = this.typeCloth;
                            Color fillcolor = h.Color;
                            fillcolor.a = Mathf.Clamp01(this.smoothAparition - y * TransitionDelay);
                            for (int i = 0; i < this.width / 3; i++)
                                for (int j = 0; j < this.width / 3; j++)
                                    fill.SetPixel(i, j, fillcolor);
                            fill.Apply();
                            rect = new Rect((Screen.width / 40 + Screen.width / 20) * x + Screen.width / 25f, y * (Screen.height / 10) + Screen.height / 2.6f, Screen.height / 11, Screen.height / 11);
                            if (rect.Contains(Event.current.mousePosition))
                                tooltip = h.Description;
                            if (this.smoothAparition > y * TransitionDelay && GUI.Button(rect, fill, skin.GetStyle("Square")))
                            {
                                this.skinCharacter.Hat = h;
                                this.skinCharacter.Apply(this.character);
                            }
                            y += 1;
                        }
                    break;
                #endregion
                #region Beard
                case (CategoryCloth.Beard):
                    y = 0;
                    x = 0;
                    rect = new Rect(Screen.width / 25f, this.posY - this.spacing * 1.5f, Screen.height / 11, Screen.height / 11);
                    if (GUI.Button(rect, Resources.Load<Texture2D>("Sprites/Cosmetics/NoneIcon"), skin.GetStyle("Square")))
                    {
                        this.smoothAparition = 0;
                        typeCloth = (int)Beard.TypeBeard.None;
                    }
                    rect.x += (Screen.width / 50 + Screen.width / 20);

                    if (GUI.Button(rect, Resources.Load<Texture2D>("Sprites/Cosmetics/BeardIcon"), skin.GetStyle("Square")))
                    {
                        this.smoothAparition = 0;
                        typeCloth = (int)Beard.TypeBeard.Beard;
                    }
                    rect.x += (Screen.width / 50 + Screen.width / 20);
开发者ID:JMounier,项目名称:Aegina,代码行数:66,代码来源:NetworkManagerHUD.cs

示例8: CreateDummyTexture

		private Texture2D CreateDummyTexture(int width, int height)
		{
			Texture2D texture2D = new Texture2D(width, height);
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					Color color = ((j & i) <= 0) ? Color.gray : Color.white;
					texture2D.SetPixel(j, i, color);
				}
			}
			texture2D.Apply();
			return texture2D;
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:14,代码来源:Local.cs


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