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怎么设置提高好牌几率(透视)积累教程(都是有挂)-...
透视曝光!wpk俱乐部辅助器(... 透视曝光!wpk俱乐部辅助器(透视)wpk德州局透视,教程方案(有挂细节)-哔哩哔哩1、实时wpk俱...
透视策略!wepoker私人局... 透视策略!wepoker私人局透视插件,wepoker破解器激活码(脚本)普及教程(切实真的是有挂)...
最新消息!aapoker辅助工... 您好,aapoker辅助工具安全吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【4852750...
透视解迷!wpk辅助是什么(透... 透视解迷!wpk辅助是什么(透视)wpk软件是正规的吗,教程学习(有挂神器)-哔哩哔哩wpk软件是正...
透视方案!wepoker透视脚... 透视方案!wepoker透视脚本免费下载pc,wepokerplus作弊(脚本)关于教程(竟然有挂)...
现场直击!aapoker透视脚... 现场直击!aapoker透视脚本,aapoker免费透视脚本(透视)课程教程(切实有挂)-哔哩哔哩1...
透视方针!wepoker透视脚... 透视方针!wepoker透视脚本是什么,wepoker数据分析工具(脚本)科普教程(一直是有挂)-哔...
透视揭露!wpk软件是正规的吗... 透视揭露!wpk软件是正规的吗(透视)wpk有透视吗,教程方针(有挂猫腻)-哔哩哔哩1、打开软件启动...
针对!aapoker辅助器是真... 针对!aapoker辅助器是真的吗,aa poker辅助(透视)课程教程(本来是有挂)-哔哩哔哩1、...