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.点右上角三个点,进行调用脚本中的方法。


相关内容

热门资讯

透视科技!闲来游戏辅助器脚本,... 透视科技!闲来游戏辅助器脚本,哈糖大菠萝开挂(透视)开挂辅助安装2026新版技巧;无需打开直接搜索加...
实测辅助!wepoker怎么增... 您好:赣牌圈挂安装图解这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
指引辅助"微信老铁1... 大家好,今天小编来为大家解答微信老铁13水辅助这个问题咨询软件客服可以免费测试直接加微信(13670...
第九分钟开挂"约战丹... 第九分钟开挂"约战丹东辅助"原先有开挂辅助透视器(有挂秘笈) 【无需打开直接搜索加薇13670430...
透视中牌率!微乐河南麻将辅助i... 透视中牌率!微乐河南麻将辅助ios,新卡农辅助(透视)开挂辅助安装技巧教程;无需打开直接搜索薇:13...
法子开挂"微信开心是... 大家好,今天小编来为大家解答微信开心是按照辅助脚本这个问题咨询软件客服可以免费测试直接加微信(136...
关于辅助!线上德州的辅助器是什... 关于辅助!线上德州的辅助器是什么,浙江游戏大厅脚本软件,开挂(透视)辅助下载(有挂功能);打开点击测...
一分钟开挂"青龙辅助... 一分钟开挂"青龙辅助3.0"从前有开挂辅助透视脚本(有挂神器)【无需打开直接搜索加薇13670430...
技法辅助"好友赣南插... 技法辅助"好友赣南插件"开挂(安装)辅助插件(真实有挂)《详细加薇136704302咨询》游戏特色:...
透视透视!欢聚水鱼辅助插件,樱... 樱花之盛辅助真的假的是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可以加...