• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.Texture2D类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Texture2D类属于UnityEngine命名空间,在下文中一共展示了Texture2D类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: UnityGwenRenderer

 /// <summary>
 /// Initializes a new instance of the <see cref="UnityGwenRenderer"/> class.
 /// </summary>
 /// <param name="target">Unity render target.</param>
 public UnityGwenRenderer()
 {
     whiteTex = new Texture2D(1, 1);
     whiteTex.SetPixel(0, 0, UnityEngine.Color.white);
     whiteTex.Apply();
     m_ViewScale = Vector2.one;
 }
开发者ID:jcsnider,项目名称:GWEN.Net-Unity,代码行数:11,代码来源:UnityGwenRenderer.cs


示例2: setContent

    public void setContent()
    {
        if(m_grassTex == null)
            m_grassTex = m_grassSkybox.GetComponent<GrassHandler>().GetDefaultTexs();

        if(m_grassThumbs == null){
            m_grassThumbs = m_grassSkybox.GetComponent<GrassHandler>().GetDefaultThumbs();
        }
        int i=0;
        if(m_grassThumbs.Length == m_grassTex.Length){
            int count = m_grassTex.Length;
            m_texArray = new Texture2D[count];
            Texture2D[] thumbsArray = new Texture2D[count];
            for(;i<count;i++){
                m_texArray[i] =(Texture2D) m_grassTex[i];
                thumbsArray[i] =(Texture2D) m_grassThumbs[i];
            }

            Texture2D grassTex;
            i=0;
            _matTexList = new GUIUpperList (1, 0, TextManager.GetText("Material"), "sousMenuOn", "sousMenuOff", this);
            _matTexList.setImgContent(m_texArray, thumbsArray);
            //_matTexList.display();
            visibility = true;
        }
    }
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:26,代码来源:GUIMatPicker.cs


示例3: CQuadtree

    public CQuadtree(Vector3 up, Vector3 front, CPlanet planet, Texture2D shapeTex)
    {
        m_Planet = planet;
        m_ShapeTex = shapeTex;

        m_Up = m_SUp = up;
        m_Front = m_SFront = front;
        m_Right = -Vector3.Cross(m_Up, m_Front);

        m_Parent = null;
        m_SplitLevel = 0;
        m_Size = m_Planet.m_Radius * 2;

        m_Neighbors[0].node = m_Neighbors[1].node = m_Neighbors[2].node = m_Neighbors[3].node = null;
        m_Neighbors[0].isFixed = m_Neighbors[1].isFixed = m_Neighbors[2].isFixed = m_Neighbors[3].isFixed = false;
        m_Children[0] = m_Children[1] = m_Children[2] = m_Children[3] = null;

        m_NeedsRejoinCount = 0;
        m_HasChildren = false;
        m_NeedsReedge = true;
        m_NeedsTerrain = true;
        m_GapFixMask = 15;

        m_NormalMapTex = null;

        GenVolume();

        m_Plane = new Plane(m_Volume.vertices[0], m_Volume.vertices[2], m_Volume.vertices[1]);
    }
开发者ID:dexo568,项目名称:LightFight,代码行数:29,代码来源:CQuadtree_Indie.cs


示例4: Start

 void Start()
 {
     rend = GetComponent<Renderer>();
     noiseTex = new Texture2D(pixWidth, pixHeight);
     pix = new Color[noiseTex.width * noiseTex.height];
     rend.material.mainTexture = noiseTex;
 }
开发者ID:ewout99,项目名称:Stark_CPR,代码行数:7,代码来源:WaterNoise.cs


示例5: Generate2DTexture

    public void Generate2DTexture()
    {
        texture2D = new Texture2D(n,n,TextureFormat.ARGB32,true);
        int size = n*n;
        Color[] cols = new Color[size];
        float u,v;
        int idx = 0;
        Color c = Color.white;
        for(int i = 0; i < n; i++) {
            u = i/(float)n;
            for(int j = 0; j < n; j++, ++idx) {
              	v = j/(float)n;
                float noise = Mathf.PerlinNoise(u,v);
                c.r = c.g = c.b = noise;
                cols[idx] = c;

            }
        }

        texture2D.SetPixels(cols);
        texture2D.Apply();
        renderer.material.SetTexture("g_tex", texture2D);

        //Color[] cs = texture3D.GetPixels();
        //for(int i = 0; i < 10; i++)
        //	Debug.Log (cs[i]);
    }
