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


C# Material.GetVector方法代码示例

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


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

示例1: CopyMaterialProperties

        /// <summary>
        /// Copy Shader properties from source to destination material.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static void CopyMaterialProperties(Material source, Material destination)
        {
            MaterialProperty[] source_prop = MaterialEditor.GetMaterialProperties(new Material[] { source });

            for (int i = 0; i < source_prop.Length; i++)
            {
                int property_ID = Shader.PropertyToID(source_prop[i].name);
                if (destination.HasProperty(property_ID))
                {
                    //Debug.Log(source_prop[i].name + "  Type:" + ShaderUtil.GetPropertyType(source.shader, i));
                    switch (ShaderUtil.GetPropertyType(source.shader, i))
                    {
                        case ShaderUtil.ShaderPropertyType.Color:
                            destination.SetColor(property_ID, source.GetColor(property_ID));                          
                            break;
                        case ShaderUtil.ShaderPropertyType.Float:
                            destination.SetFloat(property_ID, source.GetFloat(property_ID));
                            break;
                        case ShaderUtil.ShaderPropertyType.Range:
                            destination.SetFloat(property_ID, source.GetFloat(property_ID));
                            break;
                        case ShaderUtil.ShaderPropertyType.TexEnv:
                            destination.SetTexture(property_ID, source.GetTexture(property_ID));
                            break;
                        case ShaderUtil.ShaderPropertyType.Vector:
                            destination.SetVector(property_ID, source.GetVector(property_ID));
                            break;
                    }
                }
            }

        }
开发者ID:koko11,项目名称:MatrixVR,代码行数:37,代码来源:TMPro_EditorShaderUtilities.cs

示例2: SetFromToCurrent

 public void SetFromToCurrent()
 {
     if (_material = material)
     {
         from = _material.GetVector(propertyID);
     }
 }
开发者ID:izaleu,项目名称:Steamplane,代码行数:7,代码来源:TweenMaterialVector.cs

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

示例4: OnRecord

 public override void OnRecord()
 {
     if (_material = material)
     {
         _original = _material.GetVector(propertyID);
     }
 }
开发者ID:izaleu,项目名称:Steamplane,代码行数:7,代码来源:TweenMaterialVector.cs

示例5: GetValues

	public List<StoredValue> GetValues(Material m)
	{
		var list = GetShaderProperties(m);
		var output = new List<StoredValue>();
		foreach(var p in list)
		{
			var o = new StoredValue { Property = p };
			output.Add(o);
			switch(p.type)
			{
			case MaterialProperty.PropertyType.color:
				o.Value = m.GetColor(p.name);
				break;
			case MaterialProperty.PropertyType.real:
				o.Value = m.GetFloat(p.name);
				break;
			case MaterialProperty.PropertyType.texture:
				o.Value = m.GetTexture(p.name);
				break;
			case MaterialProperty.PropertyType.vector:
				o.Value = m.GetVector(p.name);
				break;
			case MaterialProperty.PropertyType.textureOffset:
				o.Value = m.GetTextureOffset(p.name);
				break;
			case MaterialProperty.PropertyType.textureScale:
				o.Value = m.GetTextureScale(p.name);
				break;
			case MaterialProperty.PropertyType.matrix:
				o.Value = m.GetMatrix(p.name);
				break;
			}
		}
		return output;
	}
开发者ID:MHaubenstock,项目名称:RPG-Board-3D,代码行数:35,代码来源:StoreMaterials.cs

示例6: SetMatrix

 static void SetMatrix(Material material)
 {
     var r = material.GetVector("_Euler");
     var q = Quaternion.Euler(r.x, r.y, r.z);
     var m = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
     material.SetVector("_Rotation1", m.GetRow(0));
     material.SetVector("_Rotation2", m.GetRow(1));
     material.SetVector("_Rotation3", m.GetRow(2));
 }
开发者ID:esther5576,项目名称:SW-game-project,代码行数:9,代码来源:CubemapMaterialEditor.cs

示例7: OnTween

        public override void OnTween(float factor)
        {
            if (_material = material)
            {
                _temp = _material.GetVector(propertyID);

                if (mask.GetBit(0)) _temp.x = from.x + (to.x - from.x) * factor;
                if (mask.GetBit(1)) _temp.y = from.y + (to.y - from.y) * factor;
                if (mask.GetBit(2)) _temp.z = from.z + (to.z - from.z) * factor;
                if (mask.GetBit(3)) _temp.w = from.w + (to.w - from.w) * factor;

                _material.SetVector(propertyID, _temp);
            }
        }
