static bool CompareProperty(Material a, Material b, int propID) { string propName = ShaderUtil.GetPropertyName(a.shader, propID); if (propName.Equals("_MainTex") || propName.Equals(MaterialExtension.LIGHTMAP_KEY) || propName.Equals(MaterialExtension.AO_KEY)) { return(true); } ShaderUtil.ShaderPropertyType propType = ShaderUtil.GetPropertyType(a.shader, propID); if (propType == ShaderUtil.ShaderPropertyType.Color) { return(a.GetColor(propName).Equals(b.GetColor(propName))); } if (propType == ShaderUtil.ShaderPropertyType.Float || propType == ShaderUtil.ShaderPropertyType.Range) { return(Mathf.Abs(a.GetFloat(propName) - b.GetFloat(propName)) < float.Epsilon); } if (propType == ShaderUtil.ShaderPropertyType.TexEnv) { Texture texA = a.GetTexture(propName); Texture texB = b.GetTexture(propName); return(texA && texB && texA.Equals(texB)); } return(false); }
public List <ShaderInformations> GetAllShaderProperties() { Shader shader = GetComponent <Renderer>().sharedMaterial.shader; List <ShaderInformations> allInfos = new List <ShaderInformations>(); int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) { string description = ShaderUtil.GetPropertyDescription(shader, i); string name = ShaderUtil.GetPropertyName(shader, i); ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(shader, i); ShaderInformations shaderInfo = new ShaderInformations(name, description, type); if (type == ShaderUtil.ShaderPropertyType.Range) { shaderInfo.SetRange(ShaderUtil.GetRangeLimits(shader, i, 0), ShaderUtil.GetRangeLimits(shader, i, 1), ShaderUtil.GetRangeLimits(shader, i, 2)); } allInfos.Add(shaderInfo); } return(allInfos); }
private static void PasteValues(MenuCommand menuCommand) { if (sourceMaterial == null) { Debug.LogWarning("sourceMaterial is not copied"); return; } var targetMaterial = menuCommand.context as Material; Undo.RecordObject(targetMaterial, "PasteValues"); var s = sourceMaterial.shader; var numProperties = ShaderUtil.GetPropertyCount(s); for (var i = 0; i < numProperties; ++i) { var name = ShaderUtil.GetPropertyName(s, i); var type = ShaderUtil.GetPropertyType(s, i); switch (type) { case ShaderUtil.ShaderPropertyType.Color: targetMaterial.SetColor(name, sourceMaterial.GetColor(name)); break; case ShaderUtil.ShaderPropertyType.Vector: targetMaterial.SetVector(name, sourceMaterial.GetVector(name)); break; case ShaderUtil.ShaderPropertyType.Float: case ShaderUtil.ShaderPropertyType.Range: targetMaterial.SetFloat(name, sourceMaterial.GetFloat(name)); break; } } }
/// <summary> /// Adds a shader to the shader list /// </summary> /// <param name="s">The shader to add</param> private static void AddShader(Shader s) { int propertyCount = ShaderUtil.GetPropertyCount(s); if (propertyCount > 0) { List <ShaderProperty> properties = new List <ShaderProperty>(); for (int i = 0; i < propertyCount; i++) { properties.Add(new ShaderProperty { name = ShaderUtil.GetPropertyName(s, i), type = ShaderUtil.GetPropertyType(s, i) }); } if (tmp_database.ContainsKey(s.name)) { tmp_database[s.name] = properties.Union(tmp_database[s.name]).ToList(); } else { tmp_database[s.name] = properties; } } }
private ReferenceNode SearchMaterial( Object unityObject ) { Material material = (Material) unityObject; ReferenceNode referenceNode = PopReferenceNode( material ); if( searchMaterialsForShader && objectsToSearchSet.Contains( material.shader ) ) referenceNode.AddLinkTo( GetReferenceNode( material.shader ), "Shader" ); if( searchMaterialsForTexture ) { // Search through all the textures attached to this material // Credit: http://answers.unity3d.com/answers/1116025/view.html Shader shader = material.shader; int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader ); for( int i = 0; i < shaderPropertyCount; i++ ) { if( ShaderUtil.GetPropertyType( shader, i ) == ShaderUtil.ShaderPropertyType.TexEnv ) { string propertyName = ShaderUtil.GetPropertyName( shader, i ); Texture assignedTexture = material.GetTexture( propertyName ); if( objectsToSearchSet.Contains( assignedTexture ) ) referenceNode.AddLinkTo( GetReferenceNode( assignedTexture ), "Shader property: " + propertyName ); } } } return referenceNode; }
private static List <string> GetShaderPropertyList(Shader shader, ShaderUtil.ShaderPropertyType[] filterTypes = null) { List <string> results = new List <string>(); if (shader == null) { return(results); } int count = ShaderUtil.GetPropertyCount(shader); results.Capacity = count; for (int i = 0; i < count; i++) { bool isHidden = ShaderUtil.IsShaderPropertyHidden(shader, i); bool isValidPropertyType = filterTypes == null || filterTypes.Contains(ShaderUtil.GetPropertyType(shader, i)); if (!isHidden && isValidPropertyType) { results.Add(ShaderUtil.GetPropertyName(shader, i)); } } results.Sort(); return(results); }
internal static Texture2D GetPreviewTexture(Material material) { if (material == null || material.shader == null) { return(null); } Texture2D best = null; for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); i++) { if (ShaderUtil.GetPropertyType(material.shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { string propertyName = ShaderUtil.GetPropertyName(material.shader, i); Texture2D tex = material.GetTexture(propertyName) as Texture2D; if (tex != null) { if (propertyName.Contains("_MainTex") || propertyName.Contains("Albedo")) { return(tex); } else if (best == null) { best = tex; } } } } return(best); }
public static List <TexEnv> GetTexEnvs(Material material) { texEnvNames.Clear(); if (material != null) { var shader = material.shader; if (shader != null) { var count = ShaderUtil.GetPropertyCount(shader); for (var i = 0; i < count; i++) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { var texEnv = default(TexEnv); texEnv.Name = ShaderUtil.GetPropertyName(shader, i); texEnv.Desc = ShaderUtil.GetPropertyDescription(shader, i); texEnvNames.Add(texEnv); } } } } return(texEnvNames); }
void UpdateTiling() { // A Unity plane is 10 units x 10 units float planeSizeX = 10f; float planeSizeZ = 10f; // Figure out texture-to-mesh width based on user set texture-to-mesh height Texture tex = this.mat.mainTexture; float textureToMeshX = ((float)tex.width / tex.height) * this.textureToMeshZ; Vector2 scal = new Vector2(planeSizeX * gameObject.transform.lossyScale.x / textureToMeshX, planeSizeZ * gameObject.transform.lossyScale.z / textureToMeshZ); Renderer render = gameObject.GetComponent <Renderer>(); if (render) { foreach (Material mat in render.materials) { Shader shader = mat.shader; for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { mat.SetTextureScale(ShaderUtil.GetPropertyName(shader, i), scal); } } } } }
// returns the shader defines for a specific shaderName. // if the shaderName is not found (which should never happen) then it returns null; public List <string> GetShaderTexturesDefines(string shaderName) { Material mat = new Material(Shader.Find(shaderName)); if (mat == null) { Debug.LogError("Unknown Shader: " + shaderName); return(null); } if (shaderInfoCache.ContainsKey(shaderName)) //if shader is not catched, cache it. { return(shaderInfoCache[shaderName]); } else //shader not cached, calculate the shader defines and cache the shader properties { List <string> shaderTextureDefines = new List <string>(); int count = ShaderUtil.GetPropertyCount(mat.shader); for (int i = 0; i < count; i++) { if (ShaderUtil.GetPropertyType(mat.shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { if (ShaderUtil.GetTexDim(mat.shader, i) == ShaderUtil.ShaderPropertyTexDim.TexDim2D) { shaderTextureDefines.Add(ShaderUtil.GetPropertyName(mat.shader, i)); } } } CacheShaderInfo(shaderName, shaderTextureDefines); return(shaderTextureDefines); } }
public static bool TexEnvNameExists(Material material, string name) { if (material != null) { var shader = material.shader; if (shader != null) { var count = ShaderUtil.GetPropertyCount(shader); for (var i = 0; i < count; i++) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { if (ShaderUtil.GetPropertyName(shader, i) == name) { return(true); } } } } } return(false); }
private void RebuildNames() { Shader s = serializedObject.FindProperty("TargetShader").objectReferenceValue as Shader; if (s == null) { return; } _texturenames = new List <string>(); _colornames = new List <string>(); for (var i = 0; i < ShaderUtil.GetPropertyCount(s); i++) { switch (ShaderUtil.GetPropertyType(s, i)) { case ShaderUtil.ShaderPropertyType.Color: _colornames.Add(ShaderUtil.GetPropertyName(s, i)); break; case ShaderUtil.ShaderPropertyType.TexEnv: _texturenames.Add(ShaderUtil.GetPropertyName(s, i)); break; } } if (_texturenames.Count == 0) { _texturenames.Add("NO TEXTURE PROPERTY"); } if (_colornames.Count == 0) { _colornames.Add("NO COLOR PROPERTY"); } }
/// <summary> /// Get all textures from a material /// </summary> /// <returns>The textures from material.</returns> /// <param name="mat">Mat.</param> public static bool getTexturesFromMaterial(Material mat, ref ArrayList propNames, ref ArrayList texNames, ref ArrayList texPaths) { bool ret = false; if (mat == null) { Debug.LogWarning("The mat is null"); return(ret); } Shader shader = mat.shader; string propName = ""; for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { propName = ShaderUtil.GetPropertyName(shader, i); Texture texture = mat.GetTexture(propName); if (texture != null) { ret = ECLEditorUtl.moveAsset4Upgrade(texture) || ret ? true : false; propNames.Add(propName); texNames.Add(ECLEditorUtl.getAssetName4Upgrade(texture)); texPaths.Add(ECLEditorUtl.getPathByObject(texture)); } } } return(ret); }
private static void GetProperties(ref List <TextureProp> m_Properties, ShaderImporter importer) { var shader = importer.GetShader(); var propertyCount = ShaderUtil.GetPropertyCount(shader); for (var i = 0; i < propertyCount; i++) { if (ShaderUtil.GetPropertyType(shader, i) != ShaderUtil.ShaderPropertyType.TexEnv) { continue; } var propertyName = ShaderUtil.GetPropertyName(shader, i); var displayName = ShaderUtil.GetPropertyDescription(shader, i); // might be empty var texture = importer.GetDefaultTexture(propertyName); var assetBundleName = ""; if (texture != null) { var textureAssetPath = AssetDatabase.GetAssetPath(texture); assetBundleName = AssetDatabase.GetImplicitAssetBundleName(textureAssetPath); } var temp = new TextureProp { propertyName = propertyName, displayName = displayName, texture = texture, assetBundleName = assetBundleName, //dimension = ShaderUtil.GetTexDim(shader, i) }; m_Properties.Add(temp); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (!isVisible) { return; } Material targetMat = target as Material; //我们正在编辑的材质 Shader shader = targetMat.shader; //第二个材质属性 string label1 = ShaderUtil.GetPropertyDescription(shader, 1); string propertyName1 = ShaderUtil.GetPropertyName(shader, 1); float val1 = targetMat.GetFloat(propertyName1); //第三个材质属性 string label2 = ShaderUtil.GetPropertyDescription(shader, 2); string propertyName2 = ShaderUtil.GetPropertyName(shader, 2); int val2 = targetMat.GetInt(propertyName2); //第1个浮点值的展示 EditorGUILayout.LabelField(label1 + "/" + propertyName1, " " + val1); //第2个整型的展示 EditorGUILayout.LabelField(label2 + "/" + propertyName2, " " + val2); EditorGUI.BeginChangeCheck(); //GUI变动开始 if (EditorGUI.EndChangeCheck()) //GUI变动结束 { EditorUtility.SetDirty(targetMat); } }
public static MaterialItem Create(Material material) { var item = new MaterialItem { Material = material }; #if UNITY_EDITOR var propNames = new List <string>(); for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); ++i) { var propType = ShaderUtil.GetPropertyType(material.shader, i); if (propType == ShaderUtil.ShaderPropertyType.Color) { var name = ShaderUtil.GetPropertyName(material.shader, i); item.PropMap.Add(name, new PropItem { PropertyType = propType, DefaultValues = material.GetColor(name), }); propNames.Add(name); } } item.PropNames = propNames.ToArray(); #endif return(item); }
private void RegisterShaderProperties(Shader s) { for (int i = 0; i < ShaderUtil.GetPropertyCount(s); ++i) { properties.Add(ShaderUtil.GetPropertyName(s, i)); } }
private static TextureDetails GetAllTexturesFromScene() { var details = new TextureDetails(); var checkedMaterials = new List <Material>(); var allGameObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)); var allGameObjectsLength = allGameObjects.Length; for (var i = 0; i < allGameObjectsLength; i++) { var gameObject = allGameObjects[i] as GameObject; if (gameObject.hideFlags != HideFlags.None || EditorUtility.IsPersistent(gameObject.transform.root.gameObject)) { continue; } if (EditorUtility.DisplayCancelableProgressBar("Getting All Textures from Scene", gameObject.name, (float)i / allGameObjectsLength)) { break; } var renderers = gameObject.GetComponents <Renderer>(); for (var j = 0; j < renderers.Length; j++) { var renderer = renderers[j]; for (var k = 0; k < renderer.sharedMaterials.Length; k++) { var material = renderer.sharedMaterials[k]; if (material == null || checkedMaterials.Contains(material)) { continue; } checkedMaterials.Add(material); var shader = material.shader; for (var l = 0; l < ShaderUtil.GetPropertyCount(shader); l++) { if (ShaderUtil.GetPropertyType(shader, l) == ShaderUtil.ShaderPropertyType.TexEnv) { var texture = material.GetTexture(ShaderUtil.GetPropertyName(shader, l)); var textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter; if (textureImporter != null) { details.AddTexture(textureImporter, texture); } } } } } } EditorUtility.ClearProgressBar(); return(details); }
// Caches the list of properties public static List <ShaderPropertyInfo> GetShaderProperties(Shader s) { if (shaderProps.ContainsKey(s.GetInstanceID())) { return(shaderProps[s.GetInstanceID()]); } var res = new List <ShaderPropertyInfo>(); var pc = ShaderUtil.GetPropertyCount(s); for (var i = 0; i < pc; i++) { var sp = new ShaderPropertyInfo(); sp.property = ShaderUtil.GetPropertyName(s, i); sp.type = (ShaderPropertyType)ShaderUtil.GetPropertyType(s, i); sp.description = ShaderUtil.GetPropertyDescription(s, i); if (sp.type == ShaderPropertyType.Range) { sp.rangeMin = ShaderUtil.GetRangeLimits(s, i, 1); sp.rangeMax = ShaderUtil.GetRangeLimits(s, i, 2); } res.Add(sp); } return(shaderProps[s.GetInstanceID()] = res); }
protected void updateKeys() { if (mTarget.replaceMaterial != null) { Shader shader = mTarget.replaceMaterial.shader; int len = ShaderUtil.GetPropertyCount(shader); keys.Clear(); max.Clear(); max.Clear(); def.Clear(); for (int i = 0; i < len; i++) { string g = ShaderUtil.GetPropertyName(shader, i); ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(shader, i); if (type == ShaderUtil.ShaderPropertyType.Range) { def[g] = ShaderUtil.GetRangeLimits(shader, i, 0); min[g] = ShaderUtil.GetRangeLimits(shader, i, 1); max[g] = ShaderUtil.GetRangeLimits(shader, i, 2); keys.Add(g); } if (type == ShaderUtil.ShaderPropertyType.Color) { Color color = mTarget.replaceMaterial.GetColor(g); colors.Add(g, color); colorKeys = colors.Keys.ToArray(); } } } }
public static string ParseStandardShaderName(Material mat) { List <string> shaderTextureDefines = new List <string>(); int count = ShaderUtil.GetPropertyCount(mat.shader); for (int i = 0; i < count; i++) { if (ShaderUtil.GetPropertyType(mat.shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) #if UNITY_5_4_OR_NEWER { if (ShaderUtil.GetTexDim(mat.shader, i) == UnityEngine.Rendering.TextureDimension.Tex2D) { #else { if (ShaderUtil.GetTexDim(mat.shader, i) == ShaderUtil.ShaderPropertyTexDim.TexDim2D) { #endif string shaderDefine = ShaderUtil.GetPropertyName(mat.shader, i); Texture2D retrievedTextureFromShader = mat.GetTexture(shaderDefine) as Texture2D; if (retrievedTextureFromShader != null) { shaderTextureDefines.Add(shaderDefine); } } } } string parsedShaderName = mat.shader.name + "-" + GetStandardShaderRenderingMode(mat) + "-"; for (int i = 0; i < shaderTextureDefines.Count; i++) { parsedShaderName += shaderTextureDefines[i].Substring(1, 3) + "-"; } return(parsedShaderName.Remove(parsedShaderName.Length - 1));//remove ending "-" }
private static void ResetValues(MenuCommand menuCommand) { var targetMaterial = menuCommand.context as Material; Undo.RecordObject(targetMaterial, "ResetValues"); var s = targetMaterial.shader; var dummyMaterial = new Material(s); var numProperties = ShaderUtil.GetPropertyCount(s); for (var i = 0; i < numProperties; ++i) { var name = ShaderUtil.GetPropertyName(s, i); var type = ShaderUtil.GetPropertyType(s, i); // Debug.Log(name); // Debug.Log(type); switch (type) { case ShaderUtil.ShaderPropertyType.Color: targetMaterial.SetColor(name, dummyMaterial.GetColor(name)); break; case ShaderUtil.ShaderPropertyType.Vector: targetMaterial.SetVector(name, dummyMaterial.GetVector(name)); break; case ShaderUtil.ShaderPropertyType.Float: case ShaderUtil.ShaderPropertyType.Range: targetMaterial.SetFloat(name, dummyMaterial.GetFloat(name)); break; } } }
private static void ResetTextures(MenuCommand menuCommand) { var targetMaterial = menuCommand.context as Material; Undo.RecordObject(targetMaterial, "ResetTextures"); var s = targetMaterial.shader; var numProperties = ShaderUtil.GetPropertyCount(s); for (var i = 0; i < numProperties; ++i) { var name = ShaderUtil.GetPropertyName(s, i); var type = ShaderUtil.GetPropertyType(s, i); // Debug.Log(name); // Debug.Log(type); switch (type) { // case ShaderUtil.ShaderPropertyType.Color: // targetMaterial.SetColor(name, sourceMaterial.GetColor(name) ); // break; // case ShaderUtil.ShaderPropertyType.Vector: // targetMaterial.SetVector(name, sourceMaterial.GetVector(name) ); // break; // case ShaderUtil.ShaderPropertyType.Float: // case ShaderUtil.ShaderPropertyType.Range: // targetMaterial.SetFloat(name, sourceMaterial.GetFloat(name) ); // break; case ShaderUtil.ShaderPropertyType.TexEnv: targetMaterial.SetTexture(name, null); targetMaterial.SetTextureOffset(name, Vector2.zero); targetMaterial.SetTextureScale(name, Vector2.one); break; } } }
/// <summary> /// DO NOT USE: Working on, where every texture is grabbed from the object /// </summary> public static void ExportTextureFromAMesh(MeshRenderer meshRenderer, string materialFolder, string fullTextureFolder) { // 1. Need to copy the texture to the new path // Go through all materials in the mesh renderer and export them as some materials int length = meshRenderer.sharedMaterials.Length; for (int materialIndex = 0; materialIndex < length; materialIndex++) { Material currentMaterial = meshRenderer.sharedMaterials[materialIndex]; Shader shader = currentMaterial.shader; int propertyCount = ShaderUtil.GetPropertyCount(shader); // Copies all the textures to the file for (int i = 0; i < propertyCount; i++) { ShaderUtil.ShaderPropertyType propType = ShaderUtil.GetPropertyType(shader, i); if (propType == ShaderUtil.ShaderPropertyType.TexEnv) { Texture texture = currentMaterial.GetTexture(ShaderUtil.GetPropertyName(shader, i)); if (texture != null) { string texturePath = UtiltiesHiFi.GetAssetPathFolder() + AssetDatabase.GetAssetOrScenePath(texture); string newTextureName = UtiltiesHiFi.GetFileName(texturePath); string newTexturePathAndName = fullTextureFolder + newTextureName; File.Copy(texturePath, newTexturePathAndName); } } } } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (property.FindPropertyRelative("shader").hasMultipleDifferentValues) { return(EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing); } var shaderProperty = property.FindPropertyRelative("shader"); var currentShaderReference = shaderProperty.objectReferenceValue as Shader; var additionalCount = 0; if (currentShaderReference != null) { for (var index = 0; index < ShaderUtil.GetPropertyCount(currentShaderReference); index++) { var propertyName = ShaderUtil.GetPropertyName(currentShaderReference, index); if (!propertyName.StartsWith("_Public")) { continue; } additionalCount++; } } return((EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * (additionalCount + 1)); }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { // Check there's a shader to extract properties from GameObject gameObject = (prop.serializedObject.targetObject as MonoBehaviour).gameObject; if (gameObject != null) { MeshRenderer renderer = gameObject.GetComponent <MeshRenderer>(); if (renderer == null) { EditorGUI.LabelField(new Rect(pos.x, pos.y, pos.width, pos.height), "No MeshRenderer found"); } else if (renderer.sharedMaterial == null) { EditorGUI.LabelField(new Rect(pos.x, pos.y, pos.width, pos.height), "No Material found"); } else if (renderer.sharedMaterial.shader == null) { EditorGUI.LabelField(new Rect(pos.x, pos.y, pos.width, pos.height), "No suitable shader found"); } else { ShaderPropertyNameAttribute parameter = (ShaderPropertyNameAttribute)attribute; Shader shader = renderer.sharedMaterial.shader; int propertyCount = ShaderUtil.GetPropertyCount(shader); int selectedTexture = 0; List <string> textureNames = new List <string>(); // TODO: No need to instantiate this each iteration EditorGUI.LabelField(new Rect(pos.x, pos.y, pos.width / 2.0f, 20.0f), label.text + " (" + parameter.ShaderPropertyType.ToString() + ")"); // Loop through the parameters adding those that match type to the list for (int propertyID = 0; propertyID < propertyCount; ++propertyID) { // TODO: It would be lovely to mirror the internal enum somehow... if (ShaderUtil.GetPropertyType(shader, propertyID) == (ShaderUtil.ShaderPropertyType)(parameter.ShaderPropertyType)) { string name = ShaderUtil.GetPropertyName(shader, propertyID); // If the shader-property's name matches the current value of the SerializedProperty, update the selected index. if (name == prop.stringValue) { selectedTexture = textureNames.Count; } textureNames.Add(name); } } if (textureNames.Count > 0) { int newVal = EditorGUI.Popup(new Rect(pos.x + pos.width / 2.0f, pos.y, pos.width / 2.0f, pos.height), selectedTexture, textureNames.ToArray()); prop.stringValue = textureNames[newVal]; } else { EditorGUI.LabelField(new Rect(pos.x + pos.width / 2.0f, pos.y, pos.width / 2.0f, pos.height), "No Properties Found"); } } } }
private void DrawMaterial(Material m) { eGUI.LabelBold(m.name); var shader = m.shader; if (shader == null) { return; } if (shader != _cachedShader) { _cachedShader = shader; _cachedProperties = new ShaderPropertyInfo[ShaderUtil.GetPropertyCount(shader)]; for (var i = 0; i < _cachedProperties.Length; i++) { _cachedProperties[i] = new ShaderPropertyInfo { name = ShaderUtil.GetPropertyName(shader, i), type = ShaderUtil.GetPropertyType(shader, i) } } ; } eGUI.ComboEditor(ref _target.propertyName, "Property", _cachedProperties.Where(p => (byte)p.type == (byte)_target.propertyType).Select(p => p.name).ToArray()); } }
static MaterialInfo GetCertainMaterialTexturePaths(Material _mat) { List <string> results = new List <string>(); Shader shader = _mat.shader; MaterialInfo materialInfo = new MaterialInfo() { shaderName = shader.name, name = _mat.name }; materialInfo.propsFloat = new List <PropInfoFloat>(); materialInfo.propsVector4 = new List <PropInfoVector4>(); materialInfo.propsTex = new List <PropInfoTexture>(); for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); ++i) { var propName = ShaderUtil.GetPropertyName(shader, i); var propType = ShaderUtil.GetPropertyType(shader, i); if (propType == ShaderUtil.ShaderPropertyType.Color || propType == ShaderUtil.ShaderPropertyType.Vector) { materialInfo.propsVector4.Add(new PropInfoVector4() { name = propName, type = propType.ToString(), data = _mat.GetVector(propName) } ); } else if (propType == ShaderUtil.ShaderPropertyType.Float || propType == ShaderUtil.ShaderPropertyType.Range) { materialInfo.propsFloat.Add(new PropInfoFloat() { name = propName, type = propType.ToString(), data = _mat.GetFloat(propName) } ); } else if (propType == ShaderUtil.ShaderPropertyType.TexEnv) { Texture tex = _mat.GetTexture(propName); if (tex) { materialInfo.propsTex.Add(new PropInfoTexture() { name = propName, type = propType.ToString(), data = AssetDatabase.GetAssetPath(tex).Substring(7).ToLower() } ); } } } return(materialInfo); }
private void GetAllTextures (LiveMaterial.LiveMat mat) { var n = ShaderUtil.GetPropertyCount ( mat.shader ); var txs = new List<LiveMaterial.LiveTexture> (); /// Keeps texture properties within the shader into a list var count = 0; for ( int i = 0; i != n; i++ ) { if ( ShaderUtil.GetPropertyType ( mat.shader, i ) == ShaderUtil.ShaderPropertyType.TexEnv ) { var tx = new LiveMaterial.LiveTexture (); tx.id = i; tx.name = ShaderUtil.GetPropertyName ( mat.shader, i ); tx.desc = ShaderUtil.GetPropertyDescription ( mat.shader, i ); tx.currentFrame = 1; tx.fps = 30; tx.fold = true; tx.load = false; txs.Add ( tx ); count++; } } lm.mts[mat.id].txs = txs.ToArray (); txs.Clear (); lm.mts[mat.id].count = count; }
public List <KeyValuePair <string, Texture> > GetTexturesFromMaterial(Material material) { #if UNITY_EDITOR List <KeyValuePair <string, Texture> > textures = new List <KeyValuePair <string, Texture> >(); Shader shader = material.shader; if (shader == null) { return(null); } int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) { string propertyName = ShaderUtil.GetPropertyName(shader, i); ShaderUtil.ShaderPropertyType propertyType = ShaderUtil.GetPropertyType(shader, i); if (propertyType == ShaderUtil.ShaderPropertyType.TexEnv) { Texture tex = material.GetTexture(propertyName); if (tex != null) { textures.Add(new KeyValuePair <string, Texture>(tex.name, tex)); } } } return(textures); #else return(null); #endif }