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

C# UnityEngine.Material类代码示例

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

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



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

示例1: OnDisable

        private void OnDisable()
        {
            if (m_Material != null)
                DestroyImmediate(m_Material);

            m_Material = null;
        }
开发者ID:mittens,项目名称:demos_unity,代码行数:7,代码来源:Bloom.cs


示例2: ProcessSharedMaterials

	protected MaterialDesc[] ProcessSharedMaterials( Material[] mats )
	{
		MaterialDesc[] matsDesc = new MaterialDesc [ mats.Length ];
		for ( int i = 0; i < mats.Length; i++ )
		{
			matsDesc[ i ].material = mats[ i ];
			bool legacyCoverage = ( mats[ i ].GetTag( "RenderType", false ) == "TransparentCutout" );
		#if UNITY_4
			bool isCoverage = legacyCoverage;
			matsDesc[ i ].coverage = mats[ i ].HasProperty( "_MainTex" ) && isCoverage;
		#else
			bool isCoverage = legacyCoverage || mats[ i ].IsKeywordEnabled( "_ALPHATEST_ON" );
			matsDesc[ i ].propertyBlock = new MaterialPropertyBlock();
			matsDesc[ i ].coverage = mats[ i ].HasProperty( "_MainTex" ) && isCoverage;
		#endif
			matsDesc[ i ].cutoff = mats[ i ].HasProperty( "_Cutoff" );

			if ( isCoverage && !matsDesc[ i ].coverage && !m_materialWarnings.Contains( matsDesc[ i ].material ) )
			{
				Debug.LogWarning( "[AmplifyMotion] TransparentCutout material \"" + matsDesc[ i ].material.name + "\" {" + matsDesc[ i ].material.shader.name + "} not using _MainTex standard property." );
				m_materialWarnings.Add( matsDesc[ i ].material );
			}
		}
		return matsDesc;
	}
开发者ID:mirrorfishmedia,项目名称:GGJ2016,代码行数:25,代码来源:AmplifyMotionObjectBase.cs


示例3: OnRenderImage

        void OnRenderImage(RenderTexture src, RenderTexture dst)
        {
            if (m_material == null)
            {
                m_material = new Material(m_shader);
            }

            if (m_edge_highlighting)
            {
                m_material.EnableKeyword("ENABLE_EDGE_HIGHLIGHTING");
            }
            else
            {
                m_material.DisableKeyword("ENABLE_EDGE_HIGHLIGHTING");
            }

            if (m_mul_smoothness)
            {
                m_material.EnableKeyword("ENABLE_SMOOTHNESS_ATTENUAION");
            }
            else
            {
                m_material.DisableKeyword("ENABLE_SMOOTHNESS_ATTENUAION");
            }

            m_material.SetVector("_Color", GetLinearColor());
            m_material.SetVector("_Params1", new Vector4(m_fresnel_bias, m_fresnel_scale, m_fresnel_pow, m_intensity));
            m_material.SetVector("_Params2", new Vector4(m_edge_intensity, m_edge_threshold, m_edge_radius, 0.0f));
            Graphics.Blit(src, dst, m_material);
        }
开发者ID:nicegary,项目名称:Unity5Effects,代码行数:30,代码来源:RimLight.cs


示例4: CustomGraphicsBlit

        static void CustomGraphicsBlit(RenderTexture source, RenderTexture dest, Material fxMaterial, int passNr)
        {
            RenderTexture.active = dest;

            fxMaterial.SetTexture ("_MainTex", source);

            GL.PushMatrix ();
            GL.LoadOrtho ();

            fxMaterial.SetPass (passNr);

            GL.Begin (GL.QUADS);

            GL.MultiTexCoord2 (0, 0.0f, 0.0f);
            GL.Vertex3 (0.0f, 0.0f, 3.0f); // BL

            GL.MultiTexCoord2 (0, 1.0f, 0.0f);
            GL.Vertex3 (1.0f, 0.0f, 2.0f); // BR

            GL.MultiTexCoord2 (0, 1.0f, 1.0f);
            GL.Vertex3 (1.0f, 1.0f, 1.0f); // TR

            GL.MultiTexCoord2 (0, 0.0f, 1.0f);
            GL.Vertex3 (0.0f, 1.0f, 0.0f); // TL

            GL.End ();
            GL.PopMatrix ();
        }
开发者ID:hongaaronc,项目名称:IntermediateGame,代码行数:28,代码来源:GlobalFog.cs


示例5: SetKeyword

 static void SetKeyword(Material m, string keyword, bool state)
 {
     if (state)
         m.EnableKeyword(keyword);
     else
         m.DisableKeyword(keyword);
 }
