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


C# UnityEngine.Texture2D类代码示例

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


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


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