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


C# Texture2D.Apply方法代码示例

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


在下文中一共展示了Texture2D.Apply方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: drawRight

                public override void drawRight(TextureEditGUI gui)
                {
                    if (BitmapDecalCache.Instance.monoSheets.Count == 0) return;

                    Color contentColor = GUI.contentColor;
                    GUI.backgroundColor = Global.BackgroundColor;

                    _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUI.skin.box, GUILayout.MinWidth(250), GUILayout.ExpandHeight(true));

                    GUILayout.Label("Decal Sheets");

                    GUILayout.Space(3);

                    int oldSelectedSheet = _selectedSheet;
                    for (int i = 0; i < BitmapDecalCache.Instance.monoSheets.Count; ++i)
                    {
                        if (i == _selectedSheet) GUI.contentColor = Global.SelectedColor;
                        else GUI.contentColor = Global.NotSelectedColor;

                        if (GUILayout.Button(BitmapDecalCache.Instance.monoSheets[i].displayName, GUILayout.ExpandWidth(true))) _selectedSheet = i;
                    }

                    if (_selectedSheet != oldSelectedSheet)
                    {
                        if (_textures != null)
                        {
                            for (int i = 0; i < _textures.Count; ++i)
                            {
                                UnityEngine.Object.Destroy(_textures[i]);
                            }
                            _textures = null;
                        }
                        if (_selectedDecal >= BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals.Count) _selectedDecal = 0;
                    }

                    GUILayout.Space(10);

                    GUILayout.Label("Decals");

                    GUILayout.Space(3);

                    if (_textures == null)
                    {
                        _textures = new List<Texture2D>();
                        for (int i = 0; i < BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals.Count; ++i)
                        {
                            Image image = new Image(BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals[i].image);
                            image.recolor(Global.Black32, Global.White32, false, false);

                            Texture2D texture = new Texture2D(image.width, image.height, TextureFormat.ARGB32, false);
                            texture.SetPixels32(image.pixels);
                            texture.Apply();

                            _textures.Add(texture);
                        }
                    }

                    int oldSelectedDecal = _selectedDecal;
                    int x = 0;
                    GUILayout.BeginHorizontal();
                    for (int i = 0; i < _textures.Count; ++i)
                    {
                        if (i == _selectedDecal)
                        {
                            GUI.backgroundColor = Color.yellow;
                            if (GUILayout.Button(_textures[i], GUILayout.Width(_textures[i].width + 4), GUILayout.Height(_textures[i].height + 4))) _selectedDecal = i;
                            GUI.backgroundColor = Global.BackgroundColor;
                        }
                        else
                        {
                            if (GUILayout.Button(_textures[i], GUILayout.Width(_textures[i].width + 4), GUILayout.Height(_textures[i].height + 4))) _selectedDecal = i;
                        }

                        x += _textures[i].width + 5;
                        if (i < (_textures.Count - 1))
                        {
                            if (x > 0 && (x + _textures[i+1].width) > 200)
                            {
                                GUILayout.EndHorizontal();
                                GUILayout.BeginHorizontal();
                                x = 0;
                            }
                        }
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.EndScrollView();

                    GUI.contentColor = contentColor;

                    if (oldSelectedSheet != _selectedSheet || oldSelectedDecal != _selectedDecal)
                    {
                        _imBitmapMonoDecal._url = BitmapDecalCache.Instance.monoSheets[_selectedSheet].decals[_selectedDecal].url;
                        gui.setRemakePreview();
                    }
                }
开发者ID:panteras1000,项目名称:TheWriteStuff,代码行数:96,代码来源:IM_BitmapMonoDecal.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: 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

