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


C# Texture2D.SetPixels方法代码示例

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


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

示例1: CalculateWidget

    public void CalculateWidget()
    {
        int canvasWidth = FullHeart.width * (_playerHealthSystem.MaxHP / 2);
        int fullHearts = _playerHealthSystem.HP / 2;
        int halfHearts = _playerHealthSystem.HP % 2;
        int deadHearts = (_playerHealthSystem.MaxHP / 2) - (_playerHealthSystem.HP / 2);

        Texture2D tex = new Texture2D(canvasWidth, FullHeart.height);

        int i = 0;

        for(int counter = 0; counter < fullHearts; counter++)
        {
            tex.SetPixels(i, 0, FullHeart.width, FullHeart.height, FullHeart.GetPixels());
            i += FullHeart.width;
        }

        for(int counter = 0; counter < halfHearts; counter++)
        {
            tex.SetPixels(i, 0, FullHeart.width, FullHeart.height, HalfHeart.GetPixels());
            i += FullHeart.width;
        }

        for(int counter = 0; counter < deadHearts; counter++)
        {
            tex.SetPixels(i, 0, FullHeart.width, FullHeart.height, NoHeart.GetPixels());
            i += FullHeart.width;
        }

        tex.Apply();

        _fullUiWidget = tex;
        UiWidget.Image = _fullUiWidget;
    }
开发者ID:nicodeceulaer,项目名称:HerosJourney,代码行数:34,代码来源:PlayerHealthProvider.cs

示例2: UpdateFogTexture

    private void UpdateFogTexture(GameObject[] visions)
    {
        var texture = new Texture2D(128, 128);

        var fog = fogTexture.GetPixels(0, 0, 128, 128);

        texture.SetPixels(fog);
        var texturePixels = texture.GetPixels();

        for (int i = 0; i < visions.Length; i++)
        {
            var visionPos = visions[i].transform.position;
            var texturePos = new Vector2(visionPos.x, visionPos.z);
            texturePos += mapOffset;
            texturePos /= mapSize;
            texturePos *= fogSize;
            texturePos -= new Vector2(16, 16);
            int x = Mathf.FloorToInt(texturePos.x);
            int y = Mathf.FloorToInt(texturePos.y);
            AddPixels(texturePixels, visionPixels, x, y, GetVisionPoly(visions[i].transform.position));
        }
        texture.SetPixels(texturePixels);

        texture.Apply();

        Shader.SetGlobalTexture("_FogTex", texture);
        Shader.SetGlobalTexture("_LastFogTex", lastFogTexture);
        Shader.SetGlobalFloat("_FogBlend", 0f);

        lastFogTexture = texture;
    }
开发者ID:Nyntendo,项目名称:moba-prototype,代码行数:31,代码来源:FogController.cs

示例3: InitMapTexture

    Texture2D InitMapTexture()
    {
        // texture colors
        var texCols = MapTexture.GetPixels();
        var height = MapTexture.height;
        var width = MapTexture.width;

        // find next largest power of 2 from width
        int pot = 1;
        while (pot < width)
            pot <<= 1;

        // fill texture
        var blacks = new Color[pot * pot];
        for (int i = 0; i < pot * pot; i++)
            blacks[i] = Color.black;

        var bgTex = new Texture2D(pot, pot, TextureFormat.RGBA32, false); // must be power of 2
        bgTex.filterMode = FilterMode.Point;
        bgTex.wrapMode = TextureWrapMode.Clamp;
        bgTex.SetPixels(blacks);
        bgTex.SetPixels(0, 0, width, height, texCols);
        bgTex.Apply();

        // set material texture
        var rend = BGObj.GetComponent<MeshRenderer>();
        rend.material.SetTexture("_MainTex", bgTex);

        return bgTex;
    }
开发者ID:attrition,项目名称:ROGUESPY,代码行数:30,代码来源:BackgroundMaker.cs