开发者ID:kristofe,项目名称:UnityGPUMarchingCubes,代码行数:27,代码来源:Create3DAssets.cs


示例6: Read

    /// <summary>
    /// Reads from the provided file name all parameters and data for a
    /// heightmap.  If the data for the heightmap does not exist, then
    /// no data is written to the provided texture.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> that will store read-in parameters.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> that will store read-in parameters for
    /// <see cref="CloudFractal" />.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" />  that will store read-in parameters for
    /// <see cref="WorleyNoise" />.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    public static void Read(string fileName, ref NormalOptions no,
	                        ref CloudOptions co, ref VoronoiOptions vo,
							ref Texture2D tex)
    {
        using(BinaryReader r = new BinaryReader(File.OpenRead(fileName)))
        {
            no.size = r.ReadInt32();
            no.seed = r.ReadInt32();
            no.cloudInf = r.ReadSingle();
            no.voronoiInf = r.ReadSingle();
            no.useThermalErosion = r.ReadBoolean();
            no.useHydroErosion = r.ReadBoolean();
            no.showSeams = r.ReadBoolean();

            co.upperLeftStart = r.ReadSingle();
            co.lowerLeftStart = r.ReadSingle();
            co.lowerRightStart = r.ReadSingle();
            co.upperRightStart = r.ReadSingle();

            vo.metric = (DistanceFunctions.DistanceMetric)r.ReadInt32();
            vo.combiner = (CombinerFunctions.CombineFunction)r.ReadInt32();
            vo.numberOfFeaturePoints = r.ReadInt32();
            vo.numberOfSubregions = r.ReadInt32();
            vo.multiplier = r.ReadSingle();

            tex.Resize(no.size, no.size);
            int bLeft = (int)(r.BaseStream.Length - r.BaseStream.Position);
            if(bLeft > 0)
                tex.LoadImage(r.ReadBytes(bLeft));
        }
    }
开发者ID:seflopod,项目名称:EarthMake,代码行数:53,代码来源:HeightMapSerializer.cs


示例7: ScreenshotEncode

    IEnumerator ScreenshotEncode()
    {
        // wait for graphics to render
        yield return new WaitForEndOfFrame();

        // create a texture to pass to encoding
        Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        // put buffer into texture
        texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        texture.Apply();

        // split the process up--ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy
        yield return 0;

        byte[] bytes = texture.EncodeToPNG();

        count = PlayerPrefs.GetInt("count");

        // save our test image (could also upload to WWW)
        File.WriteAllBytes(Application.dataPath + "/../testscreen-" + count + ".png", bytes);
        count++;

        PlayerPrefs.SetInt("count", count);

        // Added by Karl. - Tell unity to delete the texture, by default it seems to keep hold of it and memory crashes will occur after too many screenshots.
        DestroyObject(texture);

        Debug.Log( Application.dataPath + "/../testscreen-" + count + ".png" );
    }
开发者ID:JackRFuller,项目名称:Pillar-Pits,代码行数:30,代码来源:TakeScreenshot.cs


示例8: loadIcon

 private Texture2D loadIcon(string path)
 {
     Texture2D result = new Texture2D(1, 1);
         result.LoadImage(System.IO.File.ReadAllBytes(PATH+path));
     result.Apply();
     return result;
 }
开发者ID:Baensi,项目名称:Assets,代码行数:7,代码来源:IconsFactory.cs