开发者ID:izaleu,项目名称:Steamplane,代码行数:14,代码来源:TweenMaterialVector.cs

示例8: WriteToJson

        public void WriteToJson(IResMgr resmgr, Material mat, MyJson.JsonNode_Object json)
        {
            json["shaderName"] = new MyJson.JsonNode_ValueString(this.shaderName);
            if (jsonConfig.ContainsKey("params"))
            {
                foreach (var item in jsonConfig["params"].asDict())
                {
                    //Debug.Log(item.Value);
                    string type = item.Value.asDict()["type"].AsString();
                    string flag = item.Value.asDict()["flags"].AsString();
                    string name = item.Value.asDict()["name"].AsString();
                    if (type == "Float" || type == "Range")
                    {
                        json[name] = new MyJson.JsonNode_ValueNumber(mat.GetFloat(name));
                    }
                    else if (type == "Vector")
                    {
                        json[name] = new MyJson.JsonNode_ValueString(StringHelper.ToString(mat.GetVector(name)));
                    }
                    else if (type == "Color")
                    {
                        json[name] = new MyJson.JsonNode_ValueString(StringHelper.ToString((Color32)mat.GetColor(name)));
                    }
                    else if (type == "Texture")
                    {
                        string texdim = item.Value.asDict()["texdim"].AsString();
                        var tex = mat.GetTexture(name);
                        if (tex != null)
                        {
                            if (texdim == "Tex2D")
                            {
                                string texname = resmgr.SaveTexture(tex as Texture2D);
                                json[name] = new MyJson.JsonNode_ValueString(texname);
                            }
                            else
                            {
                                throw new Exception("not support texdim:" + texdim);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("not support type:" + type);
                    }

                }
            }

        }
开发者ID:lightszero,项目名称:EgretUnity,代码行数:49,代码来源:NewMatParser.cs

示例9: BuildPreviewTexture

		private static Texture2D BuildPreviewTexture(int width, int height, Sprite sprite, Material spriteRendererMaterial)
		{
			if (!ShaderUtil.hardwareSupportsRectRenderTexture)
			{
				return null;
			}
			float width2 = sprite.rect.width;
			float height2 = sprite.rect.height;
			Texture2D spriteTexture = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(sprite, false);
			PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int)width2, (int)height2, ref width, ref height);
			EditorUtility.SetTemporarilyAllowIndieRenderTexture(true);
			SavedRenderTargetState savedRenderTargetState = new SavedRenderTargetState();
			RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default);
			RenderTexture.active = temporary;
			GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
			GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
			Texture texture = null;
			Vector4 vector = new Vector4(0f, 0f, 0f, 0f);
			bool flag = false;
			bool flag2 = false;
			if (spriteRendererMaterial != null)
			{
				flag = spriteRendererMaterial.HasProperty("_MainTex");
				flag2 = spriteRendererMaterial.HasProperty("_MainTex_TexelSize");
			}
			Material material = null;
			if (spriteRendererMaterial != null)
			{
				if (flag)
				{
					texture = spriteRendererMaterial.GetTexture("_MainTex");
					spriteRendererMaterial.SetTexture("_MainTex", spriteTexture);
				}
				if (flag2)
				{
					vector = spriteRendererMaterial.GetVector("_MainTex_TexelSize");
					spriteRendererMaterial.SetVector("_MainTex_TexelSize", TextureUtil.GetTexelSizeVector(spriteTexture));
				}
				spriteRendererMaterial.SetPass(0);
			}
			else
			{
				material = new Material(Shader.Find("Hidden/BlitCopy"));
				material.mainTexture = spriteTexture;
				material.SetPass(0);
			}
			float num = sprite.rect.width / sprite.bounds.size.x;
			Vector2[] vertices = sprite.vertices;
			Vector2[] uv = sprite.uv;
			ushort[] triangles = sprite.triangles;
			Vector2 pivot = sprite.pivot;
			GL.PushMatrix();
			GL.LoadOrtho();
			GL.Color(new Color(1f, 1f, 1f, 1f));
			GL.Begin(4);
			for (int i = 0; i < sprite.triangles.Length; i++)
			{
				ushort num2 = triangles[i];
				Vector2 vector2 = vertices[(int)num2];
				Vector2 vector3 = uv[(int)num2];
				GL.TexCoord(new Vector3(vector3.x, vector3.y, 0f));
				GL.Vertex3((vector2.x * num + pivot.x) / width2, (vector2.y * num + pivot.y) / height2, 0f);
			}
			GL.End();
			GL.PopMatrix();
			GL.sRGBWrite = false;
			if (spriteRendererMaterial != null)
			{
				if (flag)
				{
					spriteRendererMaterial.SetTexture("_MainTex", texture);
				}
				if (flag2)
				{
					spriteRendererMaterial.SetVector("_MainTex_TexelSize", vector);
				}
			}
			Texture2D texture2D = new Texture2D(width, height, TextureFormat.ARGB32, false);
			texture2D.hideFlags = HideFlags.HideAndDontSave;
			texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
			texture2D.Apply();
			RenderTexture.ReleaseTemporary(temporary);
			savedRenderTargetState.Restore();
			EditorUtility.SetTemporarilyAllowIndieRenderTexture(false);
			if (material != null)
			{
				UnityEngine.Object.DestroyImmediate(material);
			}
			return texture2D;
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:90,代码来源:SpriteInspector.cs