示例4: ConvertTangentBasis

    /// <summary>
    /// Converts vector data stored within a texture using the specified basis.  Assume all calculations are performed in tangent space.
    /// </summary>
    /// <param name='basis'>
    /// Basis to multiply the vector values against.
    /// </param>
    /// <param name='vectorData'>
    /// Texture2D containing vector data.  Textures are passed by reference, so make sure to copy beforehand if you don't want to overwrite your data!
    /// </param>
    public static void ConvertTangentBasis(Matrix4x4 basis, ref Texture2D vectorData, bool recomputeZ = false)
    {
        Color[] colorData = vectorData.GetPixels();
        Texture2D tmpTexture = new Texture2D(vectorData.width, vectorData.height, TextureFormat.ARGB32, false);

        for (int i = 0; i < colorData.Length; i++)
        {
            Color vecData = new Color(colorData[i].r, colorData[i].g, colorData[i].b, 1);
            vecData.r = Vector3.Dot(new Vector3(basis.m00, basis.m01, basis.m02), UnpackUnitVector(new Vector3(colorData[i].r, colorData[i].g, colorData[i].b))) * 0.5f + 0.5f;
            vecData.g = Vector3.Dot(new Vector3(basis.m10, basis.m11, basis.m12), UnpackUnitVector(new Vector3(colorData[i].r, colorData[i].g, colorData[i].b))) * 0.5f + 0.5f;
            if (recomputeZ)
            {
                vecData.r = vecData.r * 2 - 1;
                vecData.g = vecData.g * 2 - 1;
                vecData.b = Mathf.Sqrt(1 - vecData.r * vecData.r - vecData.g * vecData.g) * 0.5f + 0.5f;
                vecData.r = vecData.r * 0.5f + 0.5f;
                vecData.g = vecData.g * 0.5f + 0.5f;
            } else {
                vecData.b = Vector3.Dot(new Vector3(basis.m20, basis.m21, basis.m22), UnpackUnitVector(new Vector3(colorData[i].r, colorData[i].g, colorData[i].b))) * 0.5f + 0.5f;
            }
            colorData[i] = vecData;
        }
        tmpTexture.SetPixels(colorData);
        tmpTexture.Apply();
        vectorData = tmpTexture;
    }
开发者ID:Geenz,项目名称:Gz-Unity-Tools,代码行数:35,代码来源:TexturesSpaceConverter.cs

示例5: GetAd

    public IEnumerator GetAd(int id)
    {
		BusinessCard = null;
        adReady = false;
        hasAd = false;
        BusinessID = id;
        string adURL = serverURL + "getAd?b=" + id;
        string bcURL = serverURL + "bizcard?id=" + id;

        WWW card = new WWW(bcURL);
        yield return card;
        BusinessCard = new Texture2D(Convert.ToInt32(card.texture.width),
                              Convert.ToInt32(card.texture.height),
                              TextureFormat.ARGB32, false);
        BusinessCard.SetPixels(card.texture.GetPixels());
        BusinessCard.Apply();

        WWW page = new WWW(adURL);
        yield return page;
        if (page.error == null && page.text[0] == '{')
        {
            Debug.Log(page.text);
            // Get the ad as a Dictionary object.
            hasAd = true;
            Dictionary<string, object> ad = Json.Deserialize(page.text) as Dictionary<string, object>;
            AdImages(ad);
            AdInfo = new AdData(ad);
        }

        adReady = true;
    }
开发者ID:uvcteam,项目名称:univercity3d_uofo,代码行数:31,代码来源:AdManager.cs