开发者ID:Zero-Ax,项目名称:Mouse-position-Drag,代码行数:7,代码来源:SprayUnlitMaterialEditor.cs


示例6: ImportTexturesFromXml

        private void ImportTexturesFromXml(XDocument xml)
        {
            var texData = xml.Root.Elements("ImportTexture");
            foreach (var tex in texData)
            {
                string name = tex.Attribute("filename").Value;
                string data = tex.Value;

                // The data is gzip compressed base64 string. We need the raw bytes.
                //byte[] bytes = ImportUtils.GzipBase64ToBytes(data);
                byte[] bytes = ImportUtils.Base64ToBytes(data);

                // Save and import the texture asset
                {
                    string pathToSave = GetTextureAssetPath(name);
                    ImportUtils.ReadyToWrite(pathToSave);
                    File.WriteAllBytes(pathToSave, bytes);
                    AssetDatabase.ImportAsset(pathToSave, ImportAssetOptions.ForceSynchronousImport);
                }

                // Create a material if needed in prepartion for the texture being successfully imported
                {
                    string materialPath = GetMaterialAssetPath(name);
                    Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
                    if (material == null)
                    {
                        // We need to create the material afterall
                        // Use our custom shader
                        material = new Material(Shader.Find("Tiled/TextureTintSnap"));
                        ImportUtils.ReadyToWrite(materialPath);
                        AssetDatabase.CreateAsset(material, materialPath);
                    }
                }
            }
        }
开发者ID:Feoden90,项目名称:140Clone,代码行数:35,代码来源:ImportTiled2Unity.Xml.cs


示例7: Apply

        public void Apply(CloudsMaterial material, float radius, Transform parent)
        {
            Remove();
            particleMaterial.MaxScale = size.y;
            particleMaterial.MaxTrans = maxTranslation;
            particleMaterial.NoiseScale =  new Vector3(noiseScale.x, noiseScale.y, noiseScale.z / radius);
            ParticleMaterial = new Material(ParticleCloudShader);
            particleMaterial.ApplyMaterialProperties(ParticleMaterial);
            material.ApplyMaterialProperties(ParticleMaterial);
            ParticleMaterial.EnableKeyword("SOFT_DEPTH_ON");

            volumeHolder = new GameObject();
            //Add the renderer here so othe rentities (shadows)
            //can easily access it.
            Renderer r = volumeHolder.AddComponent<MeshRenderer>();
            r.material = ParticleMaterial;
            ParticleMaterial.SetMatrix(ShaderProperties._ShadowBodies_PROPERTY, Matrix4x4.zero);
            ParticleMaterial.renderQueue = (int)Tools.Queue.Transparent + 2;

            r.enabled = false;
            volumeHolder.transform.parent = parent;
            volumeHolder.transform.localPosition = Vector3.zero;
            volumeHolder.transform.localScale = Vector3.one;
            volumeHolder.transform.localRotation = Quaternion.identity;
            volumeHolder.layer = (int)Tools.Layer.Local;
            volumeManager = new VolumeManager(radius, size, ParticleMaterial, volumeHolder.transform, area.x, (int)area.y);
            
        }
开发者ID:Kerbas-ad-astra,项目名称:EnvironmentalVisualEnhancements,代码行数:28,代码来源:CloudsVolume.cs


示例8: SpriteAnimator

 public SpriteAnimator(Material material, int columnCount)
 {
     this.material = material;
     this.spriteSheetColumnCount = columnCount;
     this.Sequences = new List<SpriteAnimationSequence>();
     this.Settings = new SpriteAnimationSettings();
 }
开发者ID:maximecharron,项目名称:GLO-3002-Frima,代码行数:7,代码来源:SpriteAnimator.cs


示例9: OnEnable

        void OnEnable()
        {
            foreach(Transform child in transform)
            {
                //Search for child Loading Background to get the mesh renderer for the background texture
                if(child.name == "Loading Background")
                {
                    m_MeshRenderer = child.GetComponent<MeshRenderer>();
                }
                if(child.name == "Loading Percent")
                {
                    m_LoadingText = child.GetComponent<TextMesh>();
                }
            }

            if(m_MeshRenderer == null)
            {
                Debug.LogError("Missing a gameobject with the name \'Loading Background\' and a \'MeshRenderer\' component.");
                gameObject.SetActive(false);
                return;
            }
            if(m_LoadingText == null)
            {
                Debug.LogError("Missing a gameobject with the name \'Loading Text\' and a \'TextMesh\' component.");
                gameObject.SetActive(false);
                return;
            }
            Material material = new Material(m_MeshRenderer.sharedMaterial);
            material.SetTexture("_MainTex", m_TextureToDisplay);
            m_MeshRenderer.material = material;
        }
开发者ID:NathanSaidas,项目名称:OnLooker_Unity,代码行数:31,代码来源:LoadScreen.cs


示例10: FourierGPU

	public FourierGPU(int size)
	{	
		if(size > 256)
		{
			Debug.Log("FourierGPU::FourierGPU - fourier grid size must not be greater than 256, changing to 256");
			size = 256;
		}
		
		if(!Mathf.IsPowerOfTwo(size))
		{
			Debug.Log("FourierGPU::FourierGPU - fourier grid size must be pow2 number, changing to nearest pow2 number");
			size = Mathf.NextPowerOfTwo(size);
		}
		
//		Shader shader = Shader.Find("Math/Fourier");
		Shader shader = ShaderTool.GetShader2 ("CompiledFourier.shader");

		if(shader == null) Debug.Log("FourierGPU::FourierGPU - Could not find shader Math/Fourier");
	
		m_fourier = new Material(shader);

		m_size = size; //must be pow2 num
		m_fsize = (float)m_size;
		m_passes = (int)(Mathf.Log(m_fsize)/Mathf.Log(2.0f));
		
		m_butterflyLookupTable = new Texture2D[m_passes];
		
		ComputeButterflyLookupTable();
		
		m_fourier.SetFloat("_Size", m_fsize);
	}
开发者ID:kharbechteinn,项目名称:Scatterer,代码行数:31,代码来源:FourierGPU.cs


示例11: CreateInstance

		public static pb_Renderable CreateInstance(Mesh InMesh, Material InMaterial)
		{
			pb_Renderable ren = ScriptableObject.CreateInstance<pb_Renderable>();
			ren.mesh = InMesh;
			ren.materials = new Material[] { InMaterial };
			return ren;
		}
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:7,代码来源:pb_Renderable.cs


示例12: CreatePrefab

		public void CreatePrefab()
		{
			if (prefabAtmosphere == null)
			{
				prefabAtmosphere = new GameObject ("RefractiveAtmosphere");
				prefabAtmosphere.SetActive (false);
				var mf = prefabAtmosphere.AddComponent<MeshFilter> ();
				var mr = prefabAtmosphere.AddComponent<MeshRenderer> ();
				mr.castShadows = false;
				mr.receiveShadows = false;

				var material = new Material (Shaders.RefractiveAtmosphere);
				var _normals = new Texture2D (4, 4, TextureFormat.ARGB32, false);
				_normals.LoadImage (Textures.RefractiveAtmosphereNormals);
				material.SetTexture ("_BumpMap", _normals);
				material.SetTextureScale ("_BumpMap", new Vector2 (4f, 4f));
				material.SetVector ("_BumpMapOffset", new Vector4 (0, 0, 1, 0));

				mr.sharedMaterial = material;

				var sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere);
				var sphereMesh = sphere.GetComponent<MeshFilter> ().mesh;
				DestroyImmediate (sphere);
				mf.sharedMesh = sphereMesh;

				var behaviour = prefabAtmosphere.AddComponent<RefractiveAtmosphere> ();

				prefabAtmosphere.transform.localScale = Vector3.one * 1250f;

				DontDestroyOnLoad (prefabAtmosphere);
			}
		}
开发者ID:Kerbas-ad-astra,项目名称:KopernicusExpansion,代码行数:32,代码来源:RefractiveAtmosphereLoader.cs


示例13: FromMaterial

        public static SMaterial FromMaterial(Material mat)
        {
            if (mat == null)
                return null;

            Shader shader = mat.shader;
            if (shader == null)
                return null;

            SMaterial result = new SMaterial();
            result.instanceID = mat.GetInstanceID();
            result.materialName = mat.name;
            result.shaderName = shader.name;

            ShaderProperties.Info info = ShaderPropertyHelper.GetShaderInfo(shader.name);

            if (info != null){
                ComposedByteStream rawData = new ComposedByteStream();

                int iMax = info.propertyNames.Length;
                for (int i = 0; i < iMax; i++)
                {
                    string propName = info.propertyNames[i];
                    switch (info.propertyTypes[i])
                    {
                        case ShaderProperties.PropType.Color:
                            Color color = mat.GetColor(propName);
                            rawData.AddStream(new float[] { color.r, color.g, color.b, color.a });
                            break;

                        case ShaderProperties.PropType.Range:
                        case ShaderProperties.PropType.Float:
                            rawData.AddStream(new float[] { mat.GetFloat(propName) });
                            break;

                        case ShaderProperties.PropType.TexEnv:
                            Texture texture = mat.GetTexture(propName);
                            Vector2 offset = mat.GetTextureOffset(propName);
                            Vector2 scale = mat.GetTextureScale(propName);

                            rawData.AddStream(new int[] { texture != null ? texture.GetInstanceID() : -1 });
                            rawData.AddStream(texture != null ? texture.name : "" );
                            rawData.AddStream(new float[] { offset.x, offset.y });
                            rawData.AddStream(new float[] { scale.x, scale.y });
                            break;

                        case ShaderProperties.PropType.Vector:
                            Vector4 vector = mat.GetVector(propName);
                            rawData.AddStream(new float[] { vector.x, vector.y, vector.z, vector.w });
                            break;
                    }
                }
                result.rawData = rawData.Compose();
                return result;
            } else {
                if (vBug.settings.general.debugMode)
                    Debug.LogError("No shader-info found @" + shader.name);
                return null;
            }
        }
开发者ID:WhiteRavensGame,项目名称:JRPGTownPrototype,代码行数:60,代码来源:MaterialSerializeHelper.cs


示例14: AssignNewShaderToMaterial

 public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
 {
     if (material.HasProperty("_Emission"))
     {
         material.SetColor("_EmissionColor", material.GetColor("_Emission"));
     }
     base.AssignNewShaderToMaterial(material, oldShader, newShader);
     if ((oldShader == null) || !oldShader.name.Contains("Legacy Shaders/"))
     {
         SetupMaterialWithBlendMode(material, (BlendMode) ((int) material.GetFloat("_Mode")));
     }
     else
     {
         BlendMode opaque = BlendMode.Opaque;
         if (oldShader.name.Contains("/Transparent/Cutout/"))
         {
             opaque = BlendMode.Cutout;
         }
         else if (oldShader.name.Contains("/Transparent/"))
         {
             opaque = BlendMode.Fade;
         }
         material.SetFloat("_Mode", (float) opaque);
         Material[] mats = new Material[] { material };
         this.DetermineWorkflow(MaterialEditor.GetMaterialProperties(mats));
         MaterialChanged(material, this.m_WorkflowMode);
     }
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:28,代码来源:StandardShaderGUI.cs


示例15: CheckResources

        protected override bool CheckResources()
        {
            CheckSupport(mode == ColorCorrectionMode.Advanced);

            ccMaterial = CheckShaderAndCreateMaterial(simpleColorCorrectionCurvesShader, ccMaterial);
            ccDepthMaterial = CheckShaderAndCreateMaterial(colorCorrectionCurvesShader, ccDepthMaterial);
            selectiveCcMaterial = CheckShaderAndCreateMaterial(colorCorrectionSelectiveShader, selectiveCcMaterial);

            if (!rgbChannelTex)
                rgbChannelTex = new Texture2D(256, 4, TextureFormat.ARGB32, false, true);
            if (!rgbDepthChannelTex)
                rgbDepthChannelTex = new Texture2D(256, 4, TextureFormat.ARGB32, false, true);
            if (!zCurveTex)
                zCurveTex = new Texture2D(256, 1, TextureFormat.ARGB32, false, true);

            rgbChannelTex.hideFlags = HideFlags.DontSave;
            rgbDepthChannelTex.hideFlags = HideFlags.DontSave;
            zCurveTex.hideFlags = HideFlags.DontSave;

            rgbChannelTex.wrapMode = TextureWrapMode.Clamp;
            rgbDepthChannelTex.wrapMode = TextureWrapMode.Clamp;
            zCurveTex.wrapMode = TextureWrapMode.Clamp;

            if (!isSupported)
                ReportAutoDisable();
            return isSupported;
        }
开发者ID:FairyHamaLab,项目名称:Desertion,代码行数:27,代码来源:ColorCorrectionCurves.cs


示例16: Create

        public static void Create(Vector3 position, Vector3 normal)
        {
            var effect = new GameObject("Particle Effect");
            effect.transform.position = position;
            effect.transform.rotation = Quaternion.LookRotation(normal);

            var particleSystem = effect.AddComponent<ParticleSystem>();
            particleSystem.startLifetime = 0.4f;
            particleSystem.startSpeed = 15;
            particleSystem.startSize = 0.13f;
            particleSystem.emissionRate = 100;
            particleSystem.loop = false;

            Material material = new Material(Shader.Find(" Diffuse"));
            material.color = Color.black;
            effect.GetComponent<ParticleSystemRenderer>().sharedMaterial = material;

            GameObject.Destroy(effect, 0.2f);

            /*for (int i = 0; i < 30; i++)
            {
                ParticleSystem.Particle p = new ParticleSystem.Particle();
                p.velocity = normal*5;
                //p.position = position;
                p.lifetime = 5;
                particleSystem.Emit(p);
            }
            particleSystem.Play();*/
        }
开发者ID:Fr0sZ,项目名称:Skylines-Multiplayer,代码行数:29,代码来源:BulletHitParticlePrefab.cs


示例17: CheckShaderAndCreateMaterial

        protected Material CheckShaderAndCreateMaterial(Shader s, Material m2Create)
        {
            if (!s)
            {
                Debug.Log("Missing shader in " + this.ToString());
                enabled = false;
                return null;
            }

            if (s.isSupported && m2Create && m2Create.shader == s)
                return m2Create;

            if (!s.isSupported)
            {
                enabled = false;
                isSupported = false;
                Debug.Log("The shader " + s.ToString() + " on effect " + this.ToString() + " is not supported on this platform!");
                return null;
            }
            else
            {
                //Debug.Log("Creating material");
                m2Create = new Material(s);
                m2Create.hideFlags = HideFlags.DontSave;
                if (m2Create)
                {
                    return m2Create;
                }
                else
                    return null;
            }
        }
开发者ID:Waffletech,项目名称:KerbalKwality,代码行数:32,代码来源:ImageEffectBase.cs


示例18: Grow

        IEnumerator Grow()
        {
            float f = 0;
            float t = 0;
            Vector3 originalScale = transform.localScale;
            Vector3 targetScale = originalScale * EndScale;
            Material originalMaterial = new Material(renderer.material);
            Color originalColor = originalMaterial.GetColor("_TintColor");
            Color targetColor = new Color(originalColor.r, originalColor.g, originalColor.b, 0F);
            renderer.material = originalMaterial;

            while (f <= duration)
            {
                t = f / duration;
                transform.localScale = Vector3.Lerp(originalScale, targetScale, t);

                originalMaterial.SetColor("_TintColor", Color.Lerp(originalColor, targetColor, t));

                f += Time.deltaTime;
                yield return new WaitForEndOfFrame();
            }

            if (mode == FXmode.DestroyAtEnd)
                Destroy(gameObject);

            else if (mode == FXmode.Loop)
                Play();
        }
开发者ID:Groutcho,项目名称:EventHorizon,代码行数:28,代码来源:Shockwave.cs


示例19: CreateDecal

        public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale)
        {
            GameObject decal = new GameObject();
            decal.name = "Decal" + decal.GetInstanceID();

            decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale);
            decal.AddComponent<MeshRenderer>().sharedMaterial = mat;

            #if UNITY_5
            decal.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            #else
            decal.GetComponent<MeshRenderer>().castShadows = false;
            #endif

            qd_Decal decalComponent = decal.AddComponent<qd_Decal>();

            decalComponent.SetScale(scale);
            decalComponent.SetTexture( (Texture2D)mat.mainTexture );
            decalComponent.SetUVRect(uvCoords);

            #if DEBUG
            decal.AddComponent<qd_DecalDebug>();
            #endif

            return decal;
        }