示例6: Styles

 public Styles()
 {
     Texture2D textured = new Texture2D(4, 4);
     Color[] colors = new Color[] { Color.white, Color.white, Color.white, Color.white, Color.white, Color.clear, Color.clear, Color.white, Color.white, Color.clear, Color.clear, Color.white, Color.white, Color.white, Color.white, Color.white };
     textured.SetPixels(colors);
     textured.filterMode = UnityEngine.FilterMode.Point;
     textured.Apply();
     textured.hideFlags = HideFlags.HideAndDontSave;
     this.frame.normal.background = textured;
     this.frame.border = new RectOffset(2, 2, 2, 2);
     this.label.alignment = TextAnchor.LowerCenter;
     if (EditorGUIUtility.isProSkin)
     {
         this.tableHeaderColor = new Color(0.18f, 0.18f, 0.18f, 1f);
         this.tableLineColor = new Color(1f, 1f, 1f, 0.3f);
         this.parentColor = new Color(0.4f, 0.4f, 0.4f, 1f);
         this.selfColor = new Color(0.6f, 0.6f, 0.6f, 1f);
         this.simpleAnchorColor = new Color(0.7f, 0.3f, 0.3f, 1f);
         this.stretchAnchorColor = new Color(0f, 0.6f, 0.8f, 1f);
         this.anchorCornerColor = new Color(0.8f, 0.6f, 0f, 1f);
         this.pivotColor = new Color(0f, 0.6f, 0.8f, 1f);
     }
     else
     {
         this.tableHeaderColor = new Color(0.8f, 0.8f, 0.8f, 1f);
         this.tableLineColor = new Color(0f, 0f, 0f, 0.5f);
         this.parentColor = new Color(0.55f, 0.55f, 0.55f, 1f);
         this.selfColor = new Color(0.2f, 0.2f, 0.2f, 1f);
         this.simpleAnchorColor = new Color(0.8f, 0.3f, 0.3f, 1f);
         this.stretchAnchorColor = new Color(0.2f, 0.5f, 0.9f, 1f);
         this.anchorCornerColor = new Color(0.6f, 0.4f, 0f, 1f);
         this.pivotColor = new Color(0.2f, 0.5f, 0.9f, 1f);
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:34,代码来源:LayoutDropdownWindow.cs

示例7: 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

示例8: 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

示例9: GenerateHSVTexture

        public static Texture2D GenerateHSVTexture(int width, int height)
        {
            var list = GenerateHsvSpectrum();

            float interval = 1;
            if (list.Count > height)
            {
                interval = (float)list.Count / height;
            }

            var texture = new Texture2D(width, height);

            int ySize = Mathf.Max(1, (int)(1f / (list.Count / interval) * height));

            int colorH = 0;

            Color color = Color.white;
            for (float cnt = 0; cnt < list.Count; cnt += interval)
            {
                color = list[(int)cnt];
                Color[] colors = new Color[width * ySize];
                for (int i = 0; i < width * ySize; i++)
                {
                    colors[i] = color;
                }
                if (colorH < height)
                {
                    texture.SetPixels(0, colorH, width, ySize, colors);
                }
                colorH += ySize;
            }

            texture.Apply();

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

示例10: LoadTexture


//.........这里部分代码省略.........
                                    }
                                    else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT5)
                                    {
                                        map = new Texture2D((int)dDSHeader.dwWidth, (int)dDSHeader.dwHeight, TextureFormat.DXT5, mipmap);
                                        map.LoadRawTextureData(LoadRestOfReader(binaryReader));
                                    }
                                    else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT2)
                                    {
                                        Debug.Log("[Kopernicus]: DXT2 not supported" + path);
                                    }
                                    else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT4)
                                    {
                                        Debug.Log("[Kopernicus]: DXT4 not supported: " + path);
                                    }
                                    else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDX10)
                                    {
                                        Debug.Log("[Kopernicus]: DX10 dds not supported: " + path);
                                    }
                                    else
                                        fourcc = false;
                                }
                                if (!fourcc)
                                {
                                    TextureFormat textureFormat = TextureFormat.ARGB32;
                                    bool ok = true;
                                    if (rgb && (rgb888 /*|| bgr888*/))
                                    {
                                        // RGB or RGBA format
                                        textureFormat = alphapixel
                                        ? TextureFormat.RGBA32
                                        : TextureFormat.RGB24;
                                    }
                                    else if (rgb && rgb565)
                                    {
                                        // Nvidia texconv B5G6R5_UNORM
                                        textureFormat = TextureFormat.RGB565;
                                    }
                                    else if (rgb && alphapixel && argb4444)
                                    {
                                        // Nvidia texconv B4G4R4A4_UNORM
                                        textureFormat = TextureFormat.ARGB4444;
                                    }
                                    else if (rgb && alphapixel && rbga4444)
                                    {
                                        textureFormat = TextureFormat.RGBA4444;
                                    }
                                    else if (!rgb && alpha != luminance)
                                    {
                                        // A8 format or Luminance 8
                                        textureFormat = TextureFormat.Alpha8;
                                    }
                                    else
                                    {
                                        ok = false;
                                        Debug.Log("[Kopernicus]: Only DXT1, DXT5, A8, RGB24, RGBA32, RGB565, ARGB4444 and RGBA4444 are supported");
                                    }
                                    if (ok)
                                    {
                                        map = new Texture2D((int)dDSHeader.dwWidth, (int)dDSHeader.dwHeight, textureFormat, mipmap);
                                        map.LoadRawTextureData(LoadRestOfReader(binaryReader));
                                    }

                                }
                                if (map != null)
                                    if (upload)
                                        map.Apply(false, unreadable);
                            }
                            else
                                Debug.Log("[Kopernicus]: Bad DDS header.");
                        }
                        else
                        {
                            map = new Texture2D(2, 2);
                            byte[] data = LoadWholeFile(path);
                            if (data == null)
                                throw new Exception("LoadWholeFile failed");

                            map.LoadImage(data);
                            if (compress)
                                map.Compress(true);
                            if (upload)
                                map.Apply(false, unreadable);
                        }
                    }
                    catch (Exception ex)
                    {
                        uncaught = false;
                        Debug.Log("[Kopernicus]: failed to load " + path + " with exception " + ex.Message);
                    }
                    if (map == null && uncaught)
                    {
                        Debug.Log("[Kopernicus]: failed to load " + path);
                    }
                    map.name = path.Remove(0, (KSPUtil.ApplicationRootPath + "GameData/").Length);
                }
                else
                    Debug.Log("[Kopernicus]: texture does not exist! " + path);

                return map;
            }
开发者ID:FrancoisHarvey,项目名称:Kopernicus,代码行数:101,代码来源:OnDemandStorage.cs

示例11: DrawCharacter


//.........这里部分代码省略.........
            {
                if (this.categoryCloth == CategoryCloth.Gloves)
                    this.categoryCloth = CategoryCloth.None;
                else
                {
                    this.smoothAparition = 0;
                    this.categoryCloth = CategoryCloth.Gloves;
                }
            }
            if (GUI.Button(new Rect(this.posX + this.width - this.width / 5, this.posY + this.spacing * 1.5f, this.width / 5, this.width / 5), Resources.Load<Texture2D>("Sprites/Cosmetics/TshirtIcon"), skin.GetStyle("Square")))
            {
                if (this.categoryCloth == CategoryCloth.TShirt)
                    this.categoryCloth = CategoryCloth.None;
                else
                {
                    this.smoothAparition = 0;
                    this.categoryCloth = CategoryCloth.TShirt;
                }
            }
            if (GUI.Button(new Rect(this.posX + this.width - this.width / 5, this.posY + this.spacing * 3f, this.width / 5, this.width / 5), Resources.Load<Texture2D>("Sprites/Cosmetics/PantIcon"), skin.GetStyle("Square")))
            {
                if (this.categoryCloth == CategoryCloth.Pant)
                    this.categoryCloth = CategoryCloth.None;
                else
                {
                    this.categoryCloth = CategoryCloth.Pant;
                    this.smoothAparition = 0;
                }
            }
            if (GUI.Button(new Rect(this.posX + this.width + this.width / 5, this.posY - this.spacing * 1.5f, this.width / 5, this.width / 5), Resources.Load<Texture2D>("Sprites/Cosmetics/RandomIcon"), skin.GetStyle("Square")))
            {
                this.categoryCloth = CategoryCloth.None;
                this.skinCharacter = Skin.RandomSkin();
                this.skinCharacter.Apply(this.character);
            }
            if (GUI.Button(new Rect(this.posX + this.width + this.width / 5f, this.posY, this.width / 5, this.width / 5), Resources.Load<Texture2D>("Sprites/Cosmetics/Reset"), skin.GetStyle("Square")))
            {
                try
                {
                    this.categoryCloth = CategoryCloth.None;
                    this.skinCharacter = Skin.Load(PlayerPrefs.GetString("Skin", ""));
                    this.skinCharacter.Apply(this.character);
                }
                catch { }
            }

            switch (this.categoryCloth)
            {
                case CategoryCloth.Hair:
                case CategoryCloth.Eyes:
                case CategoryCloth.Beard:
                case CategoryCloth.Hat:
                    this.firstScene.CameraAim(1);
                    break;
                case CategoryCloth.Gloves:
                    this.firstScene.CameraAim(2);
                    break;
                default:
                    this.firstScene.CameraAim(0);
                    break;
            }

            #endregion

            Text tooltip = null;
            Texture2D fill = new Texture2D(this.width / 3, this.width / 3);
开发者ID:JMounier,项目名称:Aegina,代码行数:67,代码来源:NetworkManagerHUD.cs

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