示例9: Start

    void Start()
    {
        _img = (Texture2D)Resources.Load("bg1");
        _img2 = (Texture2D)Resources.Load("bg2");

        style = new GUIStyle();

        style.font = (Font)Resources.Load("Fonts/Arial");

        style.active.background = _img2; // not working
        style.hover.background = _img2; // not working
        style.normal.background = _img; // not working

        style.active.textColor = Color.red; // not working
        style.hover.textColor = Color.blue; // not working
        style.normal.textColor = Color.white;

        int border = 30;

        style.border.left = border; // not working, since backgrounds aren't showing
        style.border.right = border; // ---
        style.border.top = border; // ---
        style.border.bottom = border; // ---

        style.stretchWidth = true; // ---
        style.stretchHeight = true; // not working, since backgrounds aren't showing

        style.alignment = TextAnchor.MiddleCenter;
    }
开发者ID:russboss,项目名称:VisTest2,代码行数:29,代码来源:DynamicGUIStyle.cs


示例10: Start

    // Use this for initialization
    void Start()
    {
        // カメラを列挙する
        // 使いたいカメラのインデックスをVideoIndexに入れる
        // 列挙はUnityで使うのはOpenCVだけど、インデックスは同じらしい
        var devices = WebCamTexture.devices;
        for ( int i = 0; i < devices.Length; i++ ) {
            print( string.Format( "index {0}:{1}", i, devices[i].name) );
        }

        // ビデオの設定
        video = new VideoCapture( VideoIndex );
        video.Set( CaptureProperty.FrameWidth, Width );
        video.Set( CaptureProperty.FrameHeight, Height );

        print( string.Format("{0},{1}", Width, Height) );

        // 顔検出器の作成
        cascade = new CascadeClassifier( Application.dataPath + @"/haarcascade_frontalface_alt.xml" );

        // テクスチャの作成
        texture = new Texture2D( Width, Height, TextureFormat.RGB24, false );
        renderer.material.mainTexture = texture;

        // 変換用のカメラの作成
        _Camera = GameObject.Find( Camera.name ).camera;
        print( string.Format( "({0},{1})({2},{3})", Screen.width, Screen.height, _Camera.pixelWidth, _Camera.pixelHeight ) );
    }
开发者ID:kaorun55,项目名称:UnitySandbox,代码行数:29,代码来源:FaceDetect.cs


示例11: Update

    // Update is called once per frame
    void Update()
    {
        // new Vector2 はsource Textureでのピクセル位置

        float srcW = source.width;
        float srcH = source.height;

        // src texture uv position
        Vector2[] uvs = new Vector2[4];
        uvs[0] = new Vector2(P1.localPosition.x/2, P1.localPosition.y/1) /10;
        uvs[1] = new Vector2(P2.localPosition.x/2, P2.localPosition.y/1) /10;
        uvs[2] = new Vector2(P3.localPosition.x/2, P3.localPosition.y/1) /10;
        uvs[3] = new Vector2(P4.localPosition.x/2, P4.localPosition.y/1) /10;

        Color32[] colors = Homography.GetTransformedColors( source, dstWidth, dstHeight,
                                                    new Vector2(uvs[0].x * srcW, uvs[0].y * srcH),
                                                    new Vector2(uvs[1].x * srcW, uvs[1].y * srcH),
                                                    new Vector2(uvs[2].x * srcW, uvs[2].y * srcH),
                                                    new Vector2(uvs[3].x * srcW, uvs[3].y * srcH));
        if(target == null){
            target = new Texture2D(dstWidth, dstHeight);
        }
        target.SetPixels32(colors, 0);
        target.Apply();

        targetRender.material.mainTexture = target;
    }
开发者ID:inoook,项目名称:Homography,代码行数:28,代码来源:Main.cs


示例12: MainScreenButton

	/// <summary>
	/// Draws and returns the value of a GUI.Button.
	/// </summary>
	/// <param name="pos">The position of the button as an interpolant between 0 and 1.</param>
	/// <returns>Whether the button was pressed.</returns>
	private bool MainScreenButton(Vector2 posLerp, Texture2D tex, ScreenPositioningData data)
	{
		return data.GUIButton(posLerp, Cellphone.MainScreen.ButtonSize,
							  new Vector2(Cellphone.MainScreen.ScreenBorder.x * data.ScreenSizeScale.x,
							 			  Cellphone.MainScreen.ScreenBorder.y * data.ScreenSizeScale.y),
							  Cellphone.ButtonStyle, tex);
	}