开发者ID:zjucsxxd,项目名称:UnityRepository,代码行数:26,代码来源:qd_Mesh.cs


示例20: Minimap

        public Minimap()
        {
            // Init minimap
            m_gameObject = new GameObject();
            m_icons = new List<MinimapIcon>();
            m_origBounds = new Rect(1920 - 224, 16, 209, 184);
            UpdateBounds();

            // Create the minimap render texture
            m_minimap = (Material)UnityEngine.Resources.Load("textures/minimapRT");

            // Create Camera
            m_camera = m_gameObject.AddComponent<Camera>();
            m_camera.isOrthoGraphic = true;
            m_camera.orthographicSize = 500f;
            m_camera.nearClipPlane = 10f;
            m_camera.farClipPlane = 1000f;
            m_camera.clearFlags = CameraClearFlags.Color;
            m_camera.backgroundColor = Color.black;
            m_camera.targetTexture = (RenderTexture)m_minimap.mainTexture;
            m_camera.rect = new Rect(0f, 0f, 1f, 1f);
            m_camera.cullingMask = 1 << LayerMask.NameToLayer("Terrain");
            m_gameObject.transform.position = new Vector3(0f, 100f, 0f);
            m_gameObject.transform.eulerAngles = new Vector3(90f, 0f, 0f);
            m_gameObject.layer = LayerMask.NameToLayer("Minimap");
            m_gameObject.name = "Minimap";
        }
开发者ID:JJJohan,项目名称:RTS,代码行数:27,代码来源:Minimap.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.MaterialPropertyBlock类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.LineRenderer类代码示例发布时间: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