示例6: Start

	void Start ()
	{
		mTrans = transform;
		mUITex = GetComponent<UITexture>();
		mCam = UICamera.FindCameraForLayer(gameObject.layer);

		mWidth = mUITex.width;
		mHeight = mUITex.height;
		Color[] cols = new Color[mWidth * mHeight];

		for (int y = 0; y < mHeight; ++y)
		{
			float fy = (y - 1f) / mHeight;

			for (int x = 0; x < mWidth; ++x)
			{
				float fx = (x - 1f) / mWidth;
				int index = x + y * mWidth;
				cols[index] = Sample(fx, fy);
			}
		}

		mTex = new Texture2D(mWidth, mHeight, TextureFormat.RGB24, false);
		mTex.SetPixels(cols);
		mTex.filterMode = FilterMode.Trilinear;
		mTex.wrapMode = TextureWrapMode.Clamp;
		mTex.Apply();
		mUITex.mainTexture = mTex;

		Select(value);
	}
开发者ID:ChungH,项目名称:BNG,代码行数:31,代码来源:UIColorPicker.cs

示例7: CreateGrassTexture

 private void CreateGrassTexture()
 {
     grassTexture = new Texture2D(2,2);
     grassTexture.SetPixels(new Color[]{Color.green,Color.green,Color.green,Color.green});
     grassTexture.filterMode = FilterMode.Point;
     grassTexture.Apply();
 }
开发者ID:Headsta,项目名称:Boxworld,代码行数:7,代码来源:InputController.cs

示例8: CreateSprite

	public override Texture2D CreateSprite (Texture2D texture)
	{
		Color[] pixels = texture.GetPixels ();
		Color[,] pixels2D = new Color[texture.width, texture.height];
		for (int i = 0; i < pixels.Length; i++) {
			
			int x = i % texture.width;
			int y = i / texture.height;

			pixels2D [x, y] = pixels [i];
		}

		int amountOfEyes = (int)(sightAngle / 45);
		for (int i = 0; i < amountOfEyes; i++) {
			
			int radius = (texture.width - eyeSize) / 2;
			float xPos = Mathf.Sin (Mathf.Deg2Rad * (i * 45));
			float yPos = Mathf.Cos (Mathf.Deg2Rad * (i * 45));
			Vector2 pos = new Vector2 (xPos, yPos) * radius + new Vector2 (texture.width - eyeSize, texture.height - eyeSize) / 2;

			ApplyKernel (ref pixels2D, texture.width, texture.height, pos);
		}

		for (int x = 0; x < pixels2D.GetLength (0); x++) {
			for (int y = 0; y < pixels2D.GetLength (1); y++) {
				
				pixels [x + y * texture.width] = pixels2D [x, y];
			}
		}

		texture.SetPixels (pixels);
		texture.Apply ();

		return texture;
	}
开发者ID:MrImitate,项目名称:Procedural-Gen,代码行数:35,代码来源:Part_Eye.cs

示例9: AddSpriteToAtlas

        /// <summary>
        /// Creates a new sprite using the size of the image inside the atlas.
        /// </summary>
        /// <param name="dimensions">The location and size of the sprite within the atlas (in pixels).</param>
        /// <param name="spriteName">The name of the sprite to create</param>
        /// <param name="atlasName">The name of the atlas to add the sprite to.</param>
        /// <returns></returns>
        public static bool AddSpriteToAtlas(Rect dimensions, string spriteName, string atlasName)
        {
            bool returnValue = false;

            if (m_atlasStore.ContainsKey(atlasName))
            {
                UITextureAtlas foundAtlas = m_atlasStore[atlasName];
                Texture2D atlasTexture = foundAtlas.texture;
                Vector2 atlasSize = new Vector2(atlasTexture.width, atlasTexture.height);
                Rect relativeLocation = new Rect(new Vector2(dimensions.position.x / atlasSize.x, dimensions.position.y / atlasSize.y), new Vector2(dimensions.width / atlasSize.x, dimensions.height / atlasSize.y));
                Texture2D spriteTexture = new Texture2D((int)Math.Round(dimensions.width), (int)Math.Round(dimensions.height));

                spriteTexture.SetPixels(atlasTexture.GetPixels((int)dimensions.position.x, (int)dimensions.position.y, (int)dimensions.width, (int)dimensions.height));

                UITextureAtlas.SpriteInfo createdSprite = new UITextureAtlas.SpriteInfo()
                {
                    name = spriteName,
                    region = relativeLocation,
                    texture = spriteTexture,
                    border = new RectOffset()
                };

                foundAtlas.AddSprite(createdSprite);
                returnValue = true;
            }

            return returnValue;
        }