开发者ID:heyx3,项目名称:PointAndClick,代码行数:12,代码来源:CPState_MainScreen.cs


示例13: OnEnable

    void OnEnable()
    {
		displayManager = target as RUISDisplayManager;
		
        displays = serializedObject.FindProperty("displays");
		ruisMenuPrefab = serializedObject.FindProperty("ruisMenuPrefab");
		
		guiX = serializedObject.FindProperty("guiX");
		guiY = serializedObject.FindProperty("guiY");
		guiZ = serializedObject.FindProperty("guiZ");
		guiScaleX = serializedObject.FindProperty("guiScaleX");
		guiScaleY = serializedObject.FindProperty("guiScaleY");
		hideMouseOnPlay = serializedObject.FindProperty("hideMouseOnPlay");
		
		displayManagerLink = new SerializedObject(displayManager);
		guiDisplayChoiceLink = displayManagerLink.FindProperty("guiDisplayChoice");
		
//        allowResolutionDialog = serializedObject.FindProperty("allowResolutionDialog");
        displayPrefab = Resources.Load("RUIS/Prefabs/Main RUIS/RUISDisplay") as GameObject;

        displayBoxStyle = new GUIStyle();
        displayBoxStyle.normal.textColor = Color.white;
        displayBoxStyle.alignment = TextAnchor.MiddleCenter;
        displayBoxStyle.border = new RectOffset(2, 2, 2, 2);
        displayBoxStyle.margin = new RectOffset(1, 0, 0, 0);
        displayBoxStyle.wordWrap = true;

        monoDisplayTexture = Resources.Load("RUIS/Editor/Textures/monodisplay") as Texture2D;
        stereoDisplayTexture = Resources.Load("RUIS/Editor/Textures/stereodisplay") as Texture2D;
		
		menuCursorPrefab = serializedObject.FindProperty("menuCursorPrefab");
		menuLayer = serializedObject.FindProperty("menuLayer");
    }
开发者ID:znjRoLS,项目名称:RUISAircraftGunner,代码行数:33,代码来源:RUISDisplayManagerEditor.cs


示例14: Monitor

        public Monitor(Int32[] arr, UInt16 ptr, UInt16 chars, UInt16 colPtr, UInt16 modePointer)
        {
            mem = arr;
            pointer = ptr;
            charSetPtr = chars;
            colors = new Color[16];
            modePtr = modePointer;
            for (int i = 0; i < 16; ++i) {
                colors[i] = new Color();
                colors[i].a = 1.0f;
            }
            colorPointer = colPtr;

            image = new Texture2D(256, 256, TextureFormat.ARGB32, false);
            windowPos = new Rect();
            if ((windowPos.x == 0) && (windowPos.y == 0))//windowPos is used to position the GUI window, lets set it in the center of the screen
            {
                windowPos = new Rect(Screen.width / 2, Screen.height / 2, 100, 100);
            }
            //Set all the pixels to black. If you don't do this the image contains random junk.
            for (int y = 0; y < image.height; y++) {
                for (int x = 0; x < image.width; x++) {
                    image.SetPixel(x, y, Color.black);
                }
            }
            image.Apply();
        }
开发者ID:Cilph,项目名称:ProgCom,代码行数:27,代码来源:Monitor.cs


示例15: LoadTexture2DLutFromImage

		public static bool LoadTexture2DLutFromImage( Texture2D texture, ToolSettings settings, out Texture2D lutTexture )
		{
			var width = settings.Resolution.TargetWidth;
			var height = settings.Resolution.TargetHeight;

			var size = settings.LUT.Size;
			var cols = settings.LUT.Columns;
			var rows = settings.LUT.Rows;

			var imageData = texture.GetPixels();

			var lutText = new Texture2D( size * size, size, TextureFormat.ARGB32, false );
			var lutData = new Color[ size * size * size ];


			for ( int h = 0, i = 0; h < size; h++ )
			{
				for ( int r = 0; r < rows; r++ )
				{
					for ( int w = 0; w < size * cols; w++ )
					{
						var x = w;
						var y = h + r * size;
						y = height - 1 - y;
						lutData[ i++ ] = imageData[ x + y * width ];
					}
				}
			}

			lutText.SetPixels( lutData );
			lutText.Apply();
			lutTexture = lutText;

			return true;
		}