示例10: GetValues

 /// <summary>
 /// Gets the values given a material
 /// </summary>
 /// <param name="m">The material</param>
 /// <returns>A StoredValue containing value and type information</returns>
 public List<StoredValue> GetValues(Material m)
 {
     var list = GetShaderProperties(m);
     var output = new List<StoredValue>();
     foreach (var p in list) {
         var o = new StoredValue {
             property = p
         };
         output.Add(o);
         switch (p.type) {
             case MaterialProperty.PropertyType.Color:
                 o.value = new object[1];
                 o.value[0] = m.GetColor(p.name);
                 break;
             case MaterialProperty.PropertyType.Float:
                 o.value = new object[1];
                 o.value[0] = m.GetFloat(p.name);
                 break;
             case MaterialProperty.PropertyType.Range:
                 o.value = new object[1];
                 o.value[0] = m.GetFloat(p.name);
                 break;
             case MaterialProperty.PropertyType.TexEnv:
                 o.value = new object[3];
                 o.value[0] = m.GetTexture(p.name);
                 o.value[1] = m.GetTextureOffset(p.name);
                 o.value[2] = m.GetTextureScale(p.name);
                 break;
             case MaterialProperty.PropertyType.Vector:
                 o.value = new object[1];
                 o.value[0] = m.GetVector(p.name);
                 break;
             default:
                 Debug.LogError("Unsupported type: " + p.type.ToString());
                 break;
         }
     }
     return output;
 }
开发者ID:Bloodcoder,项目名称:unityserializer-ng,代码行数:44,代码来源:StoreMaterials.cs

示例11: DumpShaderMaterial

        private BabylonMaterial DumpShaderMaterial(Material material)
        {
            if (materialsDictionary.ContainsKey(material.name))
            {
                return materialsDictionary[material.name];
            }

            var babylonShaderMaterial = new BabylonShaderMaterial
            {
                name = material.name,
                id = Guid.NewGuid().ToString(),
            };

            ExporterWindow.ReportProgress(1, "Exporting glsl material: " + material.name);

            List<string> tnames = material.GetTextureNames();
            foreach (string tname in tnames)
            {
                BabylonTexture tdata = DumpTextureFromMaterial(material, tname);
                if (tdata != null)
                {
                    babylonShaderMaterial.textures.Add(tname, tdata);
                }
            }

            List<string> fnames = material.GetFloatNames();
            foreach (string fname in fnames)
            {
                float fdata = material.GetFloat(fname);
                babylonShaderMaterial.floats.Add(fname, fdata);
            }

            List<string> rnames = material.GetRangeNames();
            foreach (string rname in rnames)
            {
                float rdata = material.GetFloat(rname);
                babylonShaderMaterial.floats.Add(rname, rdata);
            }

            List<string> cnames = material.GetColorNames();
            foreach (string cname in cnames)
            {
                Color cdata = material.GetColor(cname);
                babylonShaderMaterial.vectors4.Add(cname, cdata.ToFloat());
            }

            List<string> vnames = material.GetVectorNames();
            foreach (string vname in vnames)
            {
                Vector4 vdata = material.GetVector(vname);
                babylonShaderMaterial.vectors4.Add(vname, vdata.ToFloat());
            }

            Shader shader = material.shader;
            string filename = AssetDatabase.GetAssetPath(shader);
            string program = Tools.LoadTextAsset(filename);
            string basename = shader.name.Replace("BabylonJS/", "").Replace("/", "_").Replace(" ", "");
            string outpath = (!String.IsNullOrEmpty(exportationOptions.DefaultShaderFolder)) ? exportationOptions.DefaultShaderFolder : OutputPath;

            var shaderpath = new Dictionary<string, string>();
            List<string> attributeList = new List<string>();
            List<string> uniformList = new List<string>();
            List<string> samplerList = new List<string>();
            List<string> defineList = new List<string>();
            string babylonOptions = GetShaderProgramSection(basename, program, BabylonProgramSection.Babylon);
            string[] babylonLines = babylonOptions.Split('\n');
            foreach (string babylonLine in babylonLines)
            {
                if (babylonLine.IndexOf("attributes", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    string[] attributes = babylonLine.Split(':');
                    if (attributes != null && attributes.Length > 1)
                    {
                        string abuffer = attributes[1].Replace("[", "").Replace("]", "");
                        if (!String.IsNullOrEmpty(abuffer))
                        {
                            abuffer = abuffer.Trim();
                            string[] adata = abuffer.Split(',');
                            if (adata != null && adata.Length > 0)
                            {
                                foreach (string aoption in adata)
                                {
                                    string aoption_buffer = aoption.Trim().Replace("\"", "").Trim();
                                    if (!String.IsNullOrEmpty(aoption_buffer))
                                    {
                                        attributeList.Add(aoption_buffer);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (babylonLine.IndexOf("uniforms", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    string[] uniforms = babylonLine.Split(':');
                    if (uniforms != null && uniforms.Length > 1)
                    {
                        string ubuffer = uniforms[1].Replace("[", "").Replace("]", "");
                        if (!String.IsNullOrEmpty(ubuffer))
                        {
//.........这里部分代码省略.........
开发者ID:Temechon,项目名称:Babylon.js,代码行数:101,代码来源:SceneBuilder.Materials.cs

示例12: SetMaterialKeywords

        static void SetMaterialKeywords(Material material)
        {
            // Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
            // (MaterialProperty value might come from renderer material property block)
            SetKeyword (material, "_NORMALMAP", material.GetTexture ("_BumpMap") || material.GetTexture ("_DetailNormalMap"));

            SpecularMode specularMode = ( SpecularMode )material.GetInt( "_SpecularMode" );
            if ( specularMode == SpecularMode.BlinnPhong )
            {
            SetKeyword( material, "_SPECGLOSSMAP", material.GetTexture( "_SpecGlossMap" ) );
            }
            else if ( specularMode == SpecularMode.Metallic )
            {
            SetKeyword( material, "_METALLICGLOSSMAP", material.GetTexture( "_MetallicGlossMap" ) );
            }
            SetKeyword( material, "S_SPECULAR_NONE", specularMode == SpecularMode.None );
            SetKeyword( material, "S_SPECULAR_BLINNPHONG", specularMode == SpecularMode.BlinnPhong );
            SetKeyword( material, "S_SPECULAR_METALLIC", specularMode == SpecularMode.Metallic );
            SetKeyword( material, "S_OCCLUSION", material.GetTexture("_OcclusionMap") );

            SetKeyword( material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
            SetKeyword( material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"));
            SetKeyword( material, "S_OVERRIDE_LIGHTMAP", material.GetTexture( "g_tOverrideLightmap" ) );

            SetKeyword( material, "S_UNLIT", material.GetInt( "g_bUnlit" ) == 1 );
            SetKeyword( material, "S_RECEIVE_SHADOWS", material.GetInt( "g_bReceiveShadows" ) == 1 );
            SetKeyword( material, "S_WORLD_ALIGNED_TEXTURE", material.GetInt( "g_bWorldAlignedTexture" ) == 1 );

            bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled (material.GetColor("_EmissionColor"));
            SetKeyword (material, "_EMISSION", shouldEmissionBeEnabled);

            if ( material.IsKeywordEnabled( "S_RENDER_BACKFACES" ) )
            {
            material.SetInt( "_Cull", ( int )UnityEngine.Rendering.CullMode.Off );
            }
            else
            {
            material.SetInt( "_Cull", ( int )UnityEngine.Rendering.CullMode.Back );
            }

            // Setup lightmap emissive flags
            MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
            if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
            {
            flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
            if (!shouldEmissionBeEnabled)
                flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;

            material.globalIlluminationFlags = flags;
            }

            // Reflectance constants
            float flReflectanceMin = material.GetFloat( "g_flReflectanceMin" );
            float flReflectanceMax = material.GetFloat( "g_flReflectanceMax" );
            material.SetFloat( "g_flReflectanceScale", Mathf.Max( flReflectanceMin, flReflectanceMax ) - flReflectanceMin );
            material.SetFloat( "g_flReflectanceBias", flReflectanceMin );

            // World aligned texture constants
            Vector4 worldAlignedTextureNormal = material.GetVector( "g_vWorldAlignedTextureNormal" );
            Vector3 normal = new Vector3( worldAlignedTextureNormal.x, worldAlignedTextureNormal.y, worldAlignedTextureNormal.z );
            normal = ( normal.sqrMagnitude > 0.0f ) ? normal : Vector3.up;
            Vector3 tangentU = Vector3.zero, tangentV = Vector3.zero;
            Vector3.OrthoNormalize( ref normal, ref tangentU, ref tangentV );
            material.SetVector( "g_vWorldAlignedNormalTangentU", new Vector4( tangentU.x, tangentU.y, tangentU.z, 0.0f ) );
            material.SetVector( "g_vWorldAlignedNormalTangentV", new Vector4( tangentV.x, tangentV.y, tangentV.z, 0.0f ) );

            // Static combo skips
            if ( material.GetInt( "g_bUnlit" ) == 1 )
            {
            material.DisableKeyword( "_NORMALMAP" );
            material.EnableKeyword( "S_SPECULAR_NONE" );
            material.DisableKeyword( "S_SPECULAR_BLINNPHONG" );
            material.DisableKeyword( "S_SPECULAR_METALLIC" );
            material.DisableKeyword( "_METALLICGLOSSMAP" );
            material.DisableKeyword( "_SPECGLOSSMAP" );
            material.DisableKeyword( "S_OVERRIDE_LIGHTMAP" );
            material.DisableKeyword( "S_RECEIVE_SHADOWS" );
            }
        }
开发者ID:CAOakleyII,项目名称:vive-project,代码行数:79,代码来源:ValveShaderGUI.cs

示例13: Uniform

        public Uniform(Material material, string uniform, string type)
        {
            Type = type;
            Name = uniform;

            if (Type.Equals("float")) {
                float f = material.GetFloat(Name);
                Value = f.ToString(GLexConfig.HighPrecision);
            }
            else if (Type.Equals("color") || Type.Equals("vector3")) {
                Color color = material.GetColor(Name);
                Value = "[ " + color.r.ToString(GLexConfig.MediumPrecision) + ", " + color.g.ToString(GLexConfig.MediumPrecision) + ", " + color.b.ToString(GLexConfig.MediumPrecision) + " ]";
            }
            else if (Type.Equals("color32") || Type.Equals("vector4")) {
                Vector4 color32 = material.GetVector(Name);
                Value = "[ " + color32.x.ToString(GLexConfig.MediumPrecision) + ", " + color32.y.ToString(GLexConfig.MediumPrecision) + ", " + color32.z.ToString(GLexConfig.MediumPrecision) + ", " + color32.z.ToString(GLexConfig.MediumPrecision) + " ]";
            }
        }
开发者ID:GooTechnologies,项目名称:CreateUnityExporter,代码行数:18,代码来源:GLexMaterial.cs

示例14: GetShaderProperties

	public List<MaterialProperty> GetShaderProperties(Material material)
	{
		if(cache.ContainsKey(material.shader.name))
			return cache[material.shader.name];
		
		var list = new List<MaterialProperty>();
		foreach(var m in MaterialProperties)
		{
			if(material.HasProperty(m.name))
			{
				if(m.type == MaterialProperty.PropertyType.unknown)
				{
					try
					{
						var p = material.GetColor(m.name);
						if(p != transparent)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.color });
					}
					catch
					{
					}
					try
					{
						var p = material.GetFloat(m.name);
						if(p != 0)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.real });
					}
					catch
					{
					}
					try
					{
						var p = material.GetTexture(m.name);
						if(p!=null)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.texture });
					}
					catch
					{
					}
					try
					{
						var p = material.GetVector(m.name);
						if(p != Vector4.zero)
						    list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.vector });
					}
					catch
					{
						
					}
					try
					{
						var p = material.GetMatrix(m.name);
						if(p != Matrix4x4.identity)
						     list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.matrix });
					}
					catch
					{
					}
					try
					{
						var p = material.GetTextureOffset(m.name);
						if(p != Vector2.zero)
						     list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.textureOffset });
					}
					catch
					{
					}
					try
					{
						var p = material.GetTextureScale(m.name);
						if(p != Vector2.zero)
						     list.Add( new MaterialProperty { name = m.name, type = MaterialProperty.PropertyType.textureScale });
					}
					catch
					{
					}
				}
				else
				{
					list.Add(m);
				}

					
			}
			
		}
		cache[material.shader.name] = list;
		return list;
	}
开发者ID:MHaubenstock,项目名称:RPG-Board-3D,代码行数:89,代码来源:StoreMaterials.cs

示例15: BuildPreviewTexture

 public static Texture2D BuildPreviewTexture(int width, int height, Sprite sprite, Material spriteRendererMaterial, bool isPolygon)
 {
   if (!ShaderUtil.hardwareSupportsRectRenderTexture)
     return (Texture2D) null;
   float width1 = sprite.rect.width;
   float height1 = sprite.rect.height;
   Texture2D spriteTexture = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(sprite, false);
   if (!isPolygon)
     PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int) width1, (int) height1, ref width, ref height);
   SavedRenderTargetState renderTargetState = new SavedRenderTargetState();
   RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default);
   RenderTexture.active = temporary;
   GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
   GL.Clear(true, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));
   Texture texture = (Texture) null;
   Vector4 vector = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
   bool flag1 = false;
   bool flag2 = false;
   if ((Object) spriteRendererMaterial != (Object) null)
   {
     flag1 = spriteRendererMaterial.HasProperty("_MainTex");
     flag2 = spriteRendererMaterial.HasProperty("_MainTex_TexelSize");
   }
   Material material = (Material) null;
   if ((Object) spriteRendererMaterial != (Object) null)
   {
     if (flag1)
     {
       texture = spriteRendererMaterial.GetTexture("_MainTex");
       spriteRendererMaterial.SetTexture("_MainTex", (Texture) spriteTexture);
     }
     if (flag2)
     {
       vector = spriteRendererMaterial.GetVector("_MainTex_TexelSize");
       spriteRendererMaterial.SetVector("_MainTex_TexelSize", TextureUtil.GetTexelSizeVector((Texture) spriteTexture));
     }
     spriteRendererMaterial.SetPass(0);
   }
   else
   {
     material = new Material(Shader.Find("Hidden/BlitCopy"));
     material.mainTexture = (Texture) spriteTexture;
     material.mainTextureScale = Vector2.one;
     material.mainTextureOffset = Vector2.zero;
     material.SetPass(0);
   }
   float num1 = sprite.rect.width / sprite.bounds.size.x;
   Vector2[] vertices = sprite.vertices;
   Vector2[] uv = sprite.uv;
   ushort[] triangles = sprite.triangles;
   Vector2 pivot = sprite.pivot;
   GL.PushMatrix();
   GL.LoadOrtho();
   GL.Color(new Color(1f, 1f, 1f, 1f));
   GL.Begin(4);
   for (int index = 0; index < triangles.Length; ++index)
   {
     ushort num2 = triangles[index];
     Vector2 vector2_1 = vertices[(int) num2];
     Vector2 vector2_2 = uv[(int) num2];
     GL.TexCoord(new Vector3(vector2_2.x, vector2_2.y, 0.0f));
     GL.Vertex3((vector2_1.x * num1 + pivot.x) / width1, (vector2_1.y * num1 + pivot.y) / height1, 0.0f);
   }
   GL.End();
   GL.PopMatrix();
   GL.sRGBWrite = false;
   if ((Object) spriteRendererMaterial != (Object) null)
   {
     if (flag1)
       spriteRendererMaterial.SetTexture("_MainTex", texture);
     if (flag2)
       spriteRendererMaterial.SetVector("_MainTex_TexelSize", vector);
   }
   Texture2D texture2D = new Texture2D(width, height, TextureFormat.ARGB32, false);
   texture2D.hideFlags = HideFlags.HideAndDontSave;
   texture2D.ReadPixels(new Rect(0.0f, 0.0f, (float) width, (float) height), 0, 0);
   texture2D.Apply();
   RenderTexture.ReleaseTemporary(temporary);
   renderTargetState.Restore();
   if ((Object) material != (Object) null)
     Object.DestroyImmediate((Object) material);
   return texture2D;
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:83,代码来源:SpriteInspector.cs


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