开发者ID:GRANTSWIM4,项目名称:RoadNamer,代码行数:35,代码来源:SpriteUtilities.cs

示例10: GenerateGun

	public static MisGun GenerateGun(GameObject owner) {

		// Set a random frequency
		float frequency = Random.Range(1f, 2f);

		// Set a random speed
		float speed = 60f/frequency;

		// Set a random damage
		int damage = (int)(10f/frequency);

		int size = Random.Range (4, 8);

		// Create a newtexture
		Texture2D texture = new Texture2D(size, size, TextureFormat.ARGB32, false);

		Color []bulletColors = new Color[size * size];
		for(int i = 0; i < bulletColors.Length; i++)
			bulletColors[i] = Color.grey;

		texture.SetPixels (bulletColors);

		// Apply all SetPixel calls
		texture.Apply();

		MisGun gun = new MisGun (damage, speed, frequency, texture, owner);

		return gun;
	}
开发者ID:lucasnfe,项目名称:Metronome,代码行数:29,代码来源:MisGunGenerator.cs

示例11: BuildTexture

    public void BuildTexture()
    {
        // Determine mesh texture resolution
        int texWidth = size_x * Tileset.tile_width; // + Tileset.tile_width / 2;
        int texHeight = size_y * Tileset.tile_height; // + Tileset.tile_height / 2;

        // Instantiate empty texture for mesh
        Texture2D texture = new Texture2D(texWidth, texHeight);

        // Initialize clear texture if unset previously
        if (clear_tex == null) {
            clear_tex = new Color[texWidth * texHeight];
            for (int i = 0; i < clear_tex.Length; i++)
                clear_tex[i] = Color.clear;
        }

        // Initialize texture to transparent
        texture.SetPixels (0, 0, texWidth, texHeight, clear_tex);

        // Handles map drawing logic
        DrawMap(texture);

        // Point filter does no pixel blending
        texture.filterMode = FilterMode.Point;
        texture.Apply();

        // Assigns generated texture to mesh object
        MeshRenderer mesh_renderer = GetComponent<MeshRenderer>();
        mesh_renderer.material.mainTexture = texture;
    }
开发者ID:JakeJasko,项目名称:Haven,代码行数:30,代码来源:PlayerMap.cs

示例12: Encode

 public static void Encode(Texture2D src, Texture2D dst, bool gpu = false,
                           YCgACoFormat format = YCgACoFormat.CgACoY_DontChange,
                           int quality = 100)
 {
     var pixels = src.GetPixels();
     Resize(src, dst, format);
     var resized = src.width != dst.width || src.height != dst.height;
     if (gpu)
     {
         // TODO: Force mipmap and trilinear when resized.
         var shader = Shader.Find("Hidden/RGBA to CgACoY");
         var mat = new Material(shader);
         var temp = RenderTexture.GetTemporary(dst.width, dst.height);
         Graphics.Blit(src, temp, mat);
         dst.ReadPixels(new Rect(0, 0, dst.width, dst.height), 0, 0);
         RenderTexture.ReleaseTemporary(temp);
         Object.DestroyImmediate(mat);
     }
     else
     {
         if (resized)
         {
             var srcPixels = pixels;
             pixels = dst.GetPixels();
             Shrink(srcPixels, pixels, src.width, dst.width);
         }
         RGBAToCgACoY(pixels, pixels);
         dst.SetPixels(pixels);
     }
     Compress(dst, format, quality);
 }
开发者ID:n-yoda,项目名称:unity-ycca-subsampling,代码行数:31,代码来源:YCgACoEncoder.cs