开发者ID:cuongngo90,项目名称:Unity-SpriteShader,代码行数:35,代码来源:PhotoshopTouchHelper.cs


示例16: SetSize

 public void SetSize(int w, int h)
 {
     Width = w;
     Height = h;
     Texture = new Texture2D(w, h, TextureFormat.RGB24, false);
     Texture.filterMode = FilterMode.Point;
 }
开发者ID:Takohi-Jona,项目名称:unity-gb,代码行数:7,代码来源:DefaultVideoOutput.cs


示例17: LoadTextureDXT

        public static Texture2D LoadTextureDXT( string path, TextureFormat format, bool mipmap = true )
        {
            var a = Path.Combine( GenFilePaths.CoreModsFolderPath, LoadedModManager.LoadedMods.ToList().Find( s => s.name == "LT_RedistHeat" ).name );
            var b = Path.Combine( a, "Textures" );
            var filePath = Path.Combine( b,  path + ".dds");
            var bytes = File.ReadAllBytes( filePath );

            if (format != TextureFormat.DXT1 && format != TextureFormat.DXT5)
                throw new Exception("Invalid TextureFormat. Only DXT1 and DXT5 formats are supported by this method.");

            var ddsSizeCheck = bytes[4];
            if (ddsSizeCheck != 124)
                throw new Exception("Invalid DDS DXT texture. Unable to read");  //this header byte should be 124 for DDS image files

            var height = bytes[13] * 256 + bytes[12];
            var width = bytes[17] * 256 + bytes[16];

            var dxtBytes = new byte[bytes.Length - DDSHeaderSize];
            Buffer.BlockCopy(bytes, DDSHeaderSize, dxtBytes, 0, bytes.Length - DDSHeaderSize);

            var texture = new Texture2D(width, height, format, mipmap);
            texture.LoadRawTextureData(dxtBytes);
            texture.Apply();

            return (texture);
        }
开发者ID:ForsakenShell,项目名称:RimWorld-RedistHeat,代码行数:26,代码来源:DXTLoader.cs


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


示例19: Capture

    Texture2D Capture(Camera camera, Rect rect)
    {
        // 创建一个RenderTexture对象
        RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
        // 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
        camera.targetTexture = rt;
        camera.Render();
        //ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
        //ps: camera2.targetTexture = rt;
        //ps: camera2.Render();
        //ps: -------------------------------------------------------------------

        // 激活这个rt, 并从中中读取像素。
        RenderTexture.active = rt;
        Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);
        screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
        screenShot.Apply();

        // 重置相关参数,以使用camera继续在屏幕上显示
        camera.targetTexture = null;
        //ps: camera2.targetTexture = null;
        RenderTexture.active = null; // JC: added to avoid errors
        GameObject.Destroy(rt);
        // 最后将这些纹理数据,成一个png图片文件  
        byte[] bytes = screenShot.EncodeToPNG();
        string filename = Application.dataPath + "/Screenshot.png";
        System.IO.File.WriteAllBytes(filename, bytes);
        Debug.Log(string.Format("截屏了一张照片: {0}", filename));

        return screenShot;
    }
开发者ID:zhutaorun,项目名称:unitygame,代码行数:31,代码来源:CaptureCamera.cs


示例20: OnLargeImageLoaded

	private void OnLargeImageLoaded(Texture2D image) {
		if(image != null && !profileImages.ContainsKey(FB_ProfileImageSize.large)) {
			profileImages.Add(FB_ProfileImageSize.large, image);
		}
		
		OnProfileImageLoaded(this);
	}
开发者ID:JulianPaul,项目名称:WhackBash,代码行数:7,代码来源:FB_Score.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.TouchScreenKeyboard类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.Texture类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap