Unity材质球自动遍历所需贴图
创始人
2024-12-18 01:06:25
0

Unity材质球自动遍历所需贴图


文章目录

  • Unity材质球自动遍历所需贴图
  • 一、原理
  • 二、用法
    • 1.代码:
    • 2.使用方法


一、原理

例如一个材质球名为:Decal_Text_Cranes_01_Mat ,
然后从全局遍历出:Decal_Text_Cranes_01_Albedo赋值给材质球的BaseMap,
全局遍历出Decal_Text_Cranes_01_MAODS 赋值给材质球MetallicMap通道,
全局遍历出Decal_Text_Cranes_01_Normal 给材质球NormalMap通道,
**规律:**材质球名字:Decal_Text_Cranes_01_Mat 把后面Mat换成通道名称,就是该材质球的通道贴图


二、用法

1.代码:

using UnityEngine; using System.Collections.Generic; using System.IO; using UnityEditor;  public class AutoAssignTextureMaps : MonoBehaviour {     public List targetMaterials; // 在Inspector中指定目标材质列表     private Dictionary textureMapNames = new Dictionary     {         { "Albedo", "_BaseMap" },   // Base Color         { "MAODS", "_MetallicGlossMap" }, // Metallic and Smoothness         { "Normal", "_BumpMap" }     // Normal Map     };       [ContextMenu("_AlphaMat后缀自动补全")]     void AssignTextures1( )     {         foreach (Material material in targetMaterials)         {             string baseName = material.name.Replace("_AlphaMat", "");             foreach (var pair in textureMapNames)             {                 string textureName = baseName + "_" + pair.Key;                 Texture2D texture = FindTexture(textureName);                 if (texture != null)                 {                     material.SetTexture(pair.Value, texture);                     Debug.Log($"Assigned {textureName} to {pair.Value} for material {material.name}");                 }                 else                 {                     Debug.LogError($"Could not find texture {textureName} for material {material.name}");                 }             }         }     }      [ContextMenu("_Mat后缀自动补全")]     void AssignTextures2( )     {         foreach (Material material in targetMaterials)         {             string baseName = material.name.Replace("_Mat", "");             foreach (var pair in textureMapNames)             {                 string textureName = baseName + "_" + pair.Key;                 Texture2D texture = FindTexture(textureName);                 if (texture != null)                 {                     material.SetTexture(pair.Value, texture);                     Debug.Log($"Assigned {textureName} to {pair.Value} for material {material.name}");                 }                 else                 {                     Debug.LogError($"Could not find texture {textureName} for material {material.name}");                 }             }         }     }     Texture2D FindTexture(string textureName)     {         string[] guids = AssetDatabase.FindAssets(textureName);         if (guids.Length > 0)         {             string assetPath = AssetDatabase.GUIDToAssetPath(guids[0]);             return AssetDatabase.LoadAssetAtPath(assetPath);         }         return null;     } }  

2.使用方法

在这里插入图片描述

1.将脚本挂载到一个空物体:
2.把所需的材质球添加到集合列表中。
3.点右上角三个点,进行调用脚本中的方法。


相关内容

热门资讯

透视教程!aapoker怎么选... 透视教程!aapoker怎么选牌,aapoker辅助软件合法吗,AI教程(有挂脚本)1、透视教程!a...
透视智能ai!pokemmo脚... 透视智能ai!pokemmo脚本辅助下载,fishpoker透视底牌,新2025版(有挂技巧)1、用...
透视挂透视!wpk有作弊吗,总... 透视挂透视!wpk有作弊吗,总是有挂(透视)可靠教程(有挂揭秘);一、wpk有作弊吗AI软件牌型概率...
透视规律!aapoker透视脚... 透视规律!aapoker透视脚本,aapoker辅助插件工具,必赢方法(有挂技巧)1、全新机制【aa...
透视辅助!菠萝辅助器免费版的特... 透视辅助!菠萝辅助器免费版的特点,哈糖大菠萝挂法,wpk教程(有挂揭秘)1、菠萝辅助器免费版的特点系...
透视辅助!wepoker私人局... 透视辅助!wepoker私人局俱乐部怎么进,起初真的有挂(透视)玩家教你(有挂工具)1、点击下载安装...
透视最新!aapoker辅助器... 透视最新!aapoker辅助器怎么用,aapoker怎么选牌,黑科技教程(有挂脚本);1、进入游戏-...
透视透视!pokermaste... 透视透视!pokermaster脚本,智星德州插件2024最新版,必胜教程(有挂解说)1、下载好智星...
透视app!wepoker钻石... 透视app!wepoker钻石怎么看底牌,从来是有挂(透视)揭秘教程(有挂插件)1、wepoker钻...
透视脚本!aapoker辅助器... 透视脚本!aapoker辅助器是真的吗,aapoker万能辅助器,解说技巧(有挂教程);暗藏猫腻,小...