示例13: OnEnable

	void OnEnable()
	{
		pb_Object[] pbs = (pb_Object[])Selection.transforms.GetComponents<pb_Object>();

		if(pbs.Length == 2)
		{
			lhs = pbs[0].gameObject;
			rhs = pbs[1].gameObject;
		}

		previewBackground = new GUIStyle();
		
		backgroundTexture = new Texture2D(2,2);

		backgroundTexture.SetPixels(new Color[] {
			backgroundColor,
			backgroundColor, 
			backgroundColor, 
			backgroundColor });

		backgroundTexture.Apply();

		previewBackground.normal.background = backgroundTexture;

		unicodeIconStyle = new GUIStyle();
		unicodeIconStyle.fontSize = 64;
		unicodeIconStyle.normal.textColor = Color.white;
		unicodeIconStyle.alignment = TextAnchor.MiddleCenter;
	}
开发者ID:ArthurRasmusson,项目名称:UofTHacks2016,代码行数:29,代码来源:pb_BooleanInterface.cs

示例14: Awake

    private void Awake()
    {
        var rectTransform = GetComponent<RectTransform>();
        var textureWidth = (int) rectTransform.rect.width;
        var textureHeight = (int) rectTransform.rect.height;

        var gradient = GameManager.Instance.StateColorDisplayRange;

        var stepCount = Settings.Instance.Amplitude * 2 + 1;

        texture = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false, false);
        var colors = new Color[textureWidth * textureHeight];
        for (var x = 0; x < textureWidth; x++)
        {
            //var color = gradient.Evaluate(Mathf.Clamp((float) x / (textureWidth - 1), cutoffValues.From, cutoffValues.To));
            var t = (float) x / textureWidth;
            var color = gradient.Evaluate((Mathf.FloorToInt(t * stepCount) + 0.5f) / stepCount);
            for (var y = 0; y < textureHeight; y++)
            {
                colors[x + y * textureWidth] = color;
            }
        }

        texture.SetPixels(colors);
        texture.Apply();

        imageDisplay = GetComponent<RawImage>();
        imageDisplay.texture = texture;
    }
开发者ID:TobiasWehrum,项目名称:CH15-FruitFever,代码行数:29,代码来源:GradientDisplay.cs

示例15: CreateSubMips

		public static void CreateSubMips(Cubemap cube) {
			AssetDatabase.StartAssetEditing();
			int faceSize = cube.width;
			string cubePath = AssetDatabase.GetAssetPath(cube);

			//load all sub-assets
			UnityEngine.Object[] mips = AssetDatabase.LoadAllAssetRepresentationsAtPath(cubePath);
			if(mips != null) {
				for(int i=0; i<mips.Length; ++i) {
					if( mips[i] != null && AssetDatabase.IsSubAsset(mips[i]) ) UnityEngine.Object.DestroyImmediate(mips[i], true);
				}
			}
			AssetDatabase.Refresh();

			// skip mip level 0, its in the cubemap itself
			faceSize = faceSize >> 1;
			for( int mip = 1; faceSize > 0; ++mip ) {
				// extract mipmap faces from a cubemap and add them as textures in the sub image
				Texture2D tex = new Texture2D(faceSize, faceSize*6,TextureFormat.ARGB32,false);
				tex.name = "mip"+mip;
				for( int face = 0; face<6; ++face ) {
					tex.SetPixels(0, face*faceSize, faceSize, faceSize, cube.GetPixels((CubemapFace)face,mip));
				}
				tex.Apply();
				AssetDatabase.AddObjectToAsset(tex, cubePath);
				AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tex));
				faceSize = faceSize >> 1;
			}
			AssetDatabase.StopAssetEditing();
			AssetDatabase.Refresh();
		}
开发者ID:keyward,项目名称:EnemyOfMyEnemy,代码行数:31,代码来源:CubeMipProcessor.